-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
345 lines (289 loc) · 19.9 KB
/
main.c
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include "registers.h"
#include "types.h"
#include "Data.h"
extern void DelayMs(unsigned int);
extern void DisableInterrupts(void);
extern void EnableInterrupts(void);
extern void LCD_PutPixel(unsigned int, unsigned int, unsigned int);
extern void LCD_Contrast(int, int);
extern void LCD_Refresh(void);
extern void LCD_Blank(void);
extern void LCD_Init(void);
extern void LCD_CLEAR_MAT(void);
extern void GPIO_Setup_LCD(void);
extern void GPIO_Setup_Button(void);
extern void SetupRGB_PWM(void);
extern void SetLCDColour(int r, int g, int b);
extern void ADC_Setup_Joystick(void);
extern long int GetJoystickValue(void);
extern bool ButtonPushed(void);
extern int interpolate(int, int, int, int, int);
unsigned char LCDmat[1056];
unsigned int ABits[6] = {
0x01, 0x02, 0x04,
0x08, 0x10, 0x20}; // [CSbit, RSTbit, A0bit, CLKbit, DATbit,B-]
unsigned char APorts[6] = {
'B', 'B', 'B',
'B', 'B', 'B'}; // [CSport, RSTport, A0port, CLKport, DATport,B-]
unsigned int APBases[6] = {
0x40005000, 0x40005000, 0x40005000,
0x40005000, 0x40005000, 0x40005000
};
char tiles[16][256] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,0,0,0,1,0,0 },
{ 1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,1,1,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0 },
{ 1,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,0,0,1 },
{ 1,0,0,0,1,1,0,0,0,1,0,1,0,1,0,0,1,1,1,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0 },
};
bool DEATH = false;
const int DEATH_TILE = 99;
const int SKULL_TILE = 16;
char currentCollisionTile = 0;
/*
* ─── FORWARD DECLARATIONS
* ───────────────────────────────────────────────────────
*/
extern void DrawMap(Position *viewPort, struct Map *map, const int MAP_TILES);
extern void DrawTile(int tileNumber, int x, int y);
extern void DrawPlayer(Position *playerPosition, Position *viewPort, Orientation);
extern void DrawText(int, int, char*, int);
extern void CalculateViewPortCoordinates(Position *viewPort, Position *playerPosition);
void CalculateCollisionDirection(Position *, Map *, CollisionInfo *);
void EndGame(void);
// Test Functions
extern void Test_PWM_LCD_LEDCOLOUR(void);
extern void Test_GPIO_Setup_Button(void);
extern void Test_ADC_Joystick(void);
int main(void) {
Map map = {
32,
4,
{1, 9, 8, 9, 9, 8, 8, 3, 9, 3, 9, 9, 8, 8, 8, 9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 11, 2, 1, 3, 3, 3, 3, 3, 11, 9, 9, 9, 3, 3, 9, 9, 8, 3, 3, 3, 3, 12, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 10, 2, 11, 3, 3, 3, 1, 10, 11, 1, 1, 1, 3, 3, 3, 3, 12, 3, 3, 13, 11, 6, 5, 7, 9, 5, 3, 3, 3, 3, 3, 3, 10, 2, 14, 7, 5, 7, 13, 2, 2, 15, 2, 2, 14, 7, 7, 13, 11, 3, 10, 2, 11, 6, 8, 9, 8, 8, 7, 8, 5, 13, 2, 2, 2 }
};
Map collisionMap = {
32,
4,
{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 2, 2, 0, 2, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 2, 0, 2, 2, 2, 2, 2 }
};
const int MAP_TILES = map.height * map.width;
// --- Setup and testing --------------------------------------------------
SetupRGB_PWM();
Test_PWM_LCD_LEDCOLOUR();
GPIO_Setup_Button();
Test_GPIO_Setup_Button();
ADC_Setup_Joystick();
Test_ADC_Joystick();
SetLCDColour(10, 10, 10);
GPIO_Setup_LCD();
LCD_Init();
LCD_Blank();
/*
* ─── GAME LOOP ──────────────────────────────────────────────────────────────────
*/
Position playerPosition = { 80, 15 };
Position viewPort = { 0, 0 };
Orientation orientation = idle;
CollisionInfo collisionInformation = { false, 0, false, 0, false, 0 };
int playerSpeed = 2;
int jumpSpeed = 6;
int gravity = 6;
int xVelocity = 0;
int yVelocity = 0;
bool inAir = true;
// Colour Values
int rLeft = 30;
int gLeft = 100;
int bLeft = 50;
int rRight = 30;
int gRight = 30;
int bRight = 100;
while (1) {
// Pre-Update
yVelocity += 1;
if (yVelocity >= gravity) yVelocity = gravity;
// Handle Inputs
if (GetJoystickValue() < 40) {
xVelocity = -playerSpeed;
orientation = r;
} else if (GetJoystickValue() > 60) {
xVelocity = playerSpeed;
orientation = l;
} else {
xVelocity = 0;
orientation = idle;
}
if (ButtonPushed() && !inAir) {
yVelocity = -jumpSpeed;
inAir = true;
}
playerPosition.y += yVelocity;
// Collisions
CalculateCollisionDirection(&playerPosition, &collisionMap, &collisionInformation);
if(collisionInformation.bottom && collisionInformation.bottomTile == DEATH_TILE) {
EndGame();
playerPosition.x = 50;
playerPosition.y = 15;
xVelocity = 0;
yVelocity = 0;
inAir = false;
continue;
}
if (collisionInformation.right) {
xVelocity = 0;
orientation = idle;
playerPosition.x -= playerSpeed;
}
if (collisionInformation.left) {
xVelocity = 0;
orientation = idle;
playerPosition.x += playerSpeed;
}
if (collisionInformation.bottom) {
yVelocity = 0;
// Place the player on the ground
playerPosition.y -= playerPosition.y % 16 - 5;
inAir = false;
}
// Update Coords
playerPosition.x += xVelocity;
// --- Render -------------------------------------------------------------
LCD_CLEAR_MAT();
// Elements
CalculateViewPortCoordinates(&viewPort, &playerPosition);
DrawMap(&viewPort, &map, MAP_TILES);
DrawPlayer(&playerPosition, &viewPort, orientation);
DrawText(2, 2, "bitcowboy", 9);
// Refresh
LCD_Refresh();
// --- Colour Management --------------------------------------------------
int mapWidth = map.width * 16;
int r = rLeft + (int)(((float)((float)rRight - (float)rLeft) / (float)mapWidth) * (float)playerPosition.x);
int g = gLeft + (int)(((float)((float)gRight - (float)gLeft) / (float)mapWidth) * (float)playerPosition.x);
int b = bLeft + (int)(((float)((float)bRight - (float)bLeft) / (float)mapWidth) * (float)playerPosition.x);
SetLCDColour(r, g, b);
}
}
bool CollisionTile(int x, int y, Map * collisionMap) {
int tile = x + (y * collisionMap->width);
if (tile < 0 || tile >= (collisionMap->width * collisionMap->height)) {
currentCollisionTile = 99;
return true;
}
int collisionTile = collisionMap->tiles[tile];
currentCollisionTile = collisionTile;
if (collisionTile == 2) return true;
return false;
}
void CalculateCollisionDirection(Position* playerPosition, Map* collisionMap, CollisionInfo * CI) {
// Clear Collision Information
CI->right = false; CI->left = false; CI->bottom = false;
int tileX = playerPosition->x / 16;
int tileY = playerPosition->y / 16;
int playerLeft = playerPosition->x;
int playerRight = playerPosition->x + SPRITE_WIDTH;
int playerBottom = playerPosition->y + SPRITE_HEIGHT;
int tileLeftX = tileX * 16 + 16;
int tileRightX = tileX * 16 + 16;
int tileBottomY = tileY * 16 + 16;
// Check bottom tile
if (playerBottom > tileBottomY && CollisionTile(tileX, tileY + 1, collisionMap)) {
CI->bottom = true;
CI->bottomTile = currentCollisionTile;
}
// Sometimes the player will be overlapping two tiles below (Fixed tiles going through bottom right of player)
if (playerPosition->x % 16 > 7 && playerBottom > tileBottomY && CollisionTile(tileX + 1, tileY + 1, collisionMap)) {
CI->bottom = true;
CI->bottomTile = currentCollisionTile;
}
// Might need to check tile to the side and bottom diagonal if player is over
// the lower tile boundary
if (playerBottom > tileBottomY + 2) {
// Bottom Left Diagonal
if (playerLeft < tileLeftX && CollisionTile(tileX, tileY + 1, collisionMap))
CI->left = true;
// Bottom Right Diagonal
if (playerRight > tileRightX + 1 && CollisionTile(tileX + 1, tileY + 1, collisionMap))
CI->right = true;
}
// Tile to the left
if (playerLeft < tileLeftX && CollisionTile(tileX , tileY, collisionMap))
CI->left = true;
// Tile to the right
if (playerRight > tileRightX && CollisionTile(tileX + 1, tileY, collisionMap))
CI->right = true;
}
void EndGame() {
LCD_CLEAR_MAT();
DelayMs(5);
SetLCDColour(100, 100, 100);
DelayMs(1);
SetLCDColour(0, 0, 0);
DelayMs(1);
SetLCDColour(100, 100, 100);
DelayMs(1);
SetLCDColour(0, 0, 0);
DelayMs(1);
SetLCDColour(100, 100, 100);
for (int i = 0; i < SCREEN_TILES_HEIGHT; i++) {
for (int j = 0; j < SCREEN_TILES_WIDTH; j++) {
int x = j * 16;
int y = i * 16;
if (i > 0 && i < 3) {
if (j > 1 && j < 6) {
continue;
}
}
DrawTile(SKULL_TILE, x, y);
LCD_Refresh();
DelayMs(2);
}
}
DrawText(41, 29, "gameover", 8);
LCD_Refresh();
DelayMs(100);
}