-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoloLevel1.cpp
185 lines (140 loc) · 5.21 KB
/
SoloLevel1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "SoloLevel1.h"
#include <raylib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int bacteria = 0;
int level[144]; // This is the level grid. 1=block 0=air.
Texture2D grilledcheese;
Texture2D brick;
int origlevel[]= {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 1, 1, 1,
2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
int lx = 16; // Level Width
int ly = 9; // Level Height
float playerx = 600, playery = 0; // Player position
float jetpack = 0; // Jetpack velocity
float jetpackmax = 3;
float playerspeed = 150;
float gravity = 0; // Gravity velocity
int ground = 710;
int ceiling = 0;
int left = 0;
int right = 1280;
bool grounded = false;
bool flying = false; // Checks if player is flying
bool floor_colmatch = false; // used for collision detection with platforms
bool ceiling_colmatch = false;
bool left_colmatch = false;
bool right_colmatch = false;
void SoloLevel1::Init(){
bacteria = 0;
memcpy(level, origlevel, sizeof origlevel);
// This is the level grid. 1=block 0=air.
lx = 16; // Level Width
ly = 9; // Level Height
playerx = 600, playery = 0; // Player position
jetpack = 0; // Jetpack velocity
jetpackmax = 3;
playerspeed = 150;
grilledcheese = LoadTexture("base/gc.png");
brick = LoadTexture("base/brick.png");
gravity = 0; // Gravity velocity
ceiling = 0;
ground = 710; // Ground level
left = 0;
right = 1280;
grounded = false; // Check if player is on the ground
flying = false; // Checks if player is flying
floor_colmatch = false; // used for collision detection with platforms
left_colmatch = false;
right_colmatch = false;
}
void SoloLevel1::Display(){
BeginDrawing();
ClearBackground(BLACK);
DrawText(TextFormat("Bacteria collected: %i", bacteria), 0, 0, 30, YELLOW);
DrawFPS(0,60);
// DrawText("GRILLED CHEESE", 0, 0, 20, WHITE);
/* Render Level */
for(int y = 0; y < ly; y++){
for(int x = 0; x < lx; x++){
if(level[y*lx + x] == 1) DrawTexture(brick, x*80, y*80, WHITE); //DrawRectangle(x*80, y*80, 80, 80, GRAY); // Platforms
if(level[y*lx + x] == 2) DrawRectangle(x*80, y*80, 80, 80, GREEN); // Bacteria
}
}
//DrawCircle(playerx, playery, 32, WHITE);
DrawTexture(grilledcheese, playerx-32, playery-32, WHITE);
EndDrawing();
}
void SoloLevel1::Input(){
if(IsKeyDown(KEY_W) && jetpack < jetpackmax) jetpack += GetFrameTime();
if((!IsKeyDown(KEY_W) || jetpack >= jetpackmax) && jetpack > 0) jetpack -= GetFrameTime();
flying = IsKeyDown(KEY_W);
//if(IsKeyDown(KEY_S)) playery++;
if(IsKeyDown(KEY_A) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_LEFT)) playerx -= playerspeed * GetFrameTime();
if(IsKeyDown(KEY_D) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_RIGHT)) playerx += playerspeed * GetFrameTime();
if(IsKeyPressed(KEY_ESCAPE)) GC_LoadScene(0);
}
void SoloLevel1::Misc(){
/* Player movement physics */
playery-=jetpack;
if(jetpack < 0) jetpack = 0;
// printf("%f\n", jetpack);
if(!flying)gravity+=GetFrameTime();
if(gravity > 0 && flying) gravity -= GetFrameTime();
if(playery >= ground) grounded = true;
else grounded = false;
if(gravity < 0 || grounded) gravity = 0;
playery+=gravity;
if(playery > 720) playery = 720;
if(playery < ceiling) playery = ceiling;
if(playerx < left) playerx = left;
if(playerx > right) playerx = right;
/* level collisions */
for(int y = 0; y < ly; y++){
for(int x = 0; x < lx; x++){
if(level[y*lx + x] == 1 && (int)playerx/80 == x && (int)(playery/80)+1 == y) {
ground = (y*80)-30;
floor_colmatch = true;
}
if(level[y*lx + x] == 1 && (int)playerx/80 == x && (int)(playery/80)-1 == y) {
ceiling = ((y+1)*80+30);
ceiling_colmatch = true;
}
if(level[y*lx + x] == 2 && (int)playerx/80 == x && (int)(playery/80) == y) {
level[y*lx + x] = 0;
bacteria++;
// floor_colmatch = true;
}
if(level[y*lx + x] == 1 && (int)(playerx/80)-1 == x && (int)(playery/80) == y) {
left = ((x+1)*80)+30;
left_colmatch = true;
}
if(level[y*lx + x] == 1 && (int)(playerx/80)+1 == x && (int)(playery/80) == y) {
right = ((x)*80-30);
right_colmatch = true;
}
}
}
if(!floor_colmatch) ground = 690;
if(!ceiling_colmatch) ceiling = 0;
if(!left_colmatch) left = 0;
if(!right_colmatch) right = 1280;
floor_colmatch = false;
ceiling_colmatch = false;
left_colmatch = false;
right_colmatch = false;
}
void SoloLevel1::Deinit(){
UnloadTexture(grilledcheese);
UnloadTexture(brick);
}