treender/src/App.cpp

62 lines
1.5 KiB
C++

#include <array>
#include <cmath>
#include "App.hpp"
#include "Math.hpp"
#include "values/mrand.hpp"
#include <raylib.h>
#include <raymath.h>
void App::init(int screenWidth, int screenHeight)
{
this->screenWidth = screenWidth;
this->screenHeight = screenHeight;
this->canvas.init(screenWidth);
mrand::setSeed(1);
canvasTexure = LoadRenderTexture(screenWidth, screenWidth);
dnaShow = manager.next(false);
canvas.newGen(canvasTexure, dnaShow);
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::update()
{
bool isDone = canvas.tick(canvasTexure);
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && isDone)
{
Vector2 mouse = GetMousePosition();
if (CheckCollisionPointRec(mouse, disLikeBox))
{
dnaShow = manager.next(false);
canvas.newGen(canvasTexure, dnaShow);
}
if (CheckCollisionPointRec(mouse, likeBox))
{
dnaShow = manager.next(true);
canvas.newGen(canvasTexure, dnaShow);
}
}
}
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);
}
void App::deinit()
{
UnloadRenderTexture(canvasTexure);
canvas.deinit();
}