-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmob.s
196 lines (183 loc) · 3.02 KB
/
mob.s
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
.include "global.inc"
.export mob_at
.export damage_mob
.export kill_mob
.export rand_mob
.export is_alive
.export mob_dmg
.segment "ZEROPAGE"
mob_size = .sizeof(Mob)
mobs_size = .sizeof(Mob)*maxmobs
.segment "BSS"
mobs: .res mobs_size
.segment "CODE"
; get a mob at xpos and ypos
; out: 0 on success, 1 on failure
; updates: y register to mob index
.proc mob_at
lda #$00
tay
mob_at_loop:
jsr is_alive
bne mob_at_continue
lda mobs + Mob::coords + Coord::xcoord, y
cmp xpos
bne mob_at_continue
lda mobs + Mob::coords + Coord::ycoord, y
cmp ypos
beq mob_at_success
mob_at_continue:
tya
clc
adc #mob_size
tay
cmp #mobs_size
beq mob_at_fail
jmp mob_at_loop
mob_at_success:
lda #0
rts
mob_at_fail:
ldy #$FF
lda #1
rts
.endproc
; deal damage to mob at index y
; in: damage
.proc damage_mob
cmp mobs+Mob::hp, y
bcs kill_mob
; subtract damage from hp
sta a1
lda mobs+Mob::hp, y
sec
sbc a1
sta mobs+Mob::hp, y
rts
.endproc
; kill the mob at index y
.proc kill_mob
lda #0
sta mobs+Mob::hp, y
rts
.endproc
; check if mob alive
;
; y: mob index
; out: 0 if alive
.proc is_alive
lda mobs + Mob::hp, y
beq is_dead
lda #0
rts
is_dead:
lda #1
rts
.endproc
; damage roll for mob at index y
; out: damage amount
; clobbers: x
.proc mob_dmg
lda mobs + Mob::type, y
cmp #Mobs::player
beq player
cmp #Mobs::goblin
beq d4_dmg
cmp #Mobs::orc
beq d6_dmg
cmp #Mobs::ogre
beq d8_dmg
cmp #Mobs::dragon
beq d12_dmg
rts
player:
jsr player_dmg
rts
d4_dmg:
jsr d4
rts
d6_dmg:
jsr d4
rts
d8_dmg:
jsr d8
rts
d12_dmg:
jsr d12
rts
.endproc
; generate random mob at index y
; clobbers: x
; todo ensure we don't spawn mobs in LOS of player?
.proc rand_mob
; store y for later use
tya
pha
; generate rand x, y
jsr rand_passable
; restore y pos
pla
tay
; continue mob generation
lda xpos
sta mobs + Mob::coords + Coord::xcoord, y
lda ypos
sta mobs + Mob::coords + Coord::ycoord, y
lda #Direction::right
sta mobs + Mob::direction, y
; generate random mob type
lda dlevel
cmp #3
bcc gen_1_mob
cmp #5
bcc gen_2_mob
cmp #7
bcc gen_3_mob
jmp gen_4_mob
gen_1_mob:
jsr d4
cmp #4
bcs gen_orc
jmp gen_goblin
gen_2_mob:
jsr d4
cmp #4
bcs gen_ogre
jmp gen_orc
gen_3_mob:
jsr d4
cmp #3
bcs gen_ogre
jmp gen_orc
gen_4_mob:
jsr d4
cmp #4
bcs gen_dragon
cmp #2
bcs gen_ogre
jmp gen_orc
gen_goblin:
lda #4
sta mobs + Mob::hp, y
lda #Mobs::goblin
sta mobs + Mob::type, y
rts
gen_orc:
lda #6
sta mobs + Mob::hp, y
lda #Mobs::orc
sta mobs + Mob::type, y
rts
gen_ogre:
lda #10
sta mobs + Mob::hp, y
lda #Mobs::ogre
sta mobs + Mob::type, y
rts
gen_dragon:
lda #20
sta mobs + Mob::hp, y
lda #Mobs::dragon
sta mobs + Mob::type, y
rts
.endproc