Skip to content

Commit

Permalink
Animate boss wings
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Feb 7, 2017
1 parent ece512b commit fb229c5
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Makefile
Expand Up @@ -97,7 +97,7 @@ OBJ = $(patsubst %.asm,.b/%.o,$(SRC)) .b/trig.o
.b/fader.o: fader.asm .b/fader_pal.dat
ca65 -o .b/fader.o fader.asm -g

.b/endboss.o: endboss.asm .b/boss.compressed.asm
.b/endboss.o: endboss.asm .b/boss.compressed.asm .b/boss.animate0.asm .b/boss.animate1.asm
ca65 -o .b/endboss.o endboss.asm -g

.b/msg_catalog.o: msg_catalog.asm .b/hud_msg.asm .b/title_msg.asm
Expand Down Expand Up @@ -202,6 +202,10 @@ OBJ = $(patsubst %.asm,.b/%.o,$(SRC)) .b/trig.o
mkdir -p .b/
makechr boss.png -o .b/boss.o -b 0f

.b/boss2.o: boss2.png
mkdir -p .b/
makechr boss2.png -o .b/boss2.o -b 0f

.b/bg_pal.o .b/bg_pal.dat: bg_pal.png
makechr --makepal bg_pal.png -o .b/bg_pal.o
makechr --makepal bg_pal.png -o .b/bg_pal.dat
Expand Down Expand Up @@ -268,13 +272,17 @@ OBJ = $(patsubst %.asm,.b/%.o,$(SRC)) .b/trig.o
head -c 16 .b/bg_pal.dat > .b/resource.palette.dat
tail -c 16 .b/chars.palette.dat >> .b/resource.palette.dat

.b/resource1.chr.dat .b/boss.graphics.dat .b/boss.palette.dat: \
.b/chars.chr.dat .b/hud.o .b/boss.o .b/alpha.o .b/digit.o
python merge_chr_nt.py .b/hud.o .b/boss.o -A .b/alpha.o -D .b/digit.o \
-c .b/boss.chr.dat -n .b/boss.nametable.dat \
-a .b/boss.attribute.dat
cat .b/boss.nametable.dat .b/boss.attribute.dat > \
.b/resource1.chr.dat .b/boss.graphics.dat .b/boss.palette.dat .b/boss.animate0.asm .b/boss.animate1.asm: \
.b/chars.chr.dat .b/hud.o .b/boss.o .b/boss2.o .b/alpha.o .b/digit.o
python merge_chr_nt.py .b/hud.o .b/boss.o .b/boss2.o \
-A .b/alpha.o -D .b/digit.o \
-c .b/boss.chr.dat -n .b/boss%d.nametable.dat \
-a .b/boss%d.attribute.dat
cat .b/boss01.nametable.dat .b/boss01.attribute.dat > \
.b/boss.graphics.dat
python build_boss_delta.py \
.b/boss01.nametable.dat .b/boss02.nametable.dat \
-l .b/boss.animate0.asm -r .b/boss.animate1.asm
head -c 4096 .b/boss.chr.dat > .b/resource1.chr.dat
tail -c 4096 .b/chars.chr.dat >> .b/resource1.chr.dat

Expand Down
3 changes: 3 additions & 0 deletions boot.asm
Expand Up @@ -7,6 +7,7 @@
.include "gfx.h.asm"
.include "intro_outro.h.asm"
.include "famitone.h.asm"
.include "endboss.h.asm"

.importzp bg_x_scroll, bg_y_scroll, main_yield, ppu_ctrl_current, debug_mode
.importzp player_removed
Expand Down Expand Up @@ -86,6 +87,8 @@ NMI:
jsr LevelDataUpdateScroll
; Render changes to the PPU.
jsr RenderActionApplyAll
; Boss wing animation.
jsr EndbossAnimation
; Reset ppu pointer.
lda #0
sta PPU_ADDR
Expand Down
Binary file added boss2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions build_boss_delta.py
@@ -0,0 +1,85 @@
import argparse


def read_file(filename):
fp = open(filename, 'r')
content = fp.read()
fp.close()
return content


def is_next_pos(prev_y, prev_x, y, x):
if prev_y is None or prev_x is None:
return False
if y == prev_y and x == prev_x + 1:
return True
if y == prev_y + 1 and x == 0 and prev_x == 31:
return True
return False


def write_addr(fout, byte):
if byte == 0:
fout.write('sty PPU_ADDR\n')
elif byte == 0x25:
fout.write('stx PPU_ADDR\n')
else:
fout.write('mov PPU_ADDR, #$%02x\n' % byte)


