-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_map_boundaries.c
138 lines (115 loc) · 5.13 KB
/
main_map_boundaries.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
/*
* StickGBC by Matt Comben is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit
* http://creativecommons.org/licenses/by-nc-nd/4.0/.
*/
#pragma bank=7
#include <gb/gb.h>
#include "main.h"
#include "game_constants.h"
#include "main_map.h"
const UBYTE MAIN_MAP_BOUNDARIES[] = {
// Each row of map is 8.75 bytes. Each row in this array ends with any leading tiles form next map row.
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
// ^ end of 4th row (0-3)
// Rows 4-7
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 8-11
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0xFC, 0xFD, 0xFF, 0x3F, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 12-15
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 16-19
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 20-23
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0F, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xF9, 0x3F,
// Rows 24-27
0xFC, 0x9F, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0xF0, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x20,
// Rows 28-31
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x20,
// Rows 32-35
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x20,
// Rows 36-39
0x00, 0x00, 0x00, 0x20, 0x00, 0xFC, 0xFF, 0x9F, 0xFF,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 40-43
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 44-47
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 48-51
0x00, 0x00, 0x00, 0x30, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
// Rows 52-55
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0xFF, 0x04, 0x00, 0x00, 0x00,
// Row 56
0x00, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0x00,
};
// Check if next position will hit a boundary
void check_boundary_hit()
{
unsigned int new_x;
unsigned int new_y;
unsigned int new_tile_itx;
#if IN_TESTING && DEBUG_IGNORE_BOUNDARIES
return;
#endif
new_x = game_state.user_pos_x + (signed int)joypad_state.travel_x;
new_y = game_state.user_pos_y + (signed int)joypad_state.travel_y;
// Check if traveling to new tile
if ((joypad_state.travel_x == 1 && (new_x & 0x07U) == 0x00U) ||
(joypad_state.travel_x == -1 && (new_x & 0x07U) == 0x07U) ||
(joypad_state.travel_y == 1 && (new_y & 0x07U) == 0x00U) ||
(joypad_state.travel_y == -1 && (new_y & 0x07U) == 0x07U))
{
new_tile_itx = X_Y_TO_TILE_INDEX(
PIXEL_LOCATION_TO_TILE_COUNT(new_x),
PIXEL_LOCATION_TO_TILE_COUNT(new_y)
);
// Check if new tile is a boundary
if (TILE_INDEX_BIT_MAP_VALUE(MAIN_MAP_BOUNDARIES, new_tile_itx))
{
// Reset travel directions, acting as if user is not moving.
joypad_state.travel_x = 0;
joypad_state.travel_y = 0;
}
}
}