From cf006e05e07366eeec8abc031c39183b707ef429 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Wed, 6 Mar 2024 01:52:39 +0100 Subject: [PATCH] Add multiple tree eden je spredaj ki se premika ko ga zavrnemo se zamenjata in sedaj vidimo spodnjega --- src/main.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fc7a2a6..1528d37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,11 @@ +#include #include "raylib.h" #include "raymath.h" #include "Tree.hpp" #include "Math.hpp" +#define MAX_TREES 2 + int main(void) { char name[] = "treender"; @@ -18,12 +21,16 @@ int main(void) #endif SetTargetFPS(60); { - Tree tree(800); - tree.newTree(); + std::array trees = {Tree(screenWidth), Tree(screenWidth)}; + + for (auto &&tree : trees) + tree.newTree(); + int pos = 0; Vector2 center = {(float)screenWidth / 2, (float)screenHeight / 2}; 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()) { @@ -34,20 +41,22 @@ int main(void) center.y = GetMouseY(); float l = (float)mouseX / screenWidth; rotation = Lerp(45.0f, -45.0f, l); - dest = CalculateRect(center, rotation, screenWidth, screenWidth); + destA = CalculateRect(center, rotation, screenWidth, screenWidth); } if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { - tree.newTree(); + trees[1 - pos].newTree(); + pos = 1 - pos; rotation = 0.0f; center.x = screenWidth / 2; center.y = screenHeight / 2; - dest = CalculateRect(center, rotation, screenWidth, screenWidth); + destA = CalculateRect(center, rotation, screenWidth, screenWidth); } BeginDrawing(); ClearBackground(RED); - tree.draw(dest, rotation); + trees[pos].draw(destB, 0.0f); + trees[1 - pos].draw(destA, rotation); EndDrawing(); } }