-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.asm
75 lines (63 loc) · 1.19 KB
/
health.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
.export HealthSetMax
.export HealthApplyDelta
.include "include.branch-macros.asm"
.include "include.mov-macros.asm"
.include "render_action.h.asm"
.importzp player_health, player_health_delta
HEALTH_FILL_TILE = $06
HEALTH_EMPTY_TILE = $07
HEALTH_MAX = 5
HEALTH_METER_PPU_HIGH = $20
HEALTH_METER_PPU_LOW = $64
.segment "CODE"
.proc HealthSetMax
mov player_health, #HEALTH_MAX
mov player_health_delta, #0
jmp RenderHealthMeter
.endproc
.proc HealthApplyDelta
lda player_health_delta
clc
adc player_health
bmi Negative
cmp #HEALTH_MAX
blt Okay
Max:
lda #HEALTH_MAX
bne Okay
Negative:
lda #0
Okay:
sta player_health
mov player_health_delta, #0
jsr RenderHealthMeter
lda player_health
beq Failure
Success:
sec
rts
Failure:
clc
rts
.endproc
.proc RenderHealthMeter
lda #5
jsr AllocateRenderAction
mov {render_action_addr_high,y}, #HEALTH_METER_PPU_HIGH
mov {render_action_addr_low,y}, #HEALTH_METER_PPU_LOW
ldx #0
Loop:
cpx player_health
blt FillOne
EmptyOne:
mov {render_action_data,y}, #HEALTH_EMPTY_TILE
bne Increment
FillOne:
mov {render_action_data,y}, #HEALTH_FILL_TILE
Increment:
iny
inx
cpx #HEALTH_MAX
blt Loop
rts
.endproc