80 lines
1.8 KiB
C++
80 lines
1.8 KiB
C++
#include <array>
|
|
#include <cmath>
|
|
|
|
#include "App.hpp"
|
|
#include "Math.hpp"
|
|
|
|
#include <raylib.h>
|
|
#include <raymath.h>
|
|
|
|
void App::init(int screenWidth, int screenHeight)
|
|
{
|
|
this->screenWidth = screenWidth;
|
|
this->screenHeight = screenHeight;
|
|
this->canvas.init(screenWidth);
|
|
|
|
canvasTexure = LoadRenderTexture(screenWidth, screenWidth);
|
|
manager.init();
|
|
upTex(Liked::tbd);
|
|
float posY = (screenHeight - screenWidth) / 2.0f;
|
|
float recPosX = screenWidth * 0.2f;
|
|
dest = {0, posY, (float)screenWidth, (float)screenWidth};
|
|
disLikeBox = {0, posY, (float)recPosX, (float)screenWidth};
|
|
likeBox = {screenWidth - recPosX, posY, (float)recPosX, (float)screenWidth};
|
|
}
|
|
|
|
void App::upTex(Liked liked)
|
|
{
|
|
if (liked != Liked::tbd)
|
|
{
|
|
unit.liked = liked;
|
|
manager.like(unit);
|
|
}
|
|
unit = manager.next();
|
|
if (unit.dna != nullptr)
|
|
{
|
|
canvas.newGen(canvasTexure, unit.dna);
|
|
return;
|
|
}
|
|
|
|
BeginTextureMode(canvasTexure);
|
|
ClearBackground(WHITE);
|
|
DrawText("NEXT GEN", 10, 10, 20, BLACK);
|
|
EndTextureMode();
|
|
}
|
|
|
|
void App::update()
|
|
{
|
|
bool isDone = canvas.tick(canvasTexure);
|
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && isDone)
|
|
{
|
|
Vector2 mouse = GetMousePosition();
|
|
if (CheckCollisionPointRec(mouse, disLikeBox))
|
|
{
|
|
upTex(Liked::no);
|
|
}
|
|
if (CheckCollisionPointRec(mouse, likeBox))
|
|
{
|
|
upTex(Liked::yes);
|
|
}
|
|
}
|
|
}
|
|
|
|
void App::draw()
|
|
{
|
|
ClearBackground(BLUE);
|
|
|
|
Rectangle source = {0, 0, (float)canvasTexure.texture.width, (float)-canvasTexure.texture.height};
|
|
Vector2 origin = {0.0f, 0.0f};
|
|
DrawTexturePro(canvasTexure.texture, source, dest, origin, 0.0f, WHITE);
|
|
|
|
const char *text = TextFormat("GEN %d: %d / %d", manager.generation, unit.index + 1, NUM_PER_GEN);
|
|
DrawText(text, dest.x + 10, dest.y - 30, 20, BLACK);
|
|
}
|
|
|
|
void App::deinit()
|
|
{
|
|
UnloadRenderTexture(canvasTexure);
|
|
canvas.deinit();
|
|
manager.deinit();
|
|
} |