diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 82 | ||||
-rw-r--r-- | src/yabs_core.cpp | 82 | ||||
-rw-r--r-- | src/yabs_core.h | 5 |
3 files changed, 82 insertions, 87 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0472a95..4ba1970 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,50 +6,25 @@ /* ()__)____________))))) :^} */ /*********************************/ +#include <raylib.h> #include "yabs_core.h" #include "yabs_utils.h" -static yabs::gameState game_state = yabs::TITLE; - -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::gameState game_state = yabs::GAMEPLAY; int main(void) { // create window InitWindow(YABS_SCREENWIDTH, YABS_SCREENHEIGHT, YABS_TITLE); + bool started = false; - // create image - Image checked = GenImageChecked(2, 2, 1, 1, BLACK, GRAY); - Texture2D texture = LoadTextureFromImage(checked); - UnloadImage(checked); - - // create model with image as texture - Model model = {}; - model = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f)); - model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; - - // setup camera - SetTargetFPS(60); - SetCameraMode(sc3d.camera, CAMERA_FIRST_PERSON); - 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; - - sc3d.rotation = (Vector3){0.0f, 0.0f, 0.0f}; - sc3d.lastMousePos = GetMousePosition(); // game loop while (!WindowShouldClose()) { switch (game_state) { case (yabs::TITLE): { + if (IsKeyPressed(KEY_ENTER)) + { + game_state = yabs::GAMEPLAY; + } break; } case (yabs::PICK): { @@ -59,28 +34,11 @@ int main(void) { 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): { - break; - } - case (yabs::DEATH): { - break; - } - case (yabs::GAMEPLAY): { + if (!started) + { + started = true; + yabs::core::init_game(); + } break; } case (yabs::NEXT): { @@ -90,23 +48,7 @@ int main(void) { break; } } - - // draw - BeginDrawing(); - ClearBackground(GRAY); - BeginMode3D(sc3d.camera); - - yabs::core::tick(sc3d); - yabs::core::draw(model); - - EndMode3D(); - DrawFPS(0, 0); - DrawText("Controls: Mouse / WASD / SPACE/CTRL.", YABS_SCREENWIDTH - 400, - 0, 20, DARKGRAY); - EndDrawing(); } - UnloadTexture(texture); - UnloadModel(model); CloseWindow(); return (0); } diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp index fabfb09..60a74cc 100644 --- a/src/yabs_core.cpp +++ b/src/yabs_core.cpp @@ -6,25 +6,22 @@ /* ()__)____________))))) :^} */ /*********************************/ +#include <raylib.h> #include <stdlib.h> #include "yabs_core.h" namespace yabs { namespace core { - -int reset_camera(Scene3D& scene_3d) { - SetCameraMode(scene_3d.camera, CAMERA_FIRST_PERSON); - scene_3d.camera.position = (Vector3){50.0f, 1.0f, 50.0f}; - scene_3d.camera.target = (Vector3){50.0f, 1.0f, 50.0f}; - scene_3d.camera.up = (Vector3){0.0f, 1.0f, 0.0f}; - scene_3d.camera.fovy = 90.0f; - scene_3d.camera.projection = CAMERA_PERSPECTIVE; - - scene_3d.rotation = (Vector3){0.0f, 0.0f, 0.0f}; - scene_3d.lastMousePos = GetMousePosition(); - return (0); -} +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 draw(Model& model) { // draw checkerboard model @@ -71,6 +68,8 @@ int tick(Scene3D& scene_3d) { scene_3d.movement.y += 0.12f; if (IsKeyDown(KEY_LEFT_CONTROL)) scene_3d.movement.y -= 0.12f; + if (IsKeyPressed(KEY_ESCAPE)) + return (0); // apply movement scene_3d.camera.position.x += @@ -89,6 +88,63 @@ int tick(Scene3D& scene_3d) { 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; + return (1); +} + +void init_game() +{ + // create image + Image checked = GenImageChecked(2, 2, 1, 1, BLACK, GRAY); + Texture2D texture = LoadTextureFromImage(checked); + UnloadImage(checked); + + // create model with image as texture + Model model = {}; + model = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f)); + model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; + + // setup camera + SetTargetFPS(60); + SetCameraMode(sc3d.camera, CAMERA_FIRST_PERSON); + 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; + + sc3d.rotation = (Vector3){0.0f, 0.0f, 0.0f}; + sc3d.lastMousePos = GetMousePosition(); + bool alive = true; + + while (alive) + { + BeginDrawing(); + ClearBackground(GRAY); + BeginMode3D(sc3d.camera); + + alive = tick(sc3d); + draw(model); + + EndMode3D(); + DrawFPS(0, 0); + DrawText("Controls: Mouse / WASD / SPACE/CTRL.", YABS_SCREENWIDTH - 400, + 0, 20, DARKGRAY); + EndDrawing(); + } + UnloadTexture(texture); + UnloadModel(model); +} + +int reset_camera(Scene3D& scene_3d) { + SetCameraMode(scene_3d.camera, CAMERA_FIRST_PERSON); + scene_3d.camera.position = (Vector3){50.0f, 1.0f, 50.0f}; + scene_3d.camera.target = (Vector3){50.0f, 1.0f, 50.0f}; + scene_3d.camera.up = (Vector3){0.0f, 1.0f, 0.0f}; + scene_3d.camera.fovy = 90.0f; + scene_3d.camera.projection = CAMERA_PERSPECTIVE; + + scene_3d.rotation = (Vector3){0.0f, 0.0f, 0.0f}; + scene_3d.lastMousePos = GetMousePosition(); return (0); } diff --git a/src/yabs_core.h b/src/yabs_core.h index 9120d4c..69d44d0 100644 --- a/src/yabs_core.h +++ b/src/yabs_core.h @@ -42,13 +42,10 @@ typedef enum 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& scene_3d); - int draw(Model& model); - int tick(Scene3D& scene_3d); +void init_game(); } // namespace core |