Prev: AFD7 Up: Map Next: B09C
AFE9: Build the ship's sprite from its add-ons
Used by the routines at draw_ship_image and start_landscape.
The ship's sprite is put together in a buffer of 50 rows of 6 bytes (300 bytes) at ship_picture, drawn from the bottom row up: the bare ship (84 bytes from bare_ship, 14 rows) goes in rows 26-39, the top of the picture without add-on 9, and every add-on fitted -- the nine bytes from addon_slots, add-on n's slot holding n or 0 -- is masked and drawn in at its own place (fit_addon), each hanging below the ship. The sprite's height in rows (ship_height) is the most any add-on needs, at least 14, and drawing starts that many rows below row 40 (ship_graphic). Add-on 9 sits on top of the ship, rows 36-50, and adds 11 rows to the height after the start is worked out, so the picture then ends at row 50 -- one row past the buffer, in spare_after_ship. Called from draw_ship when an add-on is fitted, and from start_landscape.
The ship's top stays where it was on the screen and its bottom line (ship_screen_y) moves down by the rows added, and the ship's world position (its record at ship_record) moves with it, so the ship does not jump; ship_line, the line its shots come out of, is 8 below its top.
The add-ons' effects set here: 4 doubles the top speed across (top_speed 4 instead of 2); 5 doubles the top climb (top_climb); 9 adds 11 rows to the height, into which the tail of load_ore draws the ore collected (ore rows); a rocket part being carried (rocket_part_carried not $FF) is hung under the ship again by toggle_carried_part's second entry. Add-on 2 always comes with add-on 1: its slot is set to twice add-on 1's. All of it ran in the build's every-add-on session; with every add-on fitted the picture is 51 rows, rows 0-50, its top row in spare_after_ship (simulated for the Graphics page).
build_ship_sprite AFE9 LD A,(addon_slots) add-on 2 comes and goes with add-on 1
AFEC ADD A,A
AFED LD (addon_two),A
AFF0 LD A,$02 the top speeds across and up: 2 a pass
AFF2 LD (top_speed),A
AFF5 LD (top_climb),A
AFF8 LD BC,$0054 the bare ship into the last 14 rows of the buffer
AFFB LD DE,$F755
AFFE LD HL,bare_ship
B001 LDIR
B003 LD IX,addon_slots the nine add-on slots; 14 rows so far
B007 LD A,$0E
B009 LD (ship_height),A
B00C LD B,$09
build_ship_sprite_0 B00E PUSH BC draw in each one fitted (fit_addon), which may make the sprite taller
B00F LD A,(IX+$00)
B012 AND A
B013 CALL NZ,fit_addon
B016 INC IX
B018 POP BC
B019 DJNZ build_ship_sprite_0
B01B LD A,(ship_height) drawing starts at row 40 less the height: ship_graphic = ship_picture + 6 * (40 - height)
B01E LD B,A
B01F LD A,$28
B021 SUB B
B022 ADD A,A
B023 LD E,A
B024 ADD A,A
B025 ADD A,E
B026 LD E,A
B027 LD D,$00
B029 LD HL,ship_picture
B02C ADD HL,DE
B02D LD (ship_graphic),HL
B030 LD A,(ship_screen_y) the bottom line on screen: $6F plus the rows above 14, to the bottom of its cell
B033 LD B,A
B034 LD A,(ship_height)
B037 SUB $0E
B039 ADD A,$6F
B03B OR $07
B03D LD (ship_screen_y),A
B040 SUB B the change, as the y speed of the ship's record: move it that far
B041 LD (ship_dy),A
B044 LD IX,ship_record
B048 CALL move_down
B04B LD (IX+$04),H
B04E LD (IX+$05),L
B051 CALL ship_speed_from_scroll and clear its speed again (ship_speed_from_scroll)
B054 LD A,(ship_height) the line the shots come out of: 9 below the line above the sprite
B057 LD B,A
B058 LD A,(IX+$1E)
B05B SUB B
B05C ADD A,$09
B05E LD (ship_line),A
B061 LD A,(addon_four) add-on 4: top speed across 4
B064 AND A
B065 JR Z,build_ship_sprite_1
B067 LD A,$04
B069 LD (top_speed),A
build_ship_sprite_1 B06C LD A,(addon_five) add-on 5: top climb 4
B06F AND A
B070 JR Z,build_ship_sprite_2
B072 LD A,$04
B074 LD (top_climb),A
build_ship_sprite_2 B077 LD A,(rocket_part_carried) carrying a rocket part: hang it under the ship again
B07A INC A
B07B JR Z,build_ship_sprite_3
B07D DEC A
B07E OR $C0
B080 LD (part_being_fitted),A
B083 CALL toggle_carried_part_3
B086 XOR A
B087 LD (part_being_fitted),A
build_ship_sprite_3 B08A LD A,(addon_nine) add-on 9: 11 more rows, up to row 50 (spare_after_ship); then the rows of the tail of load_ore
B08D AND A
B08E JP Z,load_ore_3
B091 LD A,(ship_height)
B094 ADD A,$0B
B096 LD (ship_height),A
B099 JP load_ore_3
Prev: AFD7 Up: Map Next: B09C