diff options
author | Astatin <[email protected]> | 2025-05-13 15:52:37 +0200 |
---|---|---|
committer | Astatin <[email protected]> | 2025-05-13 15:52:37 +0200 |
commit | ef9de76cd0bc313385b7edac3659e03ab36d3c1e (patch) | |
tree | 4125a1ba04438d8e9db5262d24b525f370a41f2f | |
parent | b0f9e2e6d53983faa9d213b40d2bd6a23473e134 (diff) |
Add bugs and poison
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | animation.gbasm | 5 | ||||
-rw-r--r-- | animations/bubbles.gbasm | 101 | ||||
-rw-r--r-- | definitions.gbasm | 15 | ||||
-rw-r--r-- | enemiesattacks.gbasm | 1 | ||||
-rw-r--r-- | enemiesattacks/freeze.gbasm | 2 | ||||
-rw-r--r-- | enemiesattacks/poison.gbasm | 77 | ||||
-rw-r--r-- | entity/actions.gbasm | 37 | ||||
-rw-r--r-- | entity/bug.gbasm | 130 | ||||
-rw-r--r-- | entity/bunny.gbasm | 78 | ||||
-rw-r--r-- | entity/list.gbasm | 76 | ||||
-rw-r--r-- | entity/penguin.gbasm | 2 | ||||
-rw-r--r-- | main.gbasm | 9 | ||||
-rw-r--r-- | map/dungeons.gbasm | 19 | ||||
-rw-r--r-- | modes/dungeon.gbasm | 3 | ||||
-rw-r--r-- | modes/dungeongeneration.gbasm | 2 | ||||
-rw-r--r-- | scripts/generate-tiledata.py | 9 | ||||
-rw-r--r-- | scripts/parse_sprite_png.py | 160 | ||||
-rw-r--r-- | sprites/animations/bubble1.png | bin | 0 -> 147 bytes | |||
-rw-r--r-- | sprites/animations/bubble2.png | bin | 0 -> 191 bytes | |||
-rw-r--r-- | sprites/gui/status-frozen.png | bin | 0 -> 140 bytes | |||
-rw-r--r-- | sprites/gui/status-poison.png | bin | 0 -> 167 bytes | |||
-rw-r--r-- | tiles.gbasm | 4 | ||||
-rw-r--r-- | tileset.gbasm | 10 |
24 files changed, 598 insertions, 143 deletions
@@ -1,2 +1,3 @@ build/ recordings/ +scripts/__pycache__/ diff --git a/animation.gbasm b/animation.gbasm index fdd64ae..dfeb695 100644 --- a/animation.gbasm +++ b/animation.gbasm @@ -140,6 +140,11 @@ Animation_Jump_table: JP =Laser_Animation NOP + ; 04 + JP =Bubbles_Animation + NOP + .INCLUDE "animations/sparkles.gbasm" .INCLUDE "animations/rotatingball.gbasm" .INCLUDE "animations/laser.gbasm" +.INCLUDE "animations/bubbles.gbasm" diff --git a/animations/bubbles.gbasm b/animations/bubbles.gbasm new file mode 100644 index 0000000..6678e1e --- /dev/null +++ b/animations/bubbles.gbasm @@ -0,0 +1,101 @@ +Bubbles_Animation: + INC HL + + LD A, (HL+) + ADD $80 + LD D, A + LD A, $mem_viewport_x + LD B, A + SUB $82 + CP D + RET NC + ADD $0e + CP D + RET C + LD A, D + SUB $80 + SUB B + AND $0f + SWAP A + LD B, A + + + LD A, (HL+) + ADD $80 + LD D, A + LD A, $mem_viewport_y + LD C, A + SUB $82 + CP D + RET NC + ADD $0d + CP D + RET C + LD A, D + SUB $80 + SUB C + AND $0f + SWAP A + ADD $06 + LD C, A + + LD E, (HL) + DEC E + XOR A + CP E + JP Z, =End_animation + LD (HL), E + LD A, $20 + SUB E + LD E, A + + .ADD_MOVING_ANIMATION_OFFSET + + PUSH HL + LD HL, $mem_oam_buffer + LD A, $mem_oam_buffer_low + LD L, A + + LD D, E + SRA D + LD A, C + SUB D + ADD $0c + LD (HL+), A + LD A, B + LD (HL+), A + LD A, E + SRA A + SRA A + AND $02 + ADD $vram_animation_index + ADD $06 ; bubbles + + LD (HL+), A + LD A, $00 + LD (HL+), A + + SRA D + LD A, C + SUB D + ADD $08 + LD (HL+), A + LD A, B + ADD $08 + LD (HL+), A + LD A, E + SRA A + SRA A + AND $02 + ADD $vram_animation_index + ADD $06 ; bubbles + + LD (HL+), A + LD A, $00 + LD (HL+), A + + LD A, L + LD $mem_oam_buffer_low, A + + POP HL + RET diff --git a/definitions.gbasm b/definitions.gbasm index e8fdd5f..c4ae844 100644 --- a/definitions.gbasm +++ b/definitions.gbasm @@ -29,6 +29,7 @@ ; frame 5: entity collision map is being updated ; frame 8: attack is executed on the enemies if it was predicted in frame "-1" ; frame 9: entity collision map is being updated (again) +; frame 12: poison effect thingy ; frame 15: movement is ended and coordinates are updated .DEFINE mem_bunny_sprite ($cb00) @@ -150,6 +151,8 @@ .DEFINE mem_entity_spawning_pattern ($c04d) .DEFINE mem_floor_count_bin ($c04e) +.DEFINE mem_bunny_status_tile ($c04f) + ; ## WARNING THE SPACE BETWEEN $c400 and $c800 is used as a buffer for the loading map function during dungeon generation .DEFINE mem_map_loading_buffer $c400 @@ -252,7 +255,7 @@ ; flags: u8 ; bit 0: speed 2x ; bit 1: shadow mode -; bit 2: end of turn attack mode +; bit 2: end of turn effect (attack mode for fox, die for bug) ; bit 3: blinking mode ; status: u8 ; ; bit 0: whether or not turns should be skipped @@ -260,6 +263,7 @@ ; ; 01: freeze ; ; 02: invincible ; ; 04: end of freeze +; ; 08: poison ; mana: u8 ; animation: u8 ; animations: @@ -283,6 +287,15 @@ .DEFINE enum_direction_up $03 .DEFINE enum_direction_down $04 +.DEFINE entity_fox_index $00 +.DEFINE entity_frog_index $01 +.DEFINE entity_cat_index $02 +.DEFINE entity_penguin_index $03 +.DEFINE entity_mouse_index $04 +.DEFINE entity_fimsh_index $05 +.DEFINE entity_questgoalbunny_index $06 +.DEFINE entity_bug_index $07 + .DEFINE palette_normal $e4 .DEFINE palette_black $ff .DEFINE palette_white $94 diff --git a/enemiesattacks.gbasm b/enemiesattacks.gbasm index ec21d1d..4f2ef61 100644 --- a/enemiesattacks.gbasm +++ b/enemiesattacks.gbasm @@ -49,3 +49,4 @@ Check_player_next_to: ; BC = XY of the enemy. D is unchanged. Direction to face .INCLUDE "enemiesattacks/laser.gbasm" .INCLUDE "enemiesattacks/freeze.gbasm" .INCLUDE "enemiesattacks/grab.gbasm" +.INCLUDE "enemiesattacks/poison.gbasm" diff --git a/enemiesattacks/freeze.gbasm b/enemiesattacks/freeze.gbasm index e5ce309..86e47d9 100644 --- a/enemiesattacks/freeze.gbasm +++ b/enemiesattacks/freeze.gbasm @@ -75,8 +75,6 @@ Freeze_Enemy_Attack: ; Direction to face in E. Result in BC (XY), Direction in D LD A, $04 LD $mem_bunny_status_clear_turn_counter, A - LD A, $enum_dungeon_mode - LD $mem_requested_mode, A LD A, L AND $f0 diff --git a/enemiesattacks/poison.gbasm b/enemiesattacks/poison.gbasm new file mode 100644 index 0000000..807eae3 --- /dev/null +++ b/enemiesattacks/poison.gbasm @@ -0,0 +1,77 @@ +Poison_sight_check: ; BC = XY of the enemy. D = direction (must be unchanged). Direction to face in E (or 0 if not) + LD E, $00 + + LD A, L + AND $f0 + ADD $09 + LD L, A + LD A, $00 + CP (HL) + RET Z + JP =Check_player_next_to + +Poison_Enemy_Attack: ; Direction to face in E. Result in BC (XY), Direction in D + LD A, D + AND $f0 + SWAP A + LD D, A + LD A, E + DEC A + DEC D + XOR D + INC D + CP $00 + JR Z, =.attack + BIT 1, A + JR NZ, =.attack + + LD D, E + LD A, D + SWAP A + AND $70 + OR D + LD D, A + RET + + .attack: + LD A, E + SWAP A + AND $70 + OR E + LD D, A + LD A, L + AND $f0 + OR $0a + LD L, A + LD (HL), $01 + + PUSH BC + LD A, $mem_bunny_direction + AND $08 + LD B, A + LD A, $mem_bunny_flags + AND $01 + OR B + CP $09 + POP BC + RET Z + + LD A, $08 + LD $mem_bunny_status, A + + LD A, $0a + LD $mem_bunny_status_clear_turn_counter, A + + LD A, L + AND $f0 + ADD $07 + LD L, A + SET 2, (HL) + + LD A, L + AND $f0 + ADD $09 + LD L, A + DEC (HL) + + RET diff --git a/entity/actions.gbasm b/entity/actions.gbasm index 92c2c5f..5b16891 100644 --- a/entity/actions.gbasm +++ b/entity/actions.gbasm @@ -62,44 +62,7 @@ Entity_Action: LD L, A RET -Turn_Jump_table: - ; 00 - RET - NOP - NOP - NOP - - ; 01 - JP =Move_Bunny - NOP - - ; 02 - JP =Fox_Turn - NOP - ; 03 - JP =Cat_Turn - NOP - - ; 04 - JP =Penguin_Turn - NOP - - ; 05 - JP =QuestGoal_Turn - NOP - - ; 06 - JP =Fimsh_Turn - NOP - - ; 07 - JP =Mouse_Turn - NOP - - ; 08 - JP =Frog_Turn - NOP Interaction_Jump_table: ; 00 diff --git a/entity/bug.gbasm b/entity/bug.gbasm new file mode 100644 index 0000000..29e5b77 --- /dev/null +++ b/entity/bug.gbasm @@ -0,0 +1,130 @@ +Bug_Drop: + PUSH DE + LD D, $64 + LD E, $02 + CALL =RNG_Step + AND $03 + CP $00 + CALL Z, =Spawn_object + POP DE + RET + +Bug_Turn: + LD A, $mem_map_loading_flags + BIT 3, A + RET Z + + PUSH HL + PUSH BC + PUSH DE + INC HL + LD A, (HL+) + LD B, A + LD A, (HL+) + LD C, A + LD A, (HL+) + LD D, A + + .ENTITY_HEALTH_CHECK =.Skip_turn =Mouse_Drop + .ENTITY_FREEZE_SHIVER =.Skip_turn + .ENTITY_STATUS_SKIP_TURN =.Skip_turn + + .RESET_BLINKING_MODE + + LD A, $mem_moving_animation_step + CP $00 + JR NZ, =.attack_end + + .ENTITY_TRY_ATTACK =Poison_sight_check =Poison_Enemy_Attack =.attack_end + CALL =Walking + BIT 3, D + JR Z, =.attack_end + LD A, L + AND $f0 + OR $0a + LD L, A + LD (HL), $05 + LD A, (HL) + DBG + .attack_end: + + .Mid_movement: + LD A, $mem_moving_animation_step + CP $07 + JR NZ, =.Mid_movement.end + + BIT 3, D + JR Z, =.Mid_movement.end + + LD A, L + AND $f0 + OR $0a + LD L, A + LD A, $05 + CP (HL) + LD A, (HL) + JR NZ, =.Mid_movement.end + + LD A, L + AND $f0 + OR $0a + LD L, A + LD (HL), $00 + + LD A, D + RES 3, A + LD D, A + LD A, $01 + .ADD_A_TO_DIRECTION_BC + + .Mid_movement.Try_Walking: + PUSH DE + CALL =Walking + BIT 3, D + JR Z, =.Mid_movement.Walk_cancelled + LD A, L + AND $f0 + OR $0a + LD L, A + LD (HL), $05 + ADD SP, $02 + JR =.Mid_movement.end + .Mid_movement.Walk_cancelled: + POP DE + RES 3, D + .Mid_movement.end: + + .Die_After_Attack: + LD A, $mem_moving_animation_step + CP $07 + JR NZ, =.Die_After_Attack.end + LD A, L + AND $f0 + OR $07 + LD L, A + BIT 2, (HL) + JR Z, =.Die_After_Attack.end + + DEC HL + + LD (HL), $00 + + .Die_After_Attack.end: + + CALL =Entity_End_movement + + .Skip_Turn: + LD A, L + AND $f0 + LD L, A + INC HL + LD A, B + LD (HL+), A + LD A, C + LD (HL+), A + LD A, D + LD (HL+), A + POP DE + POP BC + POP HL + RET diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm index dc04535..3806df4 100644 --- a/entity/bunny.gbasm +++ b/entity/bunny.gbasm @@ -6,6 +6,9 @@ Move_Bunny: LD E, $02 .Normal_speed: + LD A, $00 + LD $mem_bunny_status_tile, A + .Finish_unfreeze: LD A, $mem_moving_animation_step CP $00 @@ -18,12 +21,14 @@ Move_Bunny: .Finish_unfreeze.end: .Freeze_shiver: - LD A, $mem_moving_animation_step - CP $00 - JP NZ, =.Freeze_shiver.end LD A, $mem_bunny_status CP $01 JR NZ, =.Freeze_shiver.end + LD A, $f5 + LD $mem_bunny_status_tile, A + LD A, $mem_moving_animation_step + CP $00 + JP NZ, =.Freeze_shiver.end LD A, $mem_bunny_direction RES 3, A LD $mem_bunny_direction, A @@ -55,6 +60,73 @@ Move_Bunny: JP =.Skip_turn .Freeze_shiver.end: + .Poison_effect: + LD A, $mem_bunny_status + CP $08 + JR NZ, =.Poison_effect.end + LD A, $f6 + LD $mem_bunny_status_tile, A + LD A, $mem_moving_animation_step + CP $0c + JR NZ, =.Poison_effect.end + + LD A, $mem_bunny_status_clear_turn_counter + DEC A + CP $00 + LD $mem_bunny_status_clear_turn_counter, A + JR Z, =.Unpoison + + CALL =RNG_Step + AND $07 + CP $00 + JR Z, =.Unpoison + + CALL =RNG_Step + AND $01 + CP $00 + JR Z, =.Poison_effect.end + + PUSH BC + LD A, $mem_moving_animation_step + LD B, A + LD A, $1f + SUB B + LD $mem_blinking_animation_counter, A + LD A, $mem_bunny_flags + SET 3, A + LD $mem_bunny_flags, A + POP BC + + LD A, $mem_bunny_health + SUB $01 + JR C, =.Poison_effect.health_underflow_fix + DAA + LD $mem_bunny_health, A + JR =.Poison_effect.Skip_health_underflow_fix + .Poison_effect.health_underflow_fix: + LD A, $00 + LD $mem_bunny_health, A + .Poison_effect.Skip_health_underflow_fix: + + PUSH BC + LD A, $mem_bunny_predicted_x + LD B, A + LD A, $mem_bunny_predicted_y + LD C, A + LD A, $04 + PUSH DE + LD E, $20 + LD D, $00 + CALL =Try_Launch_Animation + POP DE + POP BC + JR =.Poison_effect.end + + .Unpoison: + LD A, $00 + LD $mem_bunny_status, A + .Poison_effect.end: + .Should_turn_be_skipped: LD A, $mem_bunny_status BIT 0, A diff --git a/entity/list.gbasm b/entity/list.gbasm index 3038a40..3b6649a 100644 --- a/entity/list.gbasm +++ b/entity/list.gbasm @@ -166,3 +166,79 @@ Entity_list: .DB 0b00 .PADTO =.QuestGoalBunny+8 + + .Bug: + ; Sprite address + .DB =OBJ_Tile_Image_Data.Bug + + ; Turn Jump Table index + .DB $09 + + ; Interaction Jump Table index + .DB $01 + + ; Starting health + .DB $01 + + ; Starting status + .DB $00 + + ; Starting mana + .DB $05 + + ; Spawning rate (2 lsb) + .DB 0b11 + + .PADTO =.Bug+8 + +Turn_Jump_table: + ; 00 + RET + NOP + NOP + NOP + + ; 01 + JP =Move_Bunny + NOP + + ; 02 + JP =Fox_Turn + NOP + + ; 03 + JP =Cat_Turn + NOP + + ; 04 + JP =Penguin_Turn + NOP + + ; 05 + JP =QuestGoal_Turn + NOP + + ; 06 + JP =Fimsh_Turn + NOP + + ; 07 + JP =Mouse_Turn + NOP + + ; 08 + JP =Frog_Turn + NOP + + ; 09 + JP =Bug_Turn + NOP + +.INCLUDE "entity/bunny.gbasm" +.INCLUDE "entity/fox.gbasm" +.INCLUDE "entity/cat.gbasm" +.INCLUDE "entity/mouse.gbasm" +.INCLUDE "entity/penguin.gbasm" +.INCLUDE "entity/fimsh.gbasm" +.INCLUDE "entity/frog.gbasm" +.INCLUDE "entity/bug.gbasm" diff --git a/entity/penguin.gbasm b/entity/penguin.gbasm index a3b4937..3b58586 100644 --- a/entity/penguin.gbasm +++ b/entity/penguin.gbasm @@ -42,7 +42,7 @@ Penguin_Turn: LD A, (HL+) LD D, A - .ENTITY_HEALTH_CHECK =.Skip_turn =Cat_Drop + .ENTITY_HEALTH_CHECK =.Skip_turn =Penguin_Drop .ENTITY_FREEZE_SHIVER =.Skip_turn .ENTITY_STATUS_SKIP_TURN =.Skip_turn @@ -138,18 +138,11 @@ Entrypoint: .INCLUDE "modes/vblank_handler_list.gbasm" .INCLUDE "entity/utils.gbasm" .INCLUDE "entity/init.gbasm" -.INCLUDE "entity/bunny.gbasm" -.INCLUDE "entity/fox.gbasm" -.INCLUDE "entity/cat.gbasm" -.INCLUDE "entity/mouse.gbasm" -.INCLUDE "entity/penguin.gbasm" -.INCLUDE "entity/fimsh.gbasm" -.INCLUDE "entity/frog.gbasm" +.INCLUDE "entity/list.gbasm" .INCLUDE "entity/questgoal.gbasm" .INCLUDE "entity/actions.gbasm" .INCLUDE "entity/collisions.gbasm" .INCLUDE "entity/display.gbasm" -.INCLUDE "entity/list.gbasm" .INCLUDE "animation.gbasm" .INCLUDE "playerattacks.gbasm" .INCLUDE "enemiesattacks.gbasm" diff --git a/map/dungeons.gbasm b/map/dungeons.gbasm index 930fede..5fb5a2c 100644 --- a/map/dungeons.gbasm +++ b/map/dungeons.gbasm @@ -88,14 +88,11 @@ Dungeon: .name: .DB =Dungeon_Name_1_Txt .max_floor: .DB 0x0a, inv(0x0a) .spawning_patterns: - ; --DBG-- - .DB $01, $01, $01, $01, 0b11111111 - ; --DBG-- - .DB $02, $02, $02, $05, 0b00000010 - .DB $02, $02, $03, $05, 0b00100011 - .DB $02, $02, $00, $05, 0b00100111 - .DB $00, $02, $03, $05, 0b00011101 - .DB $02, $02, $04, $05, 0b00111111 - .DB $02, $00, $03, $05, 0b00011111 - .DB $00, $04, $03, $05, 0b00011111 - .DB $00, $04, $03, $05, 0b00111111 + .DB $entity_cat_index, $entity_cat_index, $entity_cat_index, $entity_fimsh_index, 0b00000010 + .DB $entity_cat_index, $entity_cat_index, $entity_penguin_index, $entity_fimsh_index, 0b00100011 + .DB $entity_cat_index, $entity_cat_index, $entity_fox_index, $entity_fimsh_index, 0b00100111 + .DB $entity_fox_index, $entity_cat_index, $entity_penguin_index, $entity_fimsh_index, 0b00011101 + .DB $entity_cat_index, $entity_cat_index, $entity_mouse_index, $entity_fimsh_index, 0b00111111 + .DB $entity_cat_index, $entity_fox_index, $entity_penguin_index, $entity_fimsh_index, 0b00011111 + .DB $entity_fox_index, $entity_bug_index, $entity_penguin_index, $entity_fimsh_index, 0b00011111 + .DB $entity_fox_index, $entity_mouse_index, $entity_penguin_index, $entity_fimsh_index, 0b00111111 diff --git a/modes/dungeon.gbasm b/modes/dungeon.gbasm index 3d5b609..14d0381 100644 --- a/modes/dungeon.gbasm +++ b/modes/dungeon.gbasm @@ -168,6 +168,9 @@ Dungeon_VBLANK_Entrypoint: CALL =Display_Animation_List CALL =Display_Entities + LD A, $mem_bunny_status_tile + LD ($9d6f), A + LD A, $mem_loop_frame_timer INC A LD $mem_loop_frame_timer, A diff --git a/modes/dungeongeneration.gbasm b/modes/dungeongeneration.gbasm index b35cdc8..8c62081 100644 --- a/modes/dungeongeneration.gbasm +++ b/modes/dungeongeneration.gbasm @@ -53,7 +53,7 @@ New_Dungeon: LD HL, =Dungeon CALL =Load_Dungeon_Spawn_patterns - LD A, $06 + LD A, $entity_questgoalbunny_index LD $mem_loaded_special_entity_index, A CALL =Reload_EP_Cost diff --git a/scripts/generate-tiledata.py b/scripts/generate-tiledata.py index 153c272..e236fdd 100644 --- a/scripts/generate-tiledata.py +++ b/scripts/generate-tiledata.py @@ -1,10 +1,11 @@ import subprocess +import parse_sprite_png sprite_idx = 0x0 def get_sprite_png_parse_output(png, tallmode=False, sprite_1bpp_mode=False): global sprite_idx - result = str(subprocess.check_output(["python", "./scripts/parse_sprite_png.py", png] + (["--8x16"] if tallmode else []) + (["--1bpp"] if sprite_1bpp_mode else []))).split("\\n") + result = parse_sprite_png.parseSprite(png, sprite_8x16=tallmode, sprite_1bpp=sprite_1bpp_mode).split("\n") for r in result: if r.startswith(".DB"): print("\t{} ; 0x{:02x}".format(r, sprite_idx)) @@ -39,6 +40,10 @@ print("\n\t; Disabled Cursor") get_sprite_png_parse_output("./sprites/gui/disabled-cursor.png") print("\n\t; Floor") get_sprite_png_parse_output("./sprites/gui/floor.png") +print("\n\t; Freeze status") +get_sprite_png_parse_output("./sprites/gui/status-frozen.png") +print("\n\t; Poison status") +get_sprite_png_parse_output("./sprites/gui/status-poison.png") sprite_idx = 0x80 print("\nFont_Data:") @@ -124,3 +129,5 @@ print("\n\t; Sparkles") get_sprite_png_parse_output("./sprites/animations/sparkle1.png", tallmode=True) get_sprite_png_parse_output("./sprites/animations/sparkle2.png", tallmode=True) get_sprite_png_parse_output("./sprites/animations/ball.png", tallmode=True) +get_sprite_png_parse_output("./sprites/animations/bubble1.png", tallmode=True) +get_sprite_png_parse_output("./sprites/animations/bubble2.png", tallmode=True) diff --git a/scripts/parse_sprite_png.py b/scripts/parse_sprite_png.py index 730b487..304a283 100644 --- a/scripts/parse_sprite_png.py +++ b/scripts/parse_sprite_png.py @@ -2,82 +2,90 @@ from PIL import Image import numpy as np import sys -sprite_8x16 = "--8x16" in sys.argv - -sprite_8x8 = "--8x8" in sys.argv - -sprite_1bpp = "--1bpp" in sys.argv - -file = Image.open(sys.argv[1]).convert("RGB") - -px_array = np.asarray(file) - -def getpx(sprite_nb, x, y): - double_sprite_nb = int(sprite_nb / 4) - sprite_double_line = int(double_sprite_nb / (file.width / 16)) - sprite_double_column = int(double_sprite_nb % (file.width / 16)) - sprite_tile_y = 1 if sprite_nb & 0b10 else 0 - sprite_tile_x = 1 if sprite_nb & 0b01 else 0 - - if sprite_8x16 or file.width < 16: - sprite_tile_x ^= sprite_tile_y - sprite_tile_y ^= sprite_tile_x - sprite_tile_x ^= sprite_tile_y - - sprite_line = sprite_double_line * 2 + sprite_tile_y - sprite_column = sprite_double_column * 2 + sprite_tile_x - - if sprite_8x8: - sprite_line = int(sprite_nb / (file.width / 8)) - sprite_column = int(sprite_nb % (file.width / 8)) - - if file.width < 16: - sprite_line = sprite_column * 2 + sprite_line - sprite_column = 0 - - return [int(x) for x in px_array[int(sprite_line * 8 + y)][int(sprite_column * 8 + x)]] - +def parseSprite(file_name, sprite_8x16=False, sprite_8x8=False, sprite_1bpp=False): + file = Image.open(file_name).convert("RGB") + + px_array = np.asarray(file) + + def getpx(sprite_nb, x, y): + double_sprite_nb = int(sprite_nb / 4) + sprite_double_line = int(double_sprite_nb / (file.width / 16)) + sprite_double_column = int(double_sprite_nb % (file.width / 16)) + sprite_tile_y = 1 if sprite_nb & 0b10 else 0 + sprite_tile_x = 1 if sprite_nb & 0b01 else 0 + + if sprite_8x16 or file.width < 16: + sprite_tile_x ^= sprite_tile_y + sprite_tile_y ^= sprite_tile_x + sprite_tile_x ^= sprite_tile_y + + sprite_line = sprite_double_line * 2 + sprite_tile_y + sprite_column = sprite_double_column * 2 + sprite_tile_x + + if sprite_8x8: + sprite_line = int(sprite_nb / (file.width / 8)) + sprite_column = int(sprite_nb % (file.width / 8)) + + if file.width < 16: + sprite_line = sprite_column * 2 + sprite_line + sprite_column = 0 + + return [int(x) for x in px_array[int(sprite_line * 8 + y)][int(sprite_column * 8 + x)]] + + + if file.width % 8 != 0 or file.height % 8 != 0: + raise ValueError("Width and height must be multiples of 8px") + + sprite_nb = int((file.width / 8) * (file.height / 8)) + + result = "" + for nb in range(0, sprite_nb): + result1 = [0,0,0,0,0,0,0,0] + result2 = [0,0,0,0,0,0,0,0] + for y in range(0, 8): + for x in range(0, 8): + px = getpx(nb, x, y) + dw = px[0] - 0xe0 + px[1] - 0xf8 + px[2] - 0xd0 + dlg = px[0] - 0x88 + px[1] - 0xc0 + px[2] - 0x70 + ddg = px[0] - 0x34 + px[1] - 0x68 + px[2] - 0x56 + db = px[0] - 0x08 + px[1] - 0x18 + px[2] - 0x20 + + if min(abs(db), abs(ddg)) < min(abs(dlg), abs(dw)): + result2[y] |= 1 << (7-x) + if min(abs(db), abs(dlg)) < min(abs(ddg), abs(dw)): + result1[y] |= 1 << (7-x) + + if abs(db) < min(abs(dw), abs(dlg), abs(ddg)): + result += "#" + elif abs(ddg) < min(abs(dw), abs(dlg), abs(db)): + result += ";" + elif abs(dlg) < min(abs(dw), abs(ddg), abs(db)): + result += "." + else: + result += " " + result += "\n" + result += "\n\n" + for i in range(0, 8): + if sprite_1bpp: + if i == 0: + result += (".DB $%02x" % (result1[i])) + else: + result += (", $%02x" % (result1[i])) + else: + if i == 0: + result += (".DB $%02x, $%02x" % (result1[i], result2[i])) + else: + result += (", $%02x, $%02x" % (result1[i], result2[i])) + result += ("\n\n") + return result -if file.width % 8 != 0 or file.height % 8 != 0: - raise ValueError("Width and height must be multiples of 8px") +if __name__ == "__main__": + sprite_8x16 = "--8x16" in sys.argv + + sprite_8x8 = "--8x8" in sys.argv + + sprite_1bpp = "--1bpp" in sys.argv -sprite_nb = int((file.width / 8) * (file.height / 8)) + file_name = sys.argv[1] -for nb in range(0, sprite_nb): - result1 = [0,0,0,0,0,0,0,0] - result2 = [0,0,0,0,0,0,0,0] - for y in range(0, 8): - for x in range(0, 8): - px = getpx(nb, x, y) - dw = px[0] - 0xe0 + px[1] - 0xf8 + px[2] - 0xd0 - dlg = px[0] - 0x88 + px[1] - 0xc0 + px[2] - 0x70 - ddg = px[0] - 0x34 + px[1] - 0x68 + px[2] - 0x56 - db = px[0] - 0x08 + px[1] - 0x18 + px[2] - 0x20 - - if min(abs(db), abs(ddg)) < min(abs(dlg), abs(dw)): - result2[y] |= 1 << (7-x) - if min(abs(db), abs(dlg)) < min(abs(ddg), abs(dw)): - result1[y] |= 1 << (7-x) - - if abs(db) < min(abs(dw), abs(dlg), abs(ddg)): - print("#", end = '') - elif abs(ddg) < min(abs(dw), abs(dlg), abs(db)): - print(";", end = '') - elif abs(dlg) < min(abs(dw), abs(ddg), abs(db)): - print(".", end = '') - else: - print(" ", end = '') - print("\n", end = '') - print("\n") - for i in range(0, 8): - if sprite_1bpp: - if i == 0: - print(".DB $%02x" % (result1[i]), end='') - else: - print(", $%02x" % (result1[i]), end='') - else: - if i == 0: - print(".DB $%02x, $%02x" % (result1[i], result2[i]), end='') - else: - print(", $%02x, $%02x" % (result1[i], result2[i]), end='') - print("\n") + print(parseSprite(file_name, sprite_8x16=sprite_8x16, sprite_8x8=sprite_8x8, sprite_1bpp=sprite_1bpp)) diff --git a/sprites/animations/bubble1.png b/sprites/animations/bubble1.png Binary files differnew file mode 100644 index 0000000..ef73589 --- /dev/null +++ b/sprites/animations/bubble1.png diff --git a/sprites/animations/bubble2.png b/sprites/animations/bubble2.png Binary files differnew file mode 100644 index 0000000..b64dada --- /dev/null +++ b/sprites/animations/bubble2.png diff --git a/sprites/gui/status-frozen.png b/sprites/gui/status-frozen.png Binary files differnew file mode 100644 index 0000000..e3d1629 --- /dev/null +++ b/sprites/gui/status-frozen.png diff --git a/sprites/gui/status-poison.png b/sprites/gui/status-poison.png Binary files differnew file mode 100644 index 0000000..3ce44e0 --- /dev/null +++ b/sprites/gui/status-poison.png diff --git a/tiles.gbasm b/tiles.gbasm index eb04d60..94e7ca5 100644 --- a/tiles.gbasm +++ b/tiles.gbasm @@ -21,12 +21,12 @@ Load_Tile: LD HL, $8f00 LD DE, =Small_sprites - LD BC, $0050 + LD BC, $0070 CALL =memcpy LD HL, $8620 LD DE, =Animation_Sprites_Data - LD BC, $0060 + LD BC, $00a0 CALL =memcpy RET diff --git a/tileset.gbasm b/tileset.gbasm index 93fa7f3..18c1a74 100644 --- a/tileset.gbasm +++ b/tileset.gbasm @@ -120,6 +120,12 @@ Small_sprites: ; Floor .DB $10, $10, $38, $28, $7c, $44, $fe, $82, $fe, $ee, $38, $28, $38, $38, $00, $00 ; 0xf4 + ; Freeze status + .DB $00, $28, $54, $54, $38, $ba, $6c, $6c, $38, $ba, $54, $54, $00, $28, $00, $00 ; 0xf5 + + ; Poison status + .DB $70, $70, $b8, $88, $f8, $88, $f8, $88, $76, $76, $0b, $09, $0f, $09, $06, $06 ; 0xf6 + Font_Data: .DB $00, $00, $38, $3c, $44, $46, $44, $46, $44, $46, $44, $46, $38, $3c, $00, $00 ; 0x80 .DB $00, $00, $10, $18, $30, $38, $10, $18, $10, $18, $10, $18, $7c, $7e, $00, $00 ; 0x81 @@ -371,3 +377,7 @@ Animation_Sprites_Data: .DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ; 0x63 .DB $00, $00, $3c, $3c, $42, $7e, $42, $7e, $42, $7e, $42, $7e, $3c, $3c, $00, $00 ; 0x64 .DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ; 0x65 + .DB $00, $00, $38, $38, $44, $4c, $44, $5c, $44, $7c, $38, $38, $00, $00, $00, $00 ; 0x66 + .DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ; 0x67 + .DB $38, $38, $44, $7c, $82, $ce, $82, $de, $82, $fe, $44, $7c, $38, $38, $00, $00 ; 0x68 + .DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ; 0x69 |