aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-06-09 22:58:20 +0200
committersalaaad2 <arthurdurant263@gmail.com>2022-06-09 22:59:32 +0200
commit947af225e80e48c46ef83f0b7cdb1e1274ba96dd (patch)
treeebc235563cfb223d0fa7100eb5c8b4d760fdf281
parentstructure, namespaces, cool stuff overall (diff)
downloadyabs-947af225e80e48c46ef83f0b7cdb1e1274ba96dd.tar.gz
yabs-947af225e80e48c46ef83f0b7cdb1e1274ba96dd.tar.bz2
yabs-947af225e80e48c46ef83f0b7cdb1e1274ba96dd.tar.xz
yabs-947af225e80e48c46ef83f0b7cdb1e1274ba96dd.tar.zst
yabs-947af225e80e48c46ef83f0b7cdb1e1274ba96dd.zip
make everything better
-rw-r--r--CMakeLists.txt17
-rw-r--r--src/main.cpp114
-rw-r--r--src/yabs_core.cpp23
-rw-r--r--src/yabs_core.h54
-rw-r--r--src/yabs_utils.cpp24
-rw-r--r--src/yabs_utils.h19
6 files changed, 205 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 68c5abc..9429c52 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,15 +3,24 @@ project(shooter)
find_package(raylib 3.0 REQUIRED) # Requires at least version 3.0
-set(CMAKE_C_STANDARD 11) # Requires C11 standard
-
set (CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME}
+ src/yabs_core.cpp
src/yabs_utils.cpp
- src/main.cpp)
+ src/main.cpp
+)
+
+target_link_libraries(${PROJECT_NAME}
+ raylib
+ m
+)
-target_link_libraries(${PROJECT_NAME} raylib m)
+target_compile_options(${PROJECT_NAME}
+ PRIVATE "-O3"
+ PRIVATE "-march=native"
+ PRIVATE "-Wall"
+)
# Checks if OSX and links appropriate frameworks (only required on MacOS)
if (APPLE)
diff --git a/src/main.cpp b/src/main.cpp
index d3481ad..8033d5a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,26 +1,32 @@
+/*********************************/
+/* YABS ( // */
+/* main ( )/ */
+/* by salade )(/ */
+/* ________________ ( /) */
+/* ()__)____________))))) :^} */
+/*********************************/
+
#include <stdlib.h>
#include "raylib.h"
#include "raymath.h"
-#include "yabs_defines.h"
+#include "yabs_core.h"
#include "yabs_utils.h"
-#include "yabs_gameplay.h"
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}
-};
+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);
+ InitWindow(YABS_SCREENWIDTH, YABS_SCREENHEIGHT, YABS_TITLE);
// create image
Image checked = GenImageChecked(2, 2, 1, 1, BLACK, GRAY);
@@ -46,28 +52,47 @@ int main(void) {
// game loop
while (!WindowShouldClose()) {
switch (game_state) {
- case (yabs::TITLE):
- {
+ case (yabs::TITLE): {
+ break;
+ }
+ case (yabs::PICK): {
+ break;
+ }
+ case (yabs::DEATH): {
+ break;
+ }
+ case (yabs::GAMEPLAY): {
+ yabs::core::reset_camera(sc3d);
+ break;
+ }
+ case (yabs::NEXT): {
+ break;
+ }
+ case (yabs::ENDING): {
+ break;
+ }
+ }
+
+ switch (game_state) {
+ case (yabs::TITLE): {
break;
}
- case (yabs::PICK):
- {
+ case (yabs::PICK): {
break;
}
- case (yabs::DEATH):
- {
+ case (yabs::DEATH): {
break;
}
- case (yabs::GAMEPLAY):
- {
+ case (yabs::GAMEPLAY): {
+ while (game_state != yabs::NEXT) {
+ yabs::core::draw(game_state);
+ }
break;
}
- case (yabs::NEXT):
- {
+ case (yabs::NEXT): {
break;
}
- case (yabs::ENDING):
- {
+ case (yabs::ENDING): {
break;
}
}
@@ -75,8 +100,10 @@ int main(void) {
Vector2 mouseMovement =
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);
+ sc3d.rotation.x +=
+ (mouseMovement.x * -YABS_CAMERA_MOUSE_MOVE_SENSITIVITY);
+ sc3d.rotation.y +=
+ (mouseMovement.y * -YABS_CAMERA_MOUSE_MOVE_SENSITIVITY);
// direction array
bool direction[4] = {IsKeyDown(KEY_W), IsKeyDown(KEY_S),
@@ -84,16 +111,16 @@ int main(void) {
// compute movement
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;
- 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;
+ 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]) /
+ YABS_PLAYER_MOVEMENT_SENSITIVITY;
+ 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]) /
+ YABS_PLAYER_MOVEMENT_SENSITIVITY;
// elevation
if (IsKeyDown(KEY_SPACE))
sc3d.movement.y += 0.12f;
@@ -101,13 +128,15 @@ int main(void) {
sc3d.movement.y -= 0.12f;
// apply movement
- sc3d.camera.position.x += sc3d.movement.x / G_PLAYER_MOVEMENT_SENSITIVITY;
+ sc3d.camera.position.x +=
+ sc3d.movement.x / YABS_PLAYER_MOVEMENT_SENSITIVITY;
sc3d.camera.position.y += sc3d.movement.y;
- sc3d.camera.position.z += sc3d.movement.z / G_PLAYER_MOVEMENT_SENSITIVITY;
+ sc3d.camera.position.z +=
+ sc3d.movement.z / YABS_PLAYER_MOVEMENT_SENSITIVITY;
Matrix translation = MatrixTranslate(0, 0, (10));
- Matrix rotation2 = MatrixRotateXYZ(
- (Vector3){DOUBLEPI - sc3d.rotation.y, DOUBLEPI - sc3d.rotation.x, 0});
+ Matrix rotation2 = MatrixRotateXYZ((Vector3){
+ DOUBLEPI - sc3d.rotation.y, DOUBLEPI - sc3d.rotation.x, 0});
Matrix transform = MatrixMultiply(translation, rotation2);
// apply camera rotation
@@ -131,7 +160,8 @@ int main(void) {
EndMode3D();
DrawFPS(0, 0);
- DrawText("Controls - Mouse / WASD / R/F.", 400, 0, 20, DARKGRAY);
+ DrawText("Controls: Mouse / WASD / SPACE/CTRL.", YABS_SCREENWIDTH - 400,
+ 0, 20, DARKGRAY);
EndDrawing();
}
UnloadTexture(texture);
diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp
new file mode 100644
index 0000000..6252b14
--- /dev/null
+++ b/src/yabs_core.cpp
@@ -0,0 +1,23 @@
+/*********************************/
+/* YABS ( // */
+/* main ( )/ */
+/* by salade )(/ */
+/* ________________ ( /) */
+/* ()__)____________))))) :^} */
+/*********************************/
+
+#include "yabs_core.h"
+
+namespace yabs {
+namespace core {
+
+int reset_camera(Scene3D const& scene_3d) {
+ return (0);
+}
+
+int draw(gameState const& game_state) {
+ return (0);
+}
+
+} // namespace core
+} // namespace yabs
diff --git a/src/yabs_core.h b/src/yabs_core.h
new file mode 100644
index 0000000..15a6d4c
--- /dev/null
+++ b/src/yabs_core.h
@@ -0,0 +1,54 @@
+#ifndef YABS_CORE_H
+#define YABS_CORE_H
+
+/*********************************/
+/* YABS ( // */
+/* yabs_CORE ( )/ */
+/* by salade )(/ */
+/* ________________ ( /) */
+/* ()__)____________))))) :^} */
+/*********************************/
+
+#include "raylib.h"
+
+#define YABS_SCREENWIDTH 1600
+#define YABS_SCREENHEIGHT 900
+#define YABS_TITLE "YABS"
+
+#define YABS_DOUBLEPI 6.28318530717958647692f
+
+#define YABS_PLAYER_MOVEMENT_SENSITIVITY 3
+#define YABS_CAMERA_MOUSE_MOVE_SENSITIVITY 0.0005f
+
+namespace yabs {
+
+typedef struct Scene3D {
+ Camera camera;
+ Vector3 movement;
+ Vector3 rotation;
+ Vector2 lastMousePos;
+} Scene3D;
+
+typedef enum gameState {
+ TITLE = 0,
+ PICK,
+ DEATH,
+ GAMEPLAY,
+ NEXT,
+ ENDING
+} gameState;
+
+// core functions
+namespace core {
+
+// draw takes a reference to the game_state, which is checked on each frame
+// for next level or death
+int reset_camera(Scene3D const& scene_3d);
+
+int draw(gameState const& game_state);
+
+} // namespace core
+
+} // namespace yabs
+
+#endif /* YABS_CORE_H */
diff --git a/src/yabs_utils.cpp b/src/yabs_utils.cpp
new file mode 100644
index 0000000..ca60489
--- /dev/null
+++ b/src/yabs_utils.cpp
@@ -0,0 +1,24 @@
+/*********************************/
+/* YABS ( // */
+/* yabs_gameplay ( )/ */
+/* by salade )(/ */
+/* ________________ ( /) */
+/* ()__)____________))))) :^} */
+/*********************************/
+
+#include "yabs_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/yabs_utils.h b/src/yabs_utils.h
new file mode 100644
index 0000000..6006935
--- /dev/null
+++ b/src/yabs_utils.h
@@ -0,0 +1,19 @@
+#ifndef YABS_UTILS_H
+#define YABS_UTILS_H
+
+/*********************************/
+/* YABS ( // */
+/* yabs_gameplay ( )/ */
+/* by salade )(/ */
+/* ________________ ( /) */
+/* ()__)____________))))) :^} */
+/*********************************/
+
+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 /* YABS_UTILS_H */