aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp16
-rw-r--r--src/yabs_core.cpp113
-rw-r--r--src/yabs_core.h41
-rw-r--r--src/yabs_structs.h48
-rw-r--r--src/yabs_utils.cpp1
-rw-r--r--src/yabs_utils.h9
6 files changed, 135 insertions, 93 deletions
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..31cfa3c 100644
--- a/src/yabs_core.cpp
+++ b/src/yabs_core.cpp
@@ -7,15 +7,17 @@
/*********************************/
#include <raylib.h>
+#include <raymath.h>
#include <stdlib.h>
#include <iostream>
#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 +27,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 +45,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 +65,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 +73,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 +110,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 +=
@@ -128,34 +128,35 @@ int tick(World& world, 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 - 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}
+ 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 = world.enemies.begin(); it != world.enemies.end(); ++it)
- {
- if(CheckCollisionBoxes(range, (*it)->enemyBounds))
- {
+
+ if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+ for (auto i = 0; i < tobjs.vEnemyBounds.size(); ++i) {
+ if(CheckCollisionBoxes(range, *tobjs.vEnemyBounds[i])) { // :^}
std::cerr << "hit enemy\n";
- (*it)->active = false;
- world.enemies.erase(it);
- // erase() invalidates iterators, we have to break
- // empty space
- break;
+ break ;
+ //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);
}
@@ -187,28 +188,39 @@ 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.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);
+ tobjs.vEnemyPos.push_back(&e->enemyBoxPos);
}
Texture2D crosshair;
@@ -221,8 +233,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 +243,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..dd712eb 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,16 +6,21 @@
/* ()__)____________))))) :^} */
/*********************************/
+#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_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"
@@ -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 */