Skip to content

Commit f2b35a3

Browse files
Merge pull request #27 from OnlyUsePascal/transition-text
transition-text
2 parents 4f38149 + b2e7c19 commit f2b35a3

File tree

4 files changed

+114
-27
lines changed

4 files changed

+114
-27
lines changed

kernel/game_be.c

+39-22
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ uint16_t currentRadius = LIGHT_RADIUS;
2222

2323

2424
void render_scene(const Maze *maze, const Asset *asset, const bool isFOVShown);
25+
void game_start(Maze *mz, int *_optIdx, int *_mazeIdx);
2526
void debug_pos(Position pos);
2627
void update_pos(Position *des, Direction dir);
2728
void handle_collision(ItemMeta *item, Maze *maze, Player *player);
@@ -97,8 +98,9 @@ void game_enter() {
9798
char *opts[] = {"Start", "Choose Level", "How To Play?", "Exit"};
9899
int optSz = sizeof(opts) / sizeof(opts[0]);
99100

100-
int optIdx = -1;
101+
int optIdx = -1, mazeIdx = 1;
101102
while (1) {
103+
str_debug_num(optIdx);
102104
if (optIdx == -1) {
103105
drawMenu(menuPosX, menuPosY, yOffset, opts,
104106
optSz, MENU_FOREGND, MENU_BACKGND, true);
@@ -109,11 +111,11 @@ void game_enter() {
109111
}
110112

111113
switch (optIdx) {
112-
case 0: //start
113-
game_start(mazes[3-1], &optIdx);
114-
uart_puts("> optIdx:"); uart_dec(optIdx); uart_puts("\n");
114+
case 0: {
115+
game_start(mazes[mazeIdx], &optIdx, &mazeIdx);
116+
uart_puts("> optIdx:"); uart_dec(optIdx); uart_puts(", maze level: "); uart_dec(mazeIdx); uart_puts("\n");
115117
break;
116-
118+
}
117119
case 1: //continue
118120
optIdx = -1;
119121
game_continue();
@@ -150,7 +152,7 @@ int game_menu_enter() {
150152
}
151153

152154

153-
void game_start(Maze *mz, int *_optIdx){
155+
void game_start(Maze *mz, int *_optIdx, int *_mazeIdx){
154156
uart_puts("Starting Game...\n");
155157
bool isFOVShown = true;
156158
Player *pl = mz->player;
@@ -164,7 +166,6 @@ void game_start(Maze *mz, int *_optIdx){
164166
curDarken = 1;
165167
currentRadius = LIGHT_RADIUS;
166168
getMazePathColor(mz);
167-
// TODO: reset item status
168169
for (int i = 0 ; i < mz->itemMetasSz; i++){
169170
ItemMeta *meta = mz->itemMetas[i];
170171
meta->collided = false;
@@ -197,17 +198,18 @@ void game_start(Maze *mz, int *_optIdx){
197198
debug_pos(*(pl->pos));
198199

199200
// DEBUG / screen shading
200-
if(c == 'o'){
201-
adjustBrightness(mz, pl->asset, true);
202-
}
203-
else if(c == 'p'){
204-
adjustBrightness(mz, pl->asset, false);
205-
}
206-
else if (c == 'k') {
207-
isFOVShown = !isFOVShown;
208-
render_scene(mz, pl->asset, isFOVShown);
209-
}
210-
else if (c == 27) { // game menu
201+
// if(c == 'o'){
202+
// adjustBrightness(mz, pl->asset, true);
203+
// }
204+
// else if(c == 'p'){
205+
// adjustBrightness(mz, pl->asset, false);
206+
// }
207+
// else if (c == 'k') {
208+
// isFOVShown = !isFOVShown;
209+
// render_scene(mz, pl->asset, isFOVShown);
210+
// }
211+
if (c == 27) {
212+
// pause menu
211213
int game_stage = game_menu_enter();
212214
switch (game_stage) {
213215
case 0:
@@ -219,9 +221,9 @@ void game_start(Maze *mz, int *_optIdx){
219221
MENU_BACKGROUND_SIZE, bitmap_menu_background);
220222
return;
221223
}
222-
// str_debug_num(game_stage);
223224
}
224225
else if (c == 'q'){
226+
// explode wall with bomb
225227
effect_bomb(mz, pl);
226228
}
227229
else {
@@ -250,7 +252,22 @@ void game_start(Maze *mz, int *_optIdx){
250252
update_pos(pl->pos, dir);
251253
ItemMeta *collidedItem = detect_collision(*(pl->pos), mz->itemMetas, mz->itemMetasSz);
252254
drawMovement(mz, pl->asset, dir, collidedItem);
253-
255+
256+
// detect end of maze
257+
if (pl->pos->posX % MAZE_SZ_CELL == MAZE_SZ_CELL - 1) {
258+
str_debug("end of maze reached!");
259+
drawLevelTransitionText(*(_mazeIdx) + 1);
260+
*_optIdx = (*(_mazeIdx) == 2) ? -1 : 0;
261+
*_mazeIdx = (*(_mazeIdx) + 1) % 3;
262+
263+
while (uart_getc() != '\n');
264+
if (*(_mazeIdx) == 0) {
265+
clearScreen();
266+
framebf_drawImg(0, 0, MENU_BACKGROUND_SIZE, MENU_BACKGROUND_SIZE, bitmap_menu_background);
267+
}
268+
return;
269+
}
270+
254271
// darken screen interval + game over
255272
pl->step += 1;
256273
if (pl->step % 7 == 0) {
@@ -328,12 +345,12 @@ void game_help() {
328345
void game_exit() {
329346
clearScreen();
330347
uart_puts("Exiting game...\n");
331-
font_drawString(150, 150, "Ta reng Ta reng Ta reng", MENU_FOREGND, 2, 1);
348+
font_drawString(150, 150, "Thank you for playing <3", MENU_FOREGND, 2, 1);
332349
}
333350

334351

335352
void game_over(int *_optIdx) {
336-
str_debug("game over :(");
353+
str_debug("Game Over :(");
337354
wait_msec(1000000);
338355
clearScreen();
339356

kernel/game_fe.c

+72-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#define STEP_AMOUNT 3
1212
#define RECT_BORDER 10
1313
#define DIALOG_HEIGHT 90
14-
#define DIALOG_EXIT_MSG "Press Enter to continue"
15-
#define DIALOG_EXIT_MSG_SIZE 23
14+
#define DIALOG_EXIT_MSG "Press Enter to continue..."
15+
#define DIALOG_EXIT_MSG_SIZE 26
1616

1717
float curDarken = 1.0f;
1818
const float darkenFactor = 0.8f;
@@ -316,6 +316,76 @@ void drawDialog(const char *title, const char *text) {
316316
);
317317
}
318318

319+
void drawLevelTransitionText(const uint8_t levelNum) {
320+
uint64_t color = 0xE7E1DA;
321+
if (levelNum != 3) {
322+
uint16_t msg_level_width = font_string_width(6, FONT_WIDTH);
323+
uint16_t msg_number_width = font_string_width(1, FONT_WIDTH);
324+
uint16_t full_msg_width = font_string_width(16, FONT_WIDTH);
325+
uint16_t esc_msg_width = font_string_width(str_len(DIALOG_EXIT_MSG), FONT_WIDTH);
326+
327+
char levelLabel[2];
328+
levelLabel[0] = levelNum + '0';
329+
levelLabel[1] = '\0';
330+
331+
font_drawString(
332+
GAME_W / 2 - full_msg_width / 2,
333+
GAME_H / 2 - DIALOG_HEIGHT / 2,
334+
"Level ",
335+
color,
336+
2,
337+
1
338+
);
339+
340+
font_drawString(
341+
GAME_W / 2 - full_msg_width / 2 + msg_level_width,
342+
GAME_H / 2 - DIALOG_HEIGHT / 2,
343+
levelLabel,
344+
color,
345+
2,
346+
1
347+
);
348+
349+
font_drawString(
350+
GAME_W / 2 - full_msg_width / 2 + msg_level_width + msg_number_width,
351+
GAME_H / 2 - DIALOG_HEIGHT / 2,
352+
" cleared!",
353+
color,
354+
2,
355+
1
356+
);
357+
358+
font_drawString(
359+
GAME_W / 2 - esc_msg_width / 2,
360+
GAME_H / 2 + DIALOG_HEIGHT / 2,
361+
DIALOG_EXIT_MSG,
362+
color,
363+
2,
364+
1
365+
);
366+
} else {
367+
uint16_t msg_level_width = font_string_width(8, FONT_WIDTH);
368+
uint16_t esc_msg_width = font_string_width(32, FONT_WIDTH);
369+
370+
font_drawString(
371+
GAME_W / 2 - msg_level_width / 2,
372+
GAME_H / 2 - DIALOG_HEIGHT / 2,
373+
"You win!",
374+
color,
375+
2,
376+
1
377+
);
378+
379+
font_drawString(
380+
GAME_W / 2 - esc_msg_width / 2,
381+
GAME_H / 2 + DIALOG_HEIGHT / 2,
382+
"Press Enter to return to menu...",
383+
color,
384+
2,
385+
1
386+
);
387+
}
388+
}
319389

320390
void updateAssetPos(Asset *asset, int x, int y) {
321391
asset->posX = x;

lib/game_be.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extern uint16_t currentRadius;
8080

8181
void game_enter();
8282
int game_menu_enter();
83-
void game_start(Maze *mz, int *_optIdx);
83+
// void game_start(Maze *mz, int *_optIdx, const uint8_t mazeIdx);
8484
void game_continue();
8585
void game_help();
8686
void game_exit();

lib/game_fe.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ void removeFOV(const Asset *asset);
3333
void drawFOV(const Maze *maze, const Asset *asset);
3434
void drawFOVWeakWall(const Maze *mz, const Asset *asset, const Asset *weakWall);
3535
void drawDialog(const char *title, const char *text);
36-
// void removeDialog(const Position *pos);
3736

3837
void drawMovement(Maze *maze, Asset *asset, Direction dir, ItemMeta *collidedItem);
39-
// void removeAsset(const Asset *asset);
4038
void drawAsset(const Asset *asset);
4139
void updateAssetPos(Asset *asset, int x, int y);
4240
void drawMovementFrame(Asset *playerAsset, Direction dir, int order);
@@ -47,6 +45,8 @@ void getMazePathColor(Maze *maze);
4745
void adjustBrightness(const Maze *maze, const Asset *asset, bool darken);
4846
uint64_t darkenPixel(uint64_t color, const float factor);
4947

48+
void drawLevelTransitionText(const uint8_t levelNum);
49+
5050
extern float curDarken;
5151
extern const float darkenFactor;
5252

0 commit comments

Comments
 (0)