Skip to content

Commit

Permalink
Health meter. Take damage from flies, gain life from food.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Dec 1, 2016
1 parent 24d6626 commit a27180f
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -25,7 +25,8 @@ SRC = main.asm \
food.asm \
explode.asm \
points.asm \
random.asm
random.asm \
health.asm

OBJ = $(patsubst %.asm,.b/%.o,$(SRC)) .b/trig.o

Expand Down
2 changes: 2 additions & 0 deletions fly.asm
Expand Up @@ -18,6 +18,7 @@ COLLISION_SWATTER_FLY_V_HITBOX = 10

.importzp player_screen, player_h, player_owns_swatter
.importzp player_injury, player_iframe, player_gravity, player_gravity_low
.importzp player_health_delta
.importzp camera_h, camera_screen
.importzp spawn_count
.importzp draw_h, draw_v, draw_screen
Expand Down Expand Up @@ -228,6 +229,7 @@ DidCollide:
mov player_iframe, #100
mov player_gravity, #$fe
mov player_gravity_low, #$00
dec player_health_delta
jmp Return
Next:
.endscope
Expand Down
13 changes: 12 additions & 1 deletion food.asm
Expand Up @@ -15,6 +15,7 @@
.include ".b/pictures.h.asm"

.importzp camera_h, camera_screen
.importzp player_health_delta
.importzp have_spawned_food
.importzp draw_screen
.importzp values
Expand All @@ -28,6 +29,10 @@ FOOD_KIND_APPLE = 0
FOOD_KIND_STEAK = 1


LIFE_GAIN_APPLE = 2
LIFE_GAIN_STEAK = 5


.segment "CODE"


Expand Down Expand Up @@ -114,10 +119,16 @@ DidCollide:
beq PointsApple
bne PointsSteak
PointsApple:
lda #LIFE_GAIN_APPLE
ldy #POINTS_APPLE
skip2
jmp Okay
PointsSteak:
lda #LIFE_GAIN_STEAK
ldy #POINTS_STEAK
Okay:
clc
adc player_health_delta
sta player_health_delta
jsr PointsGainAndCreate
jsr ObjectFree
jmp Return
Expand Down
75 changes: 75 additions & 0 deletions health.asm
@@ -0,0 +1,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 = $af
HEALTH_EMPTY_TILE = $b0

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
2 changes: 2 additions & 0 deletions health.h.asm
@@ -0,0 +1,2 @@
.import HealthSetMax
.import HealthApplyDelta
Binary file modified hud.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions hud_display.asm
Expand Up @@ -14,6 +14,7 @@ SPRITE_0_TILE = $2b
.importzp ppu_ctrl_current, bg_x_scroll, bg_nt_select

.segment "CODE"

.proc HudSplitAssign
mov $200, #19
mov $201, #SPRITE_0_TILE
Expand Down
5 changes: 5 additions & 0 deletions main.asm
Expand Up @@ -14,6 +14,7 @@
.include "fly.h.asm"
.include "food.h.asm"
.include "random.h.asm"
.include "health.h.asm"

.importzp bg_x_scroll, bg_y_scroll, main_yield, ppu_ctrl_current, debug_mode
.import palette, graphics0, graphics1
Expand Down Expand Up @@ -71,6 +72,7 @@ Wait1:

jsr HudDataFill
jsr LevelDataFillEntireScreen
jsr HealthSetMax

jsr RandomSeedInit
jsr PlayerInit
Expand Down Expand Up @@ -132,6 +134,9 @@ GameplayLoop:
DebugModeSetTint red
jsr FlashEarnedCombo

DebugModeSetTint green
jsr HealthApplyDelta

DebugModeSetTint 0
jsr MaybeDebugToggle

Expand Down
5 changes: 4 additions & 1 deletion vars.asm
Expand Up @@ -25,6 +25,8 @@ player_owns_swatter: .byte 0
player_state: .byte 0
player_collision_idx: .byte 0
player_animate: .byte 0
player_health: .byte 0
player_health_delta: .byte 0
player_injury: .byte 0
player_iframe: .byte 0
camera_h: .byte 0
Expand Down Expand Up @@ -72,7 +74,8 @@ have_spawned_food: .byte 0
.exportzp player_v, player_h, player_h_low, player_screen, player_dir
.exportzp player_gravity, player_gravity_low, player_render_v, player_render_h
.exportzp player_owns_swatter, player_state, player_collision_idx
.exportzp player_animate, player_injury, player_iframe
.exportzp player_animate, player_health, player_health_delta
.exportzp player_injury, player_iframe
.exportzp camera_h, camera_screen
.exportzp values, pointer
.exportzp NMI_SCROLL_target, NMI_SCROLL_strip_id, NMI_SCROLL_action
Expand Down

0 comments on commit a27180f

Please sign in to comment.