From 3e16eb8d2f15d40239bdf1f375daeab7bcdf95fa Mon Sep 17 00:00:00 2001
From: salaaad2 <arthurdurant263@gmail.com>
Date: Mon, 11 Jul 2022 21:24:00 +0200
Subject: dod

---
 meta/media/img/crosshair.png | Bin 0 -> 184 bytes
 src/main.cpp                 |  16 ++++----
 src/yabs_core.cpp            |  94 +++++++++++++++++++++++--------------------
 src/yabs_core.h              |  35 ++++------------
 src/yabs_structs.h           |  48 ++++++++++++++++++++++
 src/yabs_utils.cpp           |   1 +
 src/yabs_utils.h             |   9 +++--
 7 files changed, 120 insertions(+), 83 deletions(-)
 create mode 100644 meta/media/img/crosshair.png
 create mode 100644 src/yabs_structs.h

diff --git a/meta/media/img/crosshair.png b/meta/media/img/crosshair.png
new file mode 100644
index 0000000..d17bcb5
Binary files /dev/null and b/meta/media/img/crosshair.png differ
diff --git a/src/main.cpp b/src/main.cpp
index 4ba1970..69702ad 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,7 +10,7 @@
 #include "yabs_core.h"
 #include "yabs_utils.h"
 
-static yabs::gameState game_state = yabs::GAMEPLAY;
+static yabs::core::gameState game_state = yabs::core::GAMEPLAY;
 
 int main(void) {
     // create window
@@ -20,20 +20,20 @@ int main(void) {
     // game loop
     while (!WindowShouldClose()) {
         switch (game_state) {
-            case (yabs::TITLE): {
+            case (yabs::core::TITLE): {
                 if (IsKeyPressed(KEY_ENTER))
                 {
-                    game_state = yabs::GAMEPLAY;
+                    game_state = yabs::core::GAMEPLAY;
                 }
                 break;
             }
-            case (yabs::PICK): {
+            case (yabs::core::PICK): {
                 break;
             }
-            case (yabs::DEATH): {
+            case (yabs::core::DEATH): {
                 break;
             }
-            case (yabs::GAMEPLAY): {
+            case (yabs::core::GAMEPLAY): {
                 if (!started)
                 {
                     started = true;
@@ -41,10 +41,10 @@ int main(void) {
                 }
                 break;
             }
-            case (yabs::NEXT): {
+            case (yabs::core::NEXT): {
                 break;
             }
-            case (yabs::ENDING): {
+            case (yabs::core::ENDING): {
                 break;
             }
         }
diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp
index 5ae5b57..c6fdb1a 100644
--- a/src/yabs_core.cpp
+++ b/src/yabs_core.cpp
@@ -12,10 +12,11 @@
 #include <strings.h>
 
 #include "yabs_core.h"
+#include "yabs_utils.h"
 
 namespace yabs {
 namespace core {
-static yabs::Scene3D sc3d{
+static Scene3D sc3d{
     // camera
     {{5.0f, 5.0f, 5.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, 45.0f, 0},
     // movement
@@ -25,7 +26,17 @@ static yabs::Scene3D sc3d{
     // mouse
     {0.0f, 0.0f}};
 
-int draw(World& world) {
+static float vert_accel = 0.0f;
+
+// input keys array
+static bool direction[4] = {
+        false,
+        false,
+        false,
+        false};
+static BoundingBox range{};
+
+int render(RenderObjs & robjs) {
     // draw checkerboard model
     for (int x = 0; x < 50; x++) {
         for (int z = 0; z < 50; z++) {
@@ -33,29 +44,16 @@ int draw(World& world) {
             position.x = x;
             position.y = -0.5f;
             position.z = z;
-            DrawModel(world.ground, position, 1.0f, WHITE);
+            DrawModel(robjs.ground, position, 1.0f, WHITE);
         }
     }
-    for (auto & enemy : world.enemies) {
-        if (enemy->active)
-        {
-            DrawCube(enemy->enemyBoxPos, 2.0f, 2.0f, 2.0f, YABS_COOLPURPLE);
-        }
+    for (auto & pos : robjs.vEnemyPos) {
+        DrawCube(*pos, 2.0f, 2.0f, 2.0f, YABS_COOLPURPLE);
     }
     return (0);
 }
 
-static float vert_accel = 0.0f;
-
-// input keys array
-static bool direction[4] = {
-        false,
-        false,
-        false,
-        false};
-static BoundingBox range{};
-
-int tick(World& world, Scene3D& scene_3d) {
+int tick(TickObjs& tobjs, Scene3D& scene_3d) {
     // mouse look
     Vector2 mouseMovement =
         Vector2Subtract(GetMousePosition(), scene_3d.lastMousePos);
@@ -66,8 +64,7 @@ int tick(World& world, Scene3D& scene_3d) {
         (mouseMovement.y * -YABS_CAMERA_MOUSE_MOVE_SENSITIVITY);
 
     // direction array
-    if (scene_3d.camera.position.y <= YABS_GROUND_LEVEL)
-    {
+    if (scene_3d.camera.position.y <= YABS_GROUND_LEVEL) {
         bzero(&direction, sizeof(direction));
         direction[0] = IsKeyDown(KEY_W);
         direction[1] = IsKeyDown(KEY_S);
@@ -75,7 +72,6 @@ int tick(World& world, Scene3D& scene_3d) {
         direction[3] = IsKeyDown(KEY_A);
     }
 
-
     // compute movement
     scene_3d.movement.x = (sinf(scene_3d.rotation.x) * direction[1] -
                            sinf(scene_3d.rotation.x) * direction[0] -
@@ -113,7 +109,10 @@ int tick(World& world, Scene3D& scene_3d) {
     if (IsKeyPressed(KEY_LEFT_CONTROL))
         vert_accel -= 0.05;
     if (IsKeyPressed(KEY_ESCAPE))
+    {
+        *tobjs.alive = false;
         return (0);
+    }
 
     // apply movement
     scene_3d.camera.position.x +=
@@ -135,25 +134,22 @@ int tick(World& world, Scene3D& scene_3d) {
 
     // shoot
     range = {{
-            scene_3d.camera.target.x - 0.5f,
-            scene_3d.camera.target.y - 4.0f,
-            scene_3d.camera.target.z - 0.5f,},{
-            scene_3d.camera.target.x + 0.5f,
-            scene_3d.camera.target.y + 5.5f,
-            scene_3d.camera.target.z + 0.5f}
-    };
-    if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
-    {
-        for (auto it = world.enemies.begin(); it != world.enemies.end(); ++it)
-        {
-            if(CheckCollisionBoxes(range, (*it)->enemyBounds))
-            {
+        scene_3d.camera.target.x,
+        scene_3d.camera.target.y,
+        scene_3d.camera.target.z
+        }, {
+        scene_3d.camera.target.x + 1.5f,
+        scene_3d.camera.target.y + 5.5f,
+        scene_3d.camera.target.z + 1.5f
+    }};
+
+    if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+        for (auto it = tobjs.vEnemyBounds.begin(); it != tobjs.vEnemyBounds.end(); ++it) {
+            if(CheckCollisionBoxes(range, *(*it))) { // :^}
                 std::cerr << "hit enemy\n";
-                (*it)->active = false;
-                world.enemies.erase(it);
+                break ;
                 // erase() invalidates iterators, we have to break
                 //  empty space
-                break;
             }
         }
     }
@@ -187,16 +183,24 @@ void init_game()
     sc3d.movement = (Vector3){0.0f, 0.0f, 0.0f};
     Vector3 cubeSize = {2.0f, 2.0f, 2.0f};
 
-    World world = {
+    RenderObjs robjs = {
+        std::vector<Vector3*>(),
         model
     };
 
+    TickObjs tobjs = {
+        std::vector<BoundingBox*>(),
+        std::vector<Vector3*>(),
+        &range,
+        &sc3d.camera.position,
+        {direction},
+        &alive
+    };
+
     // baddies
     for (int i = 0; i < ENEMIES_N; i++)
     {
         Enemy * e = new Enemy();
-        world.enemies.push_back(e);
-
         e->enemyStartPos.x = rand() % 32;
         e->enemyStartPos.y = 1.0f;
         e->enemyStartPos.z = rand() % 32;
@@ -209,6 +213,9 @@ void init_game()
             {e->enemyBoxPos.x - 2.5f, 0.0f, e->enemyBoxPos.z - 2.5f},
             {e->enemyBoxPos.x + 2.5f, 2.5f, e->enemyBoxPos.z + 2.5f}
         };
+        robjs.vEnemyPos.push_back(&e->enemyBoxPos);
+        tobjs.vEnemyBounds.push_back(&e->enemyBounds);
+        tobjs.vEnemyPos.push_back(&e->enemyBoxPos);
     }
 
     Texture2D crosshair;
@@ -221,8 +228,8 @@ void init_game()
         ClearBackground(GRAY);
         BeginMode3D(sc3d.camera);
 
-        alive = tick(world, sc3d);
-        draw(world);
+        tick(tobjs, sc3d);
+        render(robjs);
 
         EndMode3D();
         DrawTexture(crosshair, YABS_HALFSWIDTH, YABS_HALFSHEIGHT, WHITE);
@@ -231,7 +238,6 @@ void init_game()
                     0, 20, DARKGRAY);
         EndDrawing();
     }
-    // cleanupAndExit(world);
     UnloadTexture(texture);
     UnloadModel(model);
 }
diff --git a/src/yabs_core.h b/src/yabs_core.h
index d8f111d..8ca4cfe 100644
--- a/src/yabs_core.h
+++ b/src/yabs_core.h
@@ -1,6 +1,3 @@
-#ifndef YABS_CORE_H
-#define YABS_CORE_H
-
 /*********************************/
 /*   YABS             (  //      */
 /*   yabs_CORE         ( )/      */
@@ -9,10 +6,15 @@
 /* ()__)____________)))))   :^}  */
 /*********************************/
 
+#ifndef YABS_CORE_H
+#define YABS_CORE_H
+
 #include "raylib.h"
 #include "raymath.h"
 #include <vector>
 
+#include "yabs_structs.h"
+
 #ifdef __FreeBSD__
 #  define YABS_SCREENWIDTH 1280
 #  define YABS_SCREENHEIGHT 720
@@ -43,6 +45,7 @@
     CLITERAL(Color) { 153, 0, 0, 255 }  // cool Purple
 
 namespace yabs {
+namespace core {
 
 typedef struct Scene3D {
     Camera camera;
@@ -61,35 +64,13 @@ typedef enum gameState {
 } gameState;
 
 // core functions and structs
-namespace core {
-
-typedef struct Player {
-    int hp;
-    Vector3 pos;
-}Player;
-
-typedef struct Enemy {
-    Vector3 enemyStartPos;
-    Vector3 enemyBoxPos;
-    Vector3 enemyBoxSize;
-    BoundingBox enemyBounds;
-    bool active;
-} Enemy;
-
-typedef struct World {
-    Model & ground;
-    std::vector<Enemy*> enemies;
-    Player * player;
-} World;
 
 int reset_camera(Scene3D& scene_3d);
-int draw(World& world);
-int tick(World& world, Scene3D& scene_3d);
+int render(RenderObjs & robjs);
+int tick(TickObjs & tobjs, Scene3D & scene_3d);
 void init_game();
-void cleanupAndExit(World & world);
 
 }  // namespace core
-
 }  // namespace yabs
 
 #endif /* YABS_CORE_H */
diff --git a/src/yabs_structs.h b/src/yabs_structs.h
new file mode 100644
index 0000000..c6f1d30
--- /dev/null
+++ b/src/yabs_structs.h
@@ -0,0 +1,48 @@
+/*********************************/
+/*   YABS             (  //      */
+/*   structs           ( )/      */
+/*   by salade         )(/       */
+/*  ________________  ( /)       */
+/* ()__)____________)))))   :^}  */
+/*********************************/
+
+#ifndef YABS_STRUCTS_H
+#define YABS_STRUCTS_H
+
+#include "raylib.h"
+#include <vector>
+
+namespace yabs {
+namespace core {
+
+typedef struct Player {
+    int hp;
+    Vector3 pos;
+}Player;
+
+typedef struct Enemy {
+    Vector3 enemyStartPos;
+    Vector3 enemyBoxPos;
+    Vector3 enemyBoxSize;
+    BoundingBox enemyBounds;
+    bool active;
+} Enemy;
+
+typedef struct RenderObjs {
+    std::vector<Vector3 *> vEnemyPos;
+    Model & ground;
+} RenderObjs;
+
+typedef struct TickObjs {
+    std::vector<BoundingBox *> vEnemyBounds;
+    std::vector<Vector3 *> vEnemyPos;
+    BoundingBox * range;
+    Vector3 * position;
+    bool * direction[4];
+    bool * alive;
+} TickObjs;
+
+}
+}
+
+#endif /* YABS_STRUCTS_H */
diff --git a/src/yabs_utils.cpp b/src/yabs_utils.cpp
index ca60489..0c49228 100644
--- a/src/yabs_utils.cpp
+++ b/src/yabs_utils.cpp
@@ -7,6 +7,7 @@
 /*********************************/
 
 #include "yabs_utils.h"
+#include <raylib.h>
 
 namespace utils {
 // unused, for now :^}
diff --git a/src/yabs_utils.h b/src/yabs_utils.h
index 6006935..a931189 100644
--- a/src/yabs_utils.h
+++ b/src/yabs_utils.h
@@ -1,6 +1,3 @@
-#ifndef YABS_UTILS_H
-#define YABS_UTILS_H
-
 /*********************************/
 /*   YABS             (  //      */
 /*   yabs_gameplay     ( )/      */
@@ -9,11 +6,15 @@
 /* ()__)____________)))))   :^}  */
 /*********************************/
 
+#ifndef YABS_UTILS_H
+#define YABS_UTILS_H
+
 namespace utils {
 // unused, for now :^}
 int min(int v1, int v2);
 int max(int v1, int v2);
 int clamp(int v, int v1, int v2);
-}  // namespace utils
+} // namespace utils
+
 
 #endif /* YABS_UTILS_H */
-- 
cgit v1.2.3


From e9f441064c50af95a1803fd616a3b577648be668 Mon Sep 17 00:00:00 2001
From: salaaad2 <arthurdurant263@gmail.com>
Date: Sat, 20 Aug 2022 23:45:40 +0200
Subject: something probably happenned I dunno

---
 README.org        |  0
 src/yabs_core.cpp | 41 +++++++++++++++++++++++------------------
 src/yabs_core.h   |  6 +++---
 3 files changed, 26 insertions(+), 21 deletions(-)
 create mode 100644 README.org

diff --git a/README.org b/README.org
new file mode 100644
index 0000000..e69de29
diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp
index c6fdb1a..31cfa3c 100644
--- a/src/yabs_core.cpp
+++ b/src/yabs_core.cpp
@@ -7,6 +7,7 @@
 /*********************************/
 
 #include <raylib.h>
+#include <raymath.h>
 #include <stdlib.h>
 #include <iostream>
 #include <strings.h>
@@ -127,31 +128,35 @@ int tick(TickObjs& tobjs, Scene3D& scene_3d) {
                                   YABS_DOUBLEPI - scene_3d.rotation.x, 0});
     Matrix transform = MatrixMultiply(translation, rotation2);
 
+
     // apply camera rotation
     scene_3d.camera.target.x = scene_3d.camera.position.x - transform.m12;
     scene_3d.camera.target.y = scene_3d.camera.position.y - transform.m13;
     scene_3d.camera.target.z = scene_3d.camera.position.z - transform.m14;
 
-    // shoot
-    range = {{
-        scene_3d.camera.target.x,
-        scene_3d.camera.target.y,
-        scene_3d.camera.target.z
-        }, {
-        scene_3d.camera.target.x + 1.5f,
-        scene_3d.camera.target.y + 5.5f,
-        scene_3d.camera.target.z + 1.5f
-    }};
+    range = {
+        {scene_3d.camera.target.x - 10.5f,
+         scene_3d.camera.target.y - 1.0f,
+         scene_3d.camera.target.z - 10.5f},
+        {scene_3d.camera.target.x + 10.5f,
+         scene_3d.camera.target.y + 1.5f,
+         scene_3d.camera.target.z + 10.5f}
+    };
 
     if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
-        for (auto it = tobjs.vEnemyBounds.begin(); it != tobjs.vEnemyBounds.end(); ++it) {
-            if(CheckCollisionBoxes(range, *(*it))) { // :^}
+        for (auto i = 0; i < tobjs.vEnemyBounds.size(); ++i) {
+            if(CheckCollisionBoxes(range, *tobjs.vEnemyBounds[i])) { // :^}
                 std::cerr << "hit enemy\n";
                 break ;
-                // erase() invalidates iterators, we have to break
-                //  empty space
+            //std::cout << "r: " <<
+                //"{" << range.min.x<< "," << range.min.x << "," << range.min.z << "}," <<
+                //"{" << range.max.x<< "," << range.max.x << "," << range.max.z << "}\n";
+            //std::cout << "b: " <<
+                //"{" << (*it)->min.x<< "," << (*it)->min.x << "," << (*it)->min.z << "}," <<
+                //"{" << (*it)->max.x << ","<< (*it)->max.x << "," << (*it)->max.z << "}\n";
             }
         }
+        std::cerr << "missed\n";
     }
     return (1);
 }
@@ -201,17 +206,17 @@ void init_game()
     for (int i = 0; i < ENEMIES_N; i++)
     {
         Enemy * e = new Enemy();
-        e->enemyStartPos.x = rand() % 32;
+        e->enemyStartPos.x = GetRandomValue(20, 40);
         e->enemyStartPos.y = 1.0f;
-        e->enemyStartPos.z = rand() % 32;
+        e->enemyStartPos.z = GetRandomValue(20, 40);
         e->enemyBoxPos.x = e->enemyStartPos.x;
         e->enemyBoxPos.y = e->enemyStartPos.y;
         e->enemyBoxPos.z = e->enemyStartPos.z;
         e->enemyBoxSize = cubeSize;
         e->active = true;
         e->enemyBounds = {
-            {e->enemyBoxPos.x - 2.5f, 0.0f, e->enemyBoxPos.z - 2.5f},
-            {e->enemyBoxPos.x + 2.5f, 2.5f, e->enemyBoxPos.z + 2.5f}
+            {e->enemyBoxPos.x -2.5f, 0.0f, e->enemyBoxPos.z-2.5f},
+            {e->enemyBoxPos.x+2.5f, 2.5f, e->enemyBoxPos.z+2.5f}
         };
         robjs.vEnemyPos.push_back(&e->enemyBoxPos);
         tobjs.vEnemyBounds.push_back(&e->enemyBounds);
diff --git a/src/yabs_core.h b/src/yabs_core.h
index 8ca4cfe..dd712eb 100644
--- a/src/yabs_core.h
+++ b/src/yabs_core.h
@@ -16,11 +16,11 @@
 #include "yabs_structs.h"
 
 #ifdef __FreeBSD__
-#  define YABS_SCREENWIDTH 1280
+#  define YABS_SCREENWIDTH 1080
 #  define YABS_SCREENHEIGHT 720
 #else
-#  define YABS_SCREENWIDTH 1600
-#  define YABS_SCREENHEIGHT 900
+#  define YABS_SCREENWIDTH 1080
+#  define YABS_SCREENHEIGHT 720
 #endif
 
 #define YABS_TITLE "YABS"
-- 
cgit v1.2.3