1
+ /*******************************************************************************************
2
+ *
3
+ * raylib game - Dr. Turtle & Mr. Gamera
4
+ *
5
+ * Welcome to raylib!
6
+ *
7
+ * To test examples, just press F6 and execute raylib_compile_execute script
8
+ * Note that compiled executable is placed in the same folder as .c file
9
+ *
10
+ * You can find all basic examples on C:\raylib\raylib\examples folder or
11
+ * raylib official webpage: www.raylib.com
12
+ *
13
+ * Enjoy using raylib. :)
14
+ *
15
+ * This game has been created using raylib 1.1 (www.raylib.com)
16
+ * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
17
+ *
18
+ * Copyright (c) 2014 Ramon Santamaria (Ray San - [email protected] )
19
+ *
20
+ ********************************************************************************************/
21
+
22
+ #include "raylib.h"
23
+
24
+ #define MAX_ENEMIES 10
25
+
26
+ typedef enum { TITLE , GAMEPLAY , ENDING } GameScreen ;
27
+
28
+ int main ()
29
+ {
30
+ // Initialization
31
+ //--------------------------------------------------------------------------------------
32
+ const int screenWidth = 1280 ;
33
+ const int screenHeight = 720 ;
34
+
35
+ // Init window
36
+ InitWindow (screenWidth , screenHeight , "Dr. Turtle & Mr. GAMERA" );
37
+
38
+ // Load game resources: textures
39
+ Texture2D sky = LoadTexture ("resources/sky.png" );
40
+ Texture2D mountains = LoadTexture ("resources/mountains.png" );
41
+ Texture2D sea = LoadTexture ("resources/sea.png" );
42
+
43
+ // Define scrolling variables
44
+ int backScrolling = 0 ;
45
+ int seaScrolling = 0 ;
46
+
47
+ // Define current screen
48
+ GameScreen currentScreen = TITLE ;
49
+
50
+ SetTargetFPS (60 ); // Setup game frames per second
51
+ //--------------------------------------------------------------------------------------
52
+
53
+ // Main game loop
54
+ while (!WindowShouldClose ()) // Detect window close button or ESC key
55
+ {
56
+ // Update
57
+ //----------------------------------------------------------------------------------
58
+
59
+ // Game screens management
60
+ switch (currentScreen )
61
+ {
62
+ case TITLE :
63
+ {
64
+ // Sea scrolling
65
+ seaScrolling -= 2 ;
66
+ if (seaScrolling <= - screenWidth ) seaScrolling = 0 ;
67
+
68
+ // Press enter to change to gameplay screen
69
+ if (IsKeyPressed (KEY_ENTER ))
70
+ {
71
+ currentScreen = GAMEPLAY ;
72
+ }
73
+
74
+ } break ;
75
+ case GAMEPLAY :
76
+ {
77
+ // Background scrolling logic
78
+ backScrolling -- ;
79
+ if (backScrolling <= - screenWidth ) backScrolling = 0 ;
80
+
81
+ // Sea scrolling logic
82
+ seaScrolling -= 8 ;
83
+ if (seaScrolling <= - screenWidth ) seaScrolling = 0 ;
84
+
85
+ // Press enter to change to ending screen
86
+ if (IsKeyPressed (KEY_ENTER ))
87
+ {
88
+ currentScreen = ENDING ;
89
+ }
90
+
91
+ } break ;
92
+ case ENDING :
93
+ {
94
+ // Press enter to change to title screen
95
+ if (IsKeyPressed (KEY_ENTER ))
96
+ {
97
+ currentScreen = TITLE ;
98
+ }
99
+
100
+ } break ;
101
+ default : break ;
102
+ }
103
+ //----------------------------------------------------------------------------------
104
+
105
+ // Draw
106
+ //----------------------------------------------------------------------------------
107
+ BeginDrawing ();
108
+
109
+ ClearBackground (RAYWHITE );
110
+
111
+ // Draw background (common to all screens)
112
+ DrawTexture (sky , 0 , 0 , WHITE );
113
+
114
+ DrawTexture (mountains , backScrolling , 0 , WHITE );
115
+ DrawTexture (mountains , screenWidth + backScrolling , 0 , WHITE );
116
+
117
+ DrawTexture (sea , seaScrolling , 0 , BLUE );
118
+ DrawTexture (sea , screenWidth + seaScrolling , 0 , BLUE );
119
+
120
+ switch (currentScreen )
121
+ {
122
+ case TITLE :
123
+ {
124
+ // Draw title screen
125
+ DrawText ("PRESS ENTER" , 450 , 420 , 40 , BLACK );
126
+
127
+ } break ;
128
+ case GAMEPLAY :
129
+ {
130
+ // Draw gameplay screen
131
+ DrawText ("GAMEPLAY SCREEN" , 20 , 20 , 40 , MAROON );
132
+
133
+ } break ;
134
+ case ENDING :
135
+ {
136
+ // Draw ending screen
137
+
138
+ // Draw a transparent black rectangle that covers all screen
139
+ DrawRectangle (0 , 0 , screenWidth , screenHeight , Fade (BLACK , 0.4f ));
140
+
141
+ DrawText ("ENDING SCREEN" , 20 , 20 , 40 , DARKBLUE );
142
+
143
+ } break ;
144
+ default : break ;
145
+ }
146
+
147
+ EndDrawing ();
148
+ //----------------------------------------------------------------------------------
149
+ }
150
+
151
+ // De-Initialization
152
+ //--------------------------------------------------------------------------------------
153
+
154
+ // Unload textures
155
+ UnloadTexture (sky );
156
+ UnloadTexture (mountains );
157
+ UnloadTexture (sea );
158
+
159
+ CloseWindow (); // Close window and OpenGL context
160
+ //--------------------------------------------------------------------------------------
161
+
162
+ return 0 ;
163
+ }
0 commit comments