-
Notifications
You must be signed in to change notification settings - Fork 22
/
player.asm
97 lines (92 loc) · 2.06 KB
/
player.asm
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
PlayerPos:
PlayerRow: DB START_ROW
PlayerCol: DB START_COL
MoveDir: DW 0
PlayerScrBase: DW START_ROW * 320 * 16 + START_COL * 16
UnderTile: DB 0
; how to update the player coordinates (board)
MoveTable:
.up: DB -1
DB 0
.left: DB 0
DB -1
.right: DB 0
DB 1
.down: DB 1
DB 0
; how to update the player coordinates (screen)
MoveTable2:
.up: DW -16 * 320
.left: DW -16
.right: DW 16
.down: DW 16 * 320
UpdatePlayer: PUSH SI
PUSH BX
MOV AX, [MoveDir]
AND AX, AX ; are we moving?
JZ .done
; get index into move table into SI
MOV SI, AX
DEC SI
SHL SI, 1 ; *2 for word addrs
MOV AX, [PlayerPos]
ADD AL, [MoveTable + SI] ; get new tile
ADD AH, [MoveTable + SI + 1]
MOV BX, AX ; backup new pos
CALL Shove
MOV AX, BX
CALL CanWalk ; is this tile clear?
JZ .clearMove
MOV AX, BX
.move: CALL ErasePlayer
MOV [PlayerPos], BX ; update new pos
MOV AX, [MoveTable2 + SI]
ADD [PlayerScrBase], AX
CALL UpdateUnder
CALL DrawPlayer ; draw the player
.clearMove: MOV BYTE [MoveDir], 0
.done: POP BX
POP SI
RET
; AX - contains position to be shoved
; SI - contains index into move table
Shove: PUSH BX
PUSH DX
; first, determine if there's a box in the shove location
MOV BX, AX ; backup pos
CALL FindBox
JNE .done
SUB AX, 2
XCHG AX, BX ; put box ptr into BX
MOV DX, AX ; copy shove pos
; check if the shove destination is clear
ADD AL, [MoveTable + SI]
ADD AH, [MoveTable + SI + 1]
PUSH AX ; backup shove dest
CALL CanWalk
POP AX ; get shove dest
JZ .done
; now, check if the box was on a target
XCHG AX, DX ; AX = src, DX = dest
CALL IsTarget
JNE .checkDest
DEC BYTE [BoxesOn]
; check if it's getting pushed onto a target
.checkDest: MOV AX, DX ; get destination
CALL IsTarget
JNE .doShove
INC BYTE [BoxesOn]
.doShove: MOV [BX], DX ; update box data
.done: POP DX
POP BX
RET
UpdateUnder: PUSH SI
XOR AH, AH
MOV AL, [PlayerRow]
SHL AL, 3 ; row * 8 bc 8 cols/row
ADD AL, BYTE [PlayerCol]
MOV SI, AX
MOV AL, [Board + SI]
MOV [UnderTile], AL
POP SI
RET