From 681ba9adf948ebdc909b08979c76251053af7a9e Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 11 May 2023 20:57:55 +0100 Subject: Add starfield effect --- game/entities.asm | 2 +- game/main.asm | 54 ++++++++++++++++++++++++++++++++++++++--- game/starfield.asm | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 game/starfield.asm diff --git a/game/entities.asm b/game/entities.asm index 6116624..b3e1eea 100644 --- a/game/entities.asm +++ b/game/entities.asm @@ -265,7 +265,7 @@ entity_draw_frame_done: ; blit dec b - ; writw, transparent + ; write, transparent ld y, 3 port b, y diff --git a/game/main.asm b/game/main.asm index 68d1267..e779a95 100644 --- a/game/main.asm +++ b/game/main.asm @@ -8,6 +8,7 @@ game_loop: halt call entities_erase + call stars_update call entities_update call entities_draw @@ -29,14 +30,13 @@ init: halt - ; pattern for the BG - ld b, 15 + ; erase the screen + ld b, 0 ld a, 0xbf ld x, 0 ld y, 0x40 fill_loop: ld [a : x], b - xor b, 5 inc x bno jmp fill_loop @@ -52,6 +52,7 @@ fill_loop: int_handler: iret +.include "starfield.asm" .include "entities.asm" .include "player.asm" @@ -75,3 +76,50 @@ entities: player_sprite: .incpng "assets/player.png" +; starfield data +stars: + ; video addr, speed, color + .dw 0xc361 + .db 1, 15 + .dw 0xc204 + .db 1, 6 + .dw 0xcdf9 + .db 1, 15 + .dw 0xdb87 + .db 1, 3 + .dw 0xd242 + .db 1, 15 + .dw 0xdeea + .db 1, 6 + .dw 0xe7af + .db 1, 15 + .dw 0xed68 + .db 1, 3 + .dw 0xf812 + .db 1, 15 + .dw 0xfbca + .db 1, 13 + .dw 0xc361 + .db 2, 8 + .dw 0xc204 + .db 2, 9 + .dw 0xcdf9 + .db 3, 7 + .dw 0xdb87 + .db 3, 4 + .dw 0xd242 + .db 2, 8 + .dw 0xdeea + .db 3, 9 + .dw 0xe7af + .db 3, 6 + .dw 0xed68 + .db 2, 9 + .dw 0xf812 + .db 3, 14 + .dw 0xfbca + .db 2, 3 + ; end of list + .dw 0xffff + + diff --git a/game/starfield.asm b/game/starfield.asm new file mode 100644 index 0000000..e8b8ed1 --- /dev/null +++ b/game/starfield.asm @@ -0,0 +1,70 @@ +; +; Simple starfield effect +; +stars_update: + ld x, stars + +stars_update_loop: + ld y, [a : x] + inc x + bo + inc a + ld b, [a : x] + ; is the end of list? + cmp b, 0xff + bz + ret + + push a + push x + + ; erase old + ld x, 0 + ld [b : y], x + ld x, [sp + 0] + + ; update address + inc x + bo + inc a + push x + ld x, [a : x] +stars_update_addr: + add y, 128 + bo + inc b + cmp b, 0xfe + bnz + jmp stars_no_wrap + cmp y, 0x80 + bc + ld b, 0xbf +stars_no_wrap: + dec x + bnz + jmp stars_update_addr + pop x + + ; draw new: color + inc x + bo + inc a + ld x, [a : x] + ld [b : y], x + + pop x + pop a + + ; save new address + ld [a : x], b + dec x + bo + dec a + ld [a : x], y + + ; next star + add x, 4 + bo + inc a + jmp stars_update_loop -- cgit v1.2.3