def write_data(fout, byte):
if byte == 0:
fout.write('sty PPU_DATA\n')
elif byte == 0x25:
fout.write('stx PPU_DATA\n')
else:
fout.write('mov PPU_DATA, #$%02x\n' % byte)


def create_deltas(left, rite, fpl, fpr):
n = 0
prev_y = None
prev_x = None
fpl.write('ldy #$00\n')
fpr.write('ldy #$00\n')
fpl.write('ldx #$25\n')
fpr.write('ldx #$25\n')
for y in xrange(30):
for x in xrange(32):
pos = y * 32 + x
a = ord(left[pos])
b = ord(rite[pos])
if a == b:
continue
if not is_next_pos(prev_y, prev_x, y, x):
high = y / 8 + 0x24
low = (y % 8) * 0x20 + x
write_addr(fpl, high)
write_addr(fpr, high)
write_addr(fpl, low)
write_addr(fpr, low)
write_data(fpl, a)
write_data(fpr, b)
prev_y = y
prev_x = x
fpl.write('rts\n')
fpr.write('rts\n')


def run():
parser = argparse.ArgumentParser()
parser.add_argument('input', nargs='+')
parser.add_argument('-l', dest='out_left')
parser.add_argument('-r', dest='out_right')
args = parser.parse_args()
left = read_file(args.input[0])
rite = read_file(args.input[1])
fpl = open(args.out_left, 'w')
fpr = open(args.out_right, 'w')
create_deltas(left, rite, fpl, fpr)
fpl.close()
fpr.close()


if __name__ == '__main__':
run()
46 changes: 46 additions & 0 deletions endboss.asm
Expand Up @@ -2,6 +2,7 @@
.export EndBossUpdate
.export EndBossFillGraphics
.export EndBossSwatterHandle
.export EndbossAnimation

.include "include.controller.asm"
.include "include.branch-macros.asm"
Expand All @@ -20,6 +21,8 @@
.importzp endboss_screen, endboss_count, endboss_state
.importzp endboss_h, endboss_health, endboss_aggro, endboss_speed
.importzp endboss_iframe, endboss_is_dead
.importzp endboss_render_animation
.importzp endboss_render_animation, endboss_render_count
.importzp player_owns_swatter, player_health, player_h
.importzp blink_bg_color
.importzp bg_x_scroll, bg_nt_select
Expand Down Expand Up @@ -50,6 +53,8 @@ Okay:
mov endboss_count, #0
mov endboss_aggro, #0
mov endboss_is_dead, #0
mov endboss_render_animation, #0
mov endboss_render_count, #0
rts
.endproc

Expand Down Expand Up @@ -220,6 +225,20 @@ PlayerOverlap:
jsr SoundPlay
mov player_health, #0
Break:
.endscope

.scope AnimateWings
inc endboss_render_count
lda endboss_render_count
cmp #4
blt Next
mov endboss_render_count, #0
inc endboss_render_animation
lda endboss_render_animation
and #1
ora #$80
sta endboss_render_animation
Next:
.endscope

rts
Expand Down Expand Up @@ -282,3 +301,30 @@ ExitBoss:
jsr DisableDisplayAndNmi
inc which_level
jmp MarqueScreen


.segment "BOOT"


.proc EndbossAnimation
lda endboss_render_animation
bpl Return
and #$01
sta endboss_render_animation
beq Render0
bne Render1
Render0:
jmp BossAnimateWing0
Render1:
jmp BossAnimateWing1
Return:
rts
.endproc


BossAnimateWing0:
.include ".b/boss.animate0.asm"


BossAnimateWing1:
.include ".b/boss.animate1.asm"
1 change: 1 addition & 0 deletions endboss.h.asm
Expand Up @@ -2,5 +2,6 @@
.import EndBossUpdate
.import EndBossFillGraphics
.import EndBossSwatterHandle
.import EndbossAnimation

BOSS_LEVEL = $04
3 changes: 3 additions & 0 deletions vars.asm
Expand Up @@ -100,6 +100,8 @@ endboss_speed: .byte 0
endboss_iframe: .byte 0
blink_bg_color: .byte 0
endboss_is_dead: .byte 0
endboss_render_animation: .byte 0
endboss_render_count: .byte 0

; progress
score_low: .byte 0
Expand Down Expand Up @@ -151,6 +153,7 @@ which_level: .byte 0
.exportzp endboss_screen, endboss_count, endboss_state
.exportzp endboss_h, endboss_health
.exportzp endboss_aggro, endboss_speed, endboss_iframe, endboss_is_dead
.exportzp endboss_render_animation, endboss_render_count
.exportzp blink_bg_color


Expand Down

0 comments on commit fb229c5

Please sign in to comment.