Add multiple tree

eden je spredaj ki se premika ko ga zavrnemo se zamenjata
in sedaj vidimo spodnjega
This commit is contained in:
Nikola Petrov 2024-03-06 01:52:39 +01:00
parent 4b7fb4a011
commit cf006e05e0

View File

@ -1,8 +1,11 @@
#include <array>
#include "raylib.h" #include "raylib.h"
#include "raymath.h" #include "raymath.h"
#include "Tree.hpp" #include "Tree.hpp"
#include "Math.hpp" #include "Math.hpp"
#define MAX_TREES 2
int main(void) int main(void)
{ {
char name[] = "treender"; char name[] = "treender";
@ -18,12 +21,16 @@ int main(void)
#endif #endif
SetTargetFPS(60); SetTargetFPS(60);
{ {
Tree tree(800); std::array<Tree, MAX_TREES> trees = {Tree(screenWidth), Tree(screenWidth)};
tree.newTree();
for (auto &&tree : trees)
tree.newTree();
int pos = 0;
Vector2 center = {(float)screenWidth / 2, (float)screenHeight / 2}; Vector2 center = {(float)screenWidth / 2, (float)screenHeight / 2};
float rotation = 0.0f; float rotation = 0.0f;
Rectangle dest = CalculateRect(center, rotation, screenWidth, screenWidth); Rectangle destA = CalculateRect(center, rotation, screenWidth, screenWidth);
Rectangle destB = {destA.x, destA.y, (float)screenWidth, (float)screenWidth};
while (!WindowShouldClose()) while (!WindowShouldClose())
{ {
@ -34,20 +41,22 @@ int main(void)
center.y = GetMouseY(); center.y = GetMouseY();
float l = (float)mouseX / screenWidth; float l = (float)mouseX / screenWidth;
rotation = Lerp(45.0f, -45.0f, l); rotation = Lerp(45.0f, -45.0f, l);
dest = CalculateRect(center, rotation, screenWidth, screenWidth); destA = CalculateRect(center, rotation, screenWidth, screenWidth);
} }
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
{ {
tree.newTree(); trees[1 - pos].newTree();
pos = 1 - pos;
rotation = 0.0f; rotation = 0.0f;
center.x = screenWidth / 2; center.x = screenWidth / 2;
center.y = screenHeight / 2; center.y = screenHeight / 2;
dest = CalculateRect(center, rotation, screenWidth, screenWidth); destA = CalculateRect(center, rotation, screenWidth, screenWidth);
} }
BeginDrawing(); BeginDrawing();
ClearBackground(RED); ClearBackground(RED);
tree.draw(dest, rotation); trees[pos].draw(destB, 0.0f);
trees[1 - pos].draw(destA, rotation);
EndDrawing(); EndDrawing();
} }
} }