This repository has been archived by the owner on Jan 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pause.c
62 lines (49 loc) · 1.8 KB
/
pause.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
#include "main.h"
#include "game_config.h"
#include "variables.h"
#include "constants.h"
#include <gb/gb.h>
void show_pause() {
gameState = GAME_STATE_PAUSED;
// Clear the second row of hud
for (i = 0; i != 20; ++i)
buffer[i] = 0;
set_win_tiles(0U, 1U, 20U, 1U, buffer);
// Wait a frame for that change to apply, as the following functions also use buffer.
wait_vbl_done();
// We know the rest of buffer is still 0, so no need to fill it; we'll get it for free.
// Fill the first row with PAUSE
buffer[6] = '-' + WINDOW_TEXT_OFFSET;
buffer[7] = 0;
buffer[8] = 'P' + WINDOW_TEXT_OFFSET;
buffer[9] = 'a' + WINDOW_TEXT_OFFSET;
buffer[10] = 'u' + WINDOW_TEXT_OFFSET;
buffer[11] = 's' + WINDOW_TEXT_OFFSET;
buffer[12] = 'e' + WINDOW_TEXT_OFFSET;
buffer[13] = 'd' + WINDOW_TEXT_OFFSET;
buffer[14] = 0;
buffer[15] = '-' + WINDOW_TEXT_OFFSET;
set_win_tiles(0U, 0U, 20u, 1U, buffer);
}
void do_pause() {
oldBtns = btns;
btns = joypad();
if (btns & J_START && !(oldBtns & J_START)) {
// Clear eentire hud again - both rows
for (i = 0; i != 20; i++)
buffer[i] = 0;
set_win_tiles(0U, 0U, 20U, 1U, buffer);
// Wait a frame for that change to apply, as the following functions also use buffer.
wait_vbl_done();
// Same story, clear second row, wait another frame
set_win_tiles(0U, 1U, 20U, 1U, buffer);
wait_vbl_done();
// Get the HUD back to normal
update_money();
// After updating money, wait a frame for that change to apply - otherwise we will overwrite buffer and only
// end up updating health; ignoring money altogether.
wait_vbl_done();
update_health();
gameState = GAME_STATE_RUNNING;
}
}