76 lines
1.8 KiB
C++
76 lines
1.8 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);
|
|
|
|
for (size_t i = 0; i < canvasTexure.size(); i++)
|
|
{
|
|
canvasTexure[i] = LoadRenderTexture(screenWidth, screenWidth);
|
|
}
|
|
|
|
canvas.newGen(canvasTexure[0]);
|
|
canvas.newGen(canvasTexure[1]);
|
|
|
|
float posY = (screenHeight - screenWidth) / 2.0f;
|
|
destA = {0, posY, (float)screenWidth, (float)screenWidth};
|
|
destB = destA;
|
|
}
|
|
|
|
void App::update()
|
|
{
|
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
|
{
|
|
mouseStart = GetMousePosition();
|
|
validHit = CheckCollisionPointRec(mouseStart, destA);
|
|
len = Vector2Distance(mouseStart, {destB.x, destB.y});
|
|
ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y);
|
|
}
|
|
|
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && validHit)
|
|
{
|
|
Vector2 mousePosition = GetMousePosition();
|
|
float dist = mousePosition.x - mouseStart.x;
|
|
float l = dist / screenWidth;
|
|
rotation = Lerp(45.0f, -45.0f, (l + 1) / 2);
|
|
Vector2 newCenter = CalculateVector(rotation, ofset, len);
|
|
destA.x = newCenter.x + mousePosition.x;
|
|
destA.y = newCenter.y + mousePosition.y;
|
|
}
|
|
|
|
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && validHit)
|
|
{
|
|
canvas.newGen(canvasTexure[1 - pos]);
|
|
pos = 1 - pos;
|
|
rotation = 0.0f;
|
|
destA = destB;
|
|
}
|
|
}
|
|
|
|
void App::draw()
|
|
{
|
|
ClearBackground(RED);
|
|
drawTexureWithRotation(canvasTexure[pos], destB, 0.0f);
|
|
drawTexureWithRotation(canvasTexure[1 - pos], destA, rotation);
|
|
}
|
|
|
|
void App::deinit()
|
|
{
|
|
for (size_t i = 0; i < canvasTexure.size(); i++)
|
|
{
|
|
UnloadRenderTexture(canvasTexure[i]);
|
|
}
|
|
canvas.deinit();
|
|
} |