11/*******************************************************************************************
2- *
3- * raylib gamejam template
4- *
5- * Template originally created with raylib 4.5-dev, last time updated with raylib 5.0
6- *
7- * Template licensed under an unmodified zlib/libpng license, which is an OSI-certified,
8- * BSD-like license that allows static linking with closed source software
9- *
10- * Copyright (c) 2022-2025 Ramon Santamaria (@raysan5)
11- *
12- ********************************************************************************************/
2+ *
3+ * raylib gamejam template
4+ *
5+ * Template originally created with raylib 4.5-dev, last time updated with raylib 5.0
6+ *
7+ * Template licensed under an unmodified zlib/libpng license, which is an OSI-certified,
8+ * BSD-like license that allows static linking with closed source software
9+ *
10+ * Copyright (c) 2022-2025 Ramon Santamaria (@raysan5)
11+ *
12+ ********************************************************************************************/
1313
1414#include "raylib.h"
15+ #include "raymath.h"
1516
1617#if defined(PLATFORM_WEB )
17- #define CUSTOM_MODAL_DIALOGS // Force custom modal dialogs usage
18- #include <emscripten/emscripten.h> // Emscripten library - LLVM to JavaScript compiler
18+ #define CUSTOM_MODAL_DIALOGS // Force custom modal dialogs usage
19+ #include <emscripten/emscripten.h> // Emscripten library - LLVM to JavaScript compiler
1920#endif
2021
21- #include <stdio.h> // Required for: printf()
22- #include <stdlib.h> // Required for:
23- #include <string.h> // Required for:
22+ #include <stdio.h> // Required for: printf()
23+ #include <stdlib.h> // Required for:
24+ #include <string.h> // Required for:
2425
2526//----------------------------------------------------------------------------------
2627// Defines and Macros
2930// NOTE: Avoiding those calls, also avoids const strings memory usage
3031#define SUPPORT_LOG_INFO
3132#if defined(SUPPORT_LOG_INFO )
32- #define LOG (...) printf(__VA_ARGS__)
33+ #define LOG (...) printf(__VA_ARGS__)
3334#else
34- #define LOG (...)
35+ #define LOG (...)
3536#endif
3637
38+ #include "globals.h"
39+ #include "clock.h"
40+ #include "snake.h"
41+
3742//----------------------------------------------------------------------------------
3843// Types and Structures Definition
3944//----------------------------------------------------------------------------------
40- typedef enum {
41- SCREEN_LOGO = 0 ,
42- SCREEN_TITLE ,
43- SCREEN_GAMEPLAY ,
45+ typedef enum
46+ {
47+ SCREEN_LOGO = 0 ,
48+ SCREEN_TITLE ,
49+ SCREEN_GAMEPLAY ,
4450 SCREEN_ENDING
4551} GameScreen ;
4652
@@ -49,33 +55,52 @@ typedef enum {
4955//----------------------------------------------------------------------------------
5056// Global Variables Definition
5157//----------------------------------------------------------------------------------
52- static const int screenWidth = 800 ;
53- static const int screenHeight = 450 ;
58+ static const int screenWidth = 1200 ;
59+ static const int screenHeight = 900 ;
60+
61+ static RenderTexture2D target = {0 }; // Render texture to render our game
5462
55- static RenderTexture2D target = { 0 }; // Render texture to render our game
63+ static const Vector3 cameraNeck = ( Vector3 ){ 0.f , 4.f , 6.f };
5664
5765// TODO: Define global variables here, recommended to make them static
5866
5967//----------------------------------------------------------------------------------
6068// Module Functions Declaration
6169//----------------------------------------------------------------------------------
62- static void UpdateDrawFrame (void ); // Update and Draw one frame
70+ static void UpdateDrawFrame (Camera3D camera , Clock * clock , Snake * snake ); // Update and Draw one frame
6371
6472//------------------------------------------------------------------------------------
6573// Program main entry point
6674//------------------------------------------------------------------------------------
6775int main (void )
6876{
6977#if !defined(_DEBUG )
70- SetTraceLogLevel (LOG_NONE ); // Disable raylib trace log messages
78+ SetTraceLogLevel (LOG_NONE ); // Disable raylib trace log messages
7179#endif
7280
7381 // Initialization
7482 //--------------------------------------------------------------------------------------
7583 InitWindow (screenWidth , screenHeight , "raylib gamejam template" );
76-
84+ SetWindowMonitor (0 );
85+
7786 // TODO: Load resources / Initialize variables at this point
78-
87+
88+ // Define the camera to look into our 3d world
89+ Vector3 start = (Vector3 ){0.f , 0.f , 0.f };
90+ Vector3 forward = (Vector3 ){0.f , 0.f , -1.f };
91+
92+ Camera3D camera = {0 };
93+ camera .position = cameraNeck ; // Camera position
94+ camera .target = start ; // Camera looking at point
95+ camera .up = (Vector3 ){0.0f , 1.0f , 0.0f }; // Camera up vector (rotation towards target)
96+ camera .fovy = 85.0f ; // Camera field-of-view Y
97+ camera .projection = CAMERA_PERSPECTIVE ; // Camera mode type
98+
99+ Snake snake = InitSnake (& start , forward );
100+
101+ // movement clock
102+ Clock clock = InitClock (1.f );
103+
79104 // Render texture to draw full screen, enables screen scaling
80105 // NOTE: If screen is scaled, mouse input should be scaled proportionally
81106 target = LoadRenderTexture (screenWidth , screenHeight );
@@ -84,23 +109,23 @@ int main(void)
84109#if defined(PLATFORM_WEB )
85110 emscripten_set_main_loop (UpdateDrawFrame , 60 , 1 );
86111#else
87- SetTargetFPS (60 ); // Set our game frames-per-second
112+ SetTargetFPS (60 ); // Set our game frames-per-second
88113 //--------------------------------------------------------------------------------------
89114
90115 // Main game loop
91- while (!WindowShouldClose ()) // Detect window close button
116+ while (!WindowShouldClose ()) // Detect window close button
92117 {
93- UpdateDrawFrame ();
118+ UpdateDrawFrame (camera , & clock , & snake );
94119 }
95120#endif
96121
97122 // De-Initialization
98123 //--------------------------------------------------------------------------------------
99124 UnloadRenderTexture (target );
100-
125+
101126 // TODO: Unload all loaded resources at this point
102127
103- CloseWindow (); // Close window and OpenGL context
128+ CloseWindow (); // Close window and OpenGL context
104129 //--------------------------------------------------------------------------------------
105130
106131 return 0 ;
@@ -110,35 +135,47 @@ int main(void)
110135// Module functions definition
111136//--------------------------------------------------------------------------------------------
112137// Update and draw frame
113- void UpdateDrawFrame (void )
138+ void UpdateDrawFrame (Camera3D camera , Clock * clock , Snake * snake )
114139{
115140 // Update
116141 //----------------------------------------------------------------------------------
117- // TODO: Update variables / Implement example logic at this point
118- //----------------------------------------------------------------------------------
142+ if (TickClock (clock ))
143+ {
144+ printf ("\ntick - " );
145+ MoveSnake (snake );
146+
147+ // printf("\tupdate camera - ");
148+ camera .position = Vector3Add (* snake -> body [0 ], cameraNeck );
149+ camera .target = Vector3Add (camera .position , snake -> forward );
150+ camera .up = snake -> up ;
151+ UpdateCamera (& camera , CAMERA_THIRD_PERSON );
152+ }
119153
120154 // Draw
121155 //----------------------------------------------------------------------------------
122- // Render game screen to a texture,
156+ // Render game screen to a texture,
123157 // it could be useful for scaling or further shader postprocessing
124- BeginTextureMode (target );
125- ClearBackground (RAYWHITE );
126-
127- // TODO: Draw your game screen here
128- DrawText ("Welcome to raylib NEXT gamejam!" , 150 , 140 , 30 , BLACK );
129- DrawRectangleLinesEx ((Rectangle ){ 0 , 0 , screenWidth , screenHeight }, 16 , BLACK );
130-
131- EndTextureMode ();
132-
158+ // BeginTextureMode(target);
159+ // ClearBackground(RAYWHITE);
160+
161+ // // TODO: Draw your game screen here
162+ // DrawText("Welcome to raylib NEXT gamejam!", 150, 140, 30, BLACK);
163+ // DrawRectangleLinesEx((Rectangle){0, 0, screenWidth, screenHeight}, 16, BLACK);
164+
165+ // EndTextureMode();
166+
133167 // Render to screen (main framebuffer)
134168 BeginDrawing ();
135- ClearBackground (RAYWHITE );
136-
137- // Draw render texture to screen, scaled if required
138- DrawTexturePro (target .texture , (Rectangle ){ 0 , 0 , (float )target .texture .width , - (float )target .texture .height }, (Rectangle ){ 0 , 0 , (float )target .texture .width , (float )target .texture .height }, (Vector2 ){ 0 , 0 }, 0.0f , WHITE );
169+ ClearBackground (RAYWHITE );
170+ BeginMode3D (camera );
171+
172+ // Draw render texture to screen, scaled if required
173+ DrawSnake (snake );
174+ DrawGrid (16 , 1.0f );
139175
140- // TODO: Draw everything that requires to be drawn at this point, maybe UI?
176+ EndMode3D ();
177+ // TODO: Draw everything that requires to be drawn at this point, maybe UI?
141178
142179 EndDrawing ();
143- //----------------------------------------------------------------------------------
144- }
180+ //----------------------------------------------------------------------------------
181+ }
0 commit comments