castleraider
changeset 327:af97e2fac44b reversible
Added code to create reversed versions of sprites. This allows the player's
character sprites to be generated from left-facing sprites. However, the code
to do this is quite long and it is possibly more efficient to just include
all the data in the SPRITES file.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sun Oct 05 02:15:45 2014 +0200 |
| parents | 061d634f7bc5 |
| children | |
| files | build.py loader.oph |
| diffstat | 2 files changed, 97 insertions(+), 12 deletions(-) [+] |
line diff
1.1 --- a/build.py Sun Oct 05 02:11:53 2014 +0200 1.2 +++ b/build.py Sun Oct 05 02:15:45 2014 +0200 1.3 @@ -90,9 +90,7 @@ 1.4 tiles = map(lambda tile: makelevels.tile_ref[tile], makelevels.tile_order) 1.5 1.6 char_sprites = ["images/g-left1.png", "images/g-left2.png", 1.7 - "images/g-right1.png", "images/g-right2.png", 1.8 - "images/b-left1.png", "images/b-left2.png", 1.9 - "images/b-right1.png", "images/b-right2.png"] 1.10 + "images/b-left1.png", "images/b-left2.png"] 1.11 1.12 monster_sprites = ["images/bat1.png", "images/bat2.png", 1.13 "images/spider1.png", "images/spider2.png"] 1.14 @@ -423,8 +421,10 @@ 1.15 makesprites.read_sprites(life_sprites, life_sprites_address) 1.16 char_data += life_sprites_data 1.17 1.18 - player_data, player_sprite_offsets = \ 1.19 + player_data, player_sprite_file_offsets = \ 1.20 makesprites.read_sprites(char_sprites, char_area_address + len(char_data)) 1.21 + player_sprite_offsets = player_sprite_file_offsets + \ 1.22 + map(lambda x: x + len(player_data), player_sprite_file_offsets) 1.23 char_data += player_data 1.24 1.25 panel_address = 0x3000
2.1 --- a/loader.oph Sun Oct 05 02:11:53 2014 +0200 2.2 +++ b/loader.oph Sun Oct 05 02:15:45 2014 +0200 2.3 @@ -45,7 +45,11 @@ 2.4 ldy #>sprites_block 2.5 jsr $ffdd 2.6 2.7 + jsr copy_alt_sprites 2.8 + jsr reverse_character 2.9 + 2.10 ; Clear the screen. 2.11 + 2.12 lda #12 2.13 jsr $ffee 2.14 2.15 @@ -380,9 +384,27 @@ 2.16 clc 2.17 jmp plot8x24_y0 2.18 2.19 +copy_alt_sprites: 2.20 + 2.21 + ; The definitions passed to the loader and main code provide addresses for 2.22 + ; the sprites in this order: <left> <right> <left alt> <right alt> 2.23 + ; The data has this order: <left> <left alt> 2.24 + ; We copy the alternative set out of the way so that we can create a right 2.25 + ; facing set of sprites. 2.26 + ldx #95 2.27 + copy_alt_sprites_loop: 2.28 + 2.29 + lda player_right1,x 2.30 + sta player_left_alt1,x 2.31 + dex 2.32 + bpl copy_alt_sprites_loop 2.33 + 2.34 + clc 2.35 + rts 2.36 + 2.37 switch_characters: 2.38 2.39 - ; Switch the left and right sprites. 2.40 + ; Switch the left sprites. 2.41 ldx #95 2.42 switch_characters_left_loop: 2.43 2.44 @@ -391,19 +413,82 @@ 2.45 sta player_left1,x 2.46 tya 2.47 sta player_left_alt1,x 2.48 - 2.49 - ldy player_right1,x 2.50 - lda player_right_alt1,x 2.51 - sta player_right1,x 2.52 - tya 2.53 - sta player_right_alt1,x 2.54 - 2.55 dex 2.56 bpl switch_characters_left_loop 2.57 2.58 +reverse_character: 2.59 + 2.60 + lda #<reverse_lookup 2.61 + sta $70 2.62 + lda #>reverse_lookup 2.63 + sta $71 2.64 + 2.65 + ldx #95 2.66 + reverse_character_loop1: 2.67 + 2.68 + lda player_left1,x 2.69 + pha 2.70 + and #$0f ; Select the first set of bits. 2.71 + tay 2.72 + lda ($70),y ; Look up the reversed value. 2.73 + sta $74 2.74 + 2.75 + pla 2.76 + and #$f0 ; Select the second set of bits. 2.77 + lsr 2.78 + lsr 2.79 + lsr 2.80 + lsr 2.81 + tay 2.82 + lda ($70),y ; Look up the reversed value. 2.83 + asl 2.84 + asl 2.85 + asl 2.86 + asl 2.87 + ora $74 2.88 + sta player_right1,x 2.89 + 2.90 + dex 2.91 + bpl reverse_character_loop1 2.92 + 2.93 + lda #<player_right1 2.94 + sta $70 2.95 + adc #8 2.96 + sta $72 2.97 + lda #>player_right1 2.98 + sta $71 2.99 + adc #0 2.100 + sta $73 2.101 + clc 2.102 + 2.103 + ldy #0 2.104 + reverse_character_loop2: 2.105 + 2.106 + ldx #7 2.107 + reverse_character_loop2a: 2.108 + 2.109 + lda ($70),y 2.110 + pha 2.111 + lda ($72),y 2.112 + sta ($70),y 2.113 + pla 2.114 + sta ($72),y 2.115 + 2.116 + iny 2.117 + dex 2.118 + bpl reverse_character_loop2a 2.119 + 2.120 + tya 2.121 + adc #8 2.122 + tay 2.123 + cpy #96 2.124 + bne reverse_character_loop2 2.125 + 2.126 clc 2.127 rts 2.128 2.129 +reverse_lookup: .byte $0, $8, $4, $c, $2, $a, $6, $e, $1, $9, $5, $d, $3, $b, $7, $f 2.130 + 2.131 tiles_block: .byte <tiles_file_name, >tiles_file_name 2.132 .byte sprite_area_low, sprite_area_high, 0, 0 2.133 .byte sprite_area_low, sprite_area_high, 0, 0
