-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.inc
175 lines (148 loc) · 2.86 KB
/
game.inc
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
IF !DEF(GAME_INC)
GAME_INC SET 1
INCLUDE "player.inc"
INCLUDE "obstacles.inc"
SECTION "game routines", ROM0
LoadGame:
call LoadBackground
call LoadObjects
call SetPlayerInactive
call ResetAnimCounter
call ResetPlayerVelocity
ret
LoadBackground:
call LoadBackgroundTiles
call LoadBackgroundMap
call SetBackgroundPalette
call ResetWindowPosition
ret
LoadBackgroundTiles:
ld hl, _VRAM9000
ld de, TileSet
ld bc, TileSetEnd - TileSet
call MemCpy
ret
LoadBackgroundMap:
ld hl, _SCRN0
ld de, TileMap
ld bc, TileMapEnd - TileMap
call MemCpy
ret
SetBackgroundPalette:
ld a, %11100100 ; 3 B, 2 LG, 1 DG, 0 W
ld [rBGP], a
ret
LoadObjects:
call ClearSpriteAttributes
call LoadSpriteTiles
call InitPlayerSprite
call InitPlayerYPos
call SetPlayerSpriteY
call InitObstacleSprites
call SetObjectPalette
call StartDMA
ret
LoadSpriteTiles:
ld hl, _VRAM
ld de, Sprites
ld bc, SpritesEnd - Sprites
call MemCpy
ret
SetObjectPalette:
; Change OBJ 0 palette
ld a, %11010000 ; 3 B, 2 LG, 1 W
ld [rOBP0], a
; Change OBJ 1 palette
ld a, %11100100 ; 3 B, 2 DG, 1 LG
ld [rOBP1], a
ret
ResetAnimCounter:
xor a
ld [_ANIM_COUNTER], a
ret
UpdateGame:
ld a, [_PLAYER_ACTIVE]
cp 1
jp z, .updateGameActive
.updateGameInactive:
call MoveBackground
call AnimatePlayerSprite
call ActivatePlayer
call StartDMA
call UpdatePressingA
ret
.updateGameActive:
call MoveBackground
call AnimatePlayerSprite
call MovePlayer
call MoveObstacles
call StartDMA
call CheckCollisions
call UpdatePressingA
ret
MoveBackground:
ld a, [rSCX]
inc a
ld [rSCX], a
ret
CheckCollisions:
call CheckPipeCollision
call CheckCeilingCollision
call CheckFloorCollision
ret
CheckCeilingCollision:
ld a, [_S_PLAYER_TL_Y]
cp 16
call c, SetGameOver
ret
CheckFloorCollision:
ld a, [_S_PLAYER_BL_Y]
add 8
cp 160
call nc, SetGameOver
ret
CheckPipeCollision:
; Check if player is to the right of the beggining of the obstacle
ld a, [_OBSTACLE_X]
ld b, a
ld a, [_S_PLAYER_TR_X]
add a, 8
cp b
ret c
; Check if player is to the left of the end of the obstacle
ld a, [_OBSTACLE_X]
add a, 16
ld b, a
ld a, [_S_PLAYER_TL_X]
cp b
ret nc
; We know the player is in between the pipes
ld a, [_S_OBS_TL_Y]
add a, 8
ld b, a
ld a, [_S_PLAYER_TL_Y]
cp b
jp nc, .checkBottom
call SetGameOver
ret
.checkBottom
ld a, [_S_OBS_BL_Y]
ld b, a
ld a, [_S_PLAYER_BL_Y]
add a, 8
cp b
call nc, SetGameOver
ret
SECTION "TileSet", ROM0
TileSet:
INCBIN "tile.bin"
TileSetEnd:
SECTION "TileMap", ROM0
TileMap:
INCBIN "map.bin"
TileMapEnd:
SECTION "Sprites", ROM0
Sprites:
INCBIN "sprites.bin"
SpritesEnd:
ENDC ;GAME_INC