aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/main.cpp113
-rw-r--r--src/rfps_defines.h10
-rw-r--r--src/rfps_utils.cpp16
-rw-r--r--src/rfps_utils.h11
5 files changed, 74 insertions, 78 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa535c8..68c5abc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(CMAKE_C_STANDARD 11) # Requires C11 standard
set (CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME}
- src/rfps_utils.cpp
+ src/yabs_utils.cpp
src/main.cpp)
target_link_libraries(${PROJECT_NAME} raylib m)
diff --git a/src/main.cpp b/src/main.cpp
index f9d8095..d3481ad 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,19 +2,28 @@
#include "raylib.h"
#include "raymath.h"
-#include "rfps_defines.h"
-#include "rfps_utils.h"
+#include "yabs_defines.h"
+#include "yabs_utils.h"
+#include "yabs_gameplay.h"
-static Vector2 lastMousePos;
-static Vector3 movement = {0, -0.2f, 0};
-static Vector3 rotation;
+static yabs::gameState game_state;
+static yabs::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
+{0.0f, 0.0f},
+// rotation
+{0.0f, -0.2f, 0.0f},
+// mouse
+{0.0f, 0.0f}
+};
int main(void) {
// create window
InitWindow(G_SCREENWIDTH, G_SCREENHEIGHT, G_TITLE);
// create image
- Image checked = GenImageChecked(2, 2, 1, 1, BLACK, RAYWHITE);
+ Image checked = GenImageChecked(2, 2, 1, 1, BLACK, GRAY);
Texture2D texture = LoadTextureFromImage(checked);
UnloadImage(checked);
@@ -24,66 +33,90 @@ int main(void) {
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
// setup camera
- Camera camera = {
- {5.0f, 5.0f, 5.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, 45.0f, 0};
- SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode
- camera.position = (Vector3){50.0f, 1.0f, 50.0f};
- camera.target = (Vector3){50.0f, 1.0f, 50.0f};
- camera.up = (Vector3){0.0f, 1.0f, 0.0f};
- camera.fovy = 60.0f;
- camera.projection = CAMERA_PERSPECTIVE;
+ SetCameraMode(sc3d.camera, CAMERA_FIRST_PERSON); // Set camera mode
+ sc3d.camera.position = (Vector3){50.0f, 1.0f, 50.0f};
+ sc3d.camera.target = (Vector3){50.0f, 1.0f, 50.0f};
+ sc3d.camera.up = (Vector3){0.0f, 1.0f, 0.0f};
+ sc3d.camera.fovy = 90.0f;
+ sc3d.camera.projection = CAMERA_PERSPECTIVE;
- rotation = (Vector3){0.0f, 0.0f, 0.0f};
- lastMousePos = GetMousePosition();
+ sc3d.rotation = (Vector3){0.0f, 0.0f, 0.0f};
+ sc3d.lastMousePos = GetMousePosition();
SetTargetFPS(60);
// game loop
while (!WindowShouldClose()) {
+ switch (game_state) {
+ case (yabs::TITLE):
+ {
+ break;
+ }
+ case (yabs::PICK):
+ {
+ break;
+ }
+ case (yabs::DEATH):
+ {
+ break;
+ }
+ case (yabs::GAMEPLAY):
+ {
+ break;
+ }
+ case (yabs::NEXT):
+ {
+ break;
+ }
+ case (yabs::ENDING):
+ {
+ break;
+ }
+ }
// mouse look
Vector2 mouseMovement =
- Vector2Subtract(GetMousePosition(), lastMousePos);
- lastMousePos = GetMousePosition();
- rotation.x += (mouseMovement.x * -G_CAMERA_MOUSE_MOVE_SENSITIVITY);
- rotation.y += (mouseMovement.y * -G_CAMERA_MOUSE_MOVE_SENSITIVITY);
+ Vector2Subtract(GetMousePosition(), sc3d.lastMousePos);
+ sc3d.lastMousePos = GetMousePosition();
+ sc3d.rotation.x += (mouseMovement.x * -G_CAMERA_MOUSE_MOVE_SENSITIVITY);
+ sc3d.rotation.y += (mouseMovement.y * -G_CAMERA_MOUSE_MOVE_SENSITIVITY);
// direction array
bool direction[4] = {IsKeyDown(KEY_W), IsKeyDown(KEY_S),
IsKeyDown(KEY_D), IsKeyDown(KEY_A)};
// compute movement
- movement = (Vector3){0, 0, 0};
- movement.x =
- (sinf(rotation.x) * direction[1] - sinf(rotation.x) * direction[0] -
- cosf(rotation.x) * direction[3] +
- cosf(rotation.x) * direction[2]) /
+ sc3d.movement = (Vector3){0, 0, 0};
+ sc3d.movement.x =
+ (sinf(sc3d.rotation.x) * direction[1] - sinf(sc3d.rotation.x) * direction[0] -
+ cosf(sc3d.rotation.x) * direction[3] +
+ cosf(sc3d.rotation.x) * direction[2]) /
G_PLAYER_MOVEMENT_SENSITIVITY;
- movement.z =
- (cosf(rotation.x) * direction[1] - cosf(rotation.x) * direction[0] +
- sinf(rotation.x) * direction[3] -
- sinf(rotation.x) * direction[2]) /
+ sc3d.movement.z =
+ (cosf(sc3d.rotation.x) * direction[1] - cosf(sc3d.rotation.x) * direction[0] +
+ sinf(sc3d.rotation.x) * direction[3] -
+ sinf(sc3d.rotation.x) * direction[2]) /
G_PLAYER_MOVEMENT_SENSITIVITY;
// elevation
if (IsKeyDown(KEY_SPACE))
- movement.y -= 0.12f;
+ sc3d.movement.y += 0.12f;
if (IsKeyDown(KEY_LEFT_CONTROL))
- movement.y += 0.12f;
+ sc3d.movement.y -= 0.12f;
// apply movement
- camera.position.x += movement.x / G_PLAYER_MOVEMENT_SENSITIVITY;
- camera.position.y += movement.y;
- camera.position.z += movement.z / G_PLAYER_MOVEMENT_SENSITIVITY;
+ sc3d.camera.position.x += sc3d.movement.x / G_PLAYER_MOVEMENT_SENSITIVITY;
+ sc3d.camera.position.y += sc3d.movement.y;
+ sc3d.camera.position.z += sc3d.movement.z / G_PLAYER_MOVEMENT_SENSITIVITY;
Matrix translation = MatrixTranslate(0, 0, (10));
Matrix rotation2 = MatrixRotateXYZ(
- (Vector3){PI * 2 - rotation.y, PI * 2 - rotation.x, 0});
+ (Vector3){DOUBLEPI - sc3d.rotation.y, DOUBLEPI - sc3d.rotation.x, 0});
Matrix transform = MatrixMultiply(translation, rotation2);
// apply camera rotation
- camera.target.x = camera.position.x - transform.m12;
- camera.target.y = camera.position.y - transform.m13;
- camera.target.z = camera.position.z - transform.m14;
+ sc3d.camera.target.x = sc3d.camera.position.x - transform.m12;
+ sc3d.camera.target.y = sc3d.camera.position.y - transform.m13;
+ sc3d.camera.target.z = sc3d.camera.position.z - transform.m14;
BeginDrawing();
- ClearBackground(RAYWHITE);
- BeginMode3D(camera);
+ ClearBackground(GRAY);
+ BeginMode3D(sc3d.camera);
// draw checkerboard model
for (int x = 0; x < 50; x++) {
diff --git a/src/rfps_defines.h b/src/rfps_defines.h
deleted file mode 100644
index 80faa31..0000000
--- a/src/rfps_defines.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef RFPS_DEFINES_H
-#define RFPS_DEFINES_H
-
-#define G_PLAYER_MOVEMENT_SENSITIVITY 3
-#define G_CAMERA_MOUSE_MOVE_SENSITIVITY 0.00f
-#define G_SCREENWIDTH 1600
-#define G_SCREENHEIGHT 900
-#define G_TITLE "RFPS"
-
-#endif /* RFPS_DEFINES_H */
diff --git a/src/rfps_utils.cpp b/src/rfps_utils.cpp
deleted file mode 100644
index c595a21..0000000
--- a/src/rfps_utils.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "rfps_utils.h"
-
-namespace utils {
-// unused, for now :^}
-int min(const int& v1, const int& v2) {
- return v1 >= v2 ? v2 : v1;
-}
-
-int max(const int& v1, const int& v2) {
- return v1 >= v2 ? v1 : v2;
-}
-
-int clamp(const int& v, const int& v1, const int& v2) {
- return v >= v1 ? (v <= v2 ? v : v2) : v1;
-}
-} // namespace utils
diff --git a/src/rfps_utils.h b/src/rfps_utils.h
deleted file mode 100644
index d52984a..0000000
--- a/src/rfps_utils.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef RFPS_UTILS_H
-#define RFPS_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
-
-#endif /* RFPS_UTILS_H */