~nytpu/ankano unlisted

ref: da31db5c388a3f843e1bde029528c191a374c119 ankano/src/player.asm -rw-r--r-- 1.5 KiB
da31db5cnytpu add useful defines and use them 4 months ago
                                                                                
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
; player.asm
; player paddle handlers and initialization
;
; Copyright (C) 2020 nytpu
; SPDX-License-Identifier: GPL-3.0-or-later
; For more license details, see LICENSE or <https://www.gnu.org/licenses/>.

INCLUDE "defines.asm"

SECTION "Player Handler", ROM0
; initializes the player variables and initiates oam dma
; destroy a, b, c, h, l
InitPlayer::
	;dstruct PlayerStruct, Player

	ld a, SCRN_Y - 12
	ld [Player_YPos], a
	add PLAYER_HEIGHT ; one sprite tall
	ld [Player_YBox], a

	ld a, (PLAYSPACE_WIDTH / 2) - 4
	ld [Player_XPos], a
	add PLAYER_WIDTH ; three sprites wide
	ld [Player_XBox], a

	xor a
	ld [Player_Attr], a

	ld hl, Player_Tiles
	ld b, 4
REPT 3
	ld [hl], b
	inc hl
	inc b
ENDR

; deals with player updates and bounds checking, generates and copies oam
; destroy a, b, c, h, l
PlayerHandler::
	ld hl, Player_XPos
	ld a, PLAYSPACE_WIDTH - PLAYER_WIDTH
	cp [hl]
	jr nc, .withinBounds_R
	ld [hl], a
.withinBounds_R
	ld a, 16
	cp [hl]
	jr c, .withinBounds
	ld [hl], a
.withinBounds

; initiates oam dma
; destroy a, b, c, h, l
; TODO: break out into separate oam generator
CreatePlayerOAM:
	ld b, 0
	ld c, 0
	ld hl, wShadowOAM
REPT 3
	ld a, [Player_YPos]
	ld [hli], a

	ld a, [Player_XPos]
	add b
	ld [hli], a

	ld a, [Player_Tiles]
	add c
	ld [hli], a

	ld a, [Player_Attr]
	ld [hli], a

	ld a, b
	add 8
	ld b, a
	inc c
ENDR

	ld a, HIGH(wShadowOAM)
	ldh [hOAMHigh], a
	ret


SECTION "Player Variables", HRAM
sizeof_Player EQU 8
Player::
Player_YPos:: dw
Player_XPos:: dw
Player_YBox:: dw
Player_XBox:: db
Player_Attr:: db
Player_Tiles:: ds 3