![]() |
Routines |
Prev: 25282 | Up: Map | Next: 25592 |
First, is there a spaceship in play? If not we decide whether we should create one based on the "random" number generator. If yes, choose whether it's going left to right or right to left. If no, we're done.
Otherwise, yes, there's a spaceship in play. In that case, every other game cycle the spaceship is moved one pixel and it's checked for a player bullet collision. Every other other cycle we make its noise and exit.
Used by the routine at start.
|
||||
spaceship_handler | 25442 | LD A,(_SPACESHIP_DIRECTION) | Is there a spaceship in play? Jump forward if there is | |
25445 | OR A | |||
25446 | JR NZ,spaceship_in_play | |||
25448 | LD A,(_CYCLER_3) | Introduce a new spaceship if the cycling value is in the range 65280 to 65305. | ||
25451 | CP 255 | |||
25453 | RET NZ | |||
25454 | LD A,(_CYCLER_4) | |||
25457 | CP 25 | |||
25459 | RET NC | |||
25460 | LD A,(_CYCLER_4) | OK, new spaceship required. Which direction should it go? Pick up low bit of random number | ||
25463 | BIT 0,A | |||
25465 | JR Z,new_spaceship_leftwards | |||
25467 | LD A,1 | New spaceship going left to right. | ||
25469 | LD (_SPACESHIP_DIRECTION),A | |||
25472 | XOR A | New spaceship starts at x=0 | ||
25473 | LD (_SPACESHIP_XPOS),A | |||
25476 | RET | |||
new_spaceship_leftwards | 25477 | LD A,255 | New spaceship going right to left. | |
25479 | LD (_SPACESHIP_DIRECTION),A | |||
25482 | LD A,233 | New spaceship starts at x=255 minus the width of the graphic | ||
25484 | LD (_SPACESHIP_XPOS),A | |||
25487 | RET | |||
If we get here there's a spaceship in play. Either move it or make its sound, alternating each game cycle.
|
||||
spaceship_in_play | 25488 | LD A,(_SPACESHIP_SOUND_PULSE) | Two's comp this, so every other time we play the spaceship noise. That routine returns, so that's the end of this code. Every other other time we drop through and move the spaceship | |
25491 | NEG | |||
25493 | LD (_SPACESHIP_SOUND_PULSE),A | |||
25496 | JP P,spaceship_noise | |||
25499 | LD IX,_SPACESHIP_XPOS | IX points to spaceship's xpos | ||
25503 | LD A,(_SPACESHIP_DIRECTION) | Which way is it going? Jump if it's going left to right | ||
25506 | CP 1 | |||
25508 | JR Z,spaceship_l_to_r | |||
25510 | LD HL,_GFX_SPACESHIP_R_TO_L | Spaceship right to left sprite data | ||
25513 | DEC (IX+0) | Move xpos one pixel leftwards | ||
25516 | XOR A | Has it reached left side of the screen? If not redraw it | ||
25517 | CP (IX+0) | |||
25520 | JR NZ,redraw_spaceship | |||
25522 | JR clear_spaceship | Otherwise clear it off | ||
spaceship_l_to_r | 25524 | LD HL,_GFX_SPACESHIP_L_TO_R | Spaceship left to right sprite data | |
25527 | INC (IX+0) | Move xpos one pixel rightwards | ||
25530 | LD A,234 | Has it reached right side of the screen? If not redraw it. | ||
25532 | CP (IX+0) | |||
25535 | JR NZ,redraw_spaceship | Otherwise drop through to clear it | ||
Clear the spaceship from the screen and clear the flag saying there is one.
This entry point is used by the routines at hit_spaceship and alien_hit.
|
||||
clear_spaceship | 25537 | XOR A | Set direction flag saying no spaceship | |
25538 | LD (_SPACESHIP_DIRECTION),A | |||
25541 | LD DE,16416 | Jump to clear spaceship screen row, returns out of this code | ||
25544 | JP clear_char_row | |||
Redraw the spaceship. Jumped to with the correct spaceship sprite data pointed to by HL.
|
||||
redraw_spaceship | 25547 | LD A,1 | Mode clear | |
25549 | CALL sprite_draw_or_clear | Clear spaceship sprite | ||
25552 | XOR A | Mode set | ||
25553 | CALL sprite_draw_or_clear | Draw spaceship sprite | ||
25556 | LD A,(_PLAYER_BULLET_IN_FLIGHT) | All done if no bullet in flight, there can't have been a collision | ||
25559 | OR A | |||
25560 | RET Z | |||
Check if player bullet has hit the spaceship. This checks the bullet location against the spaceship location. If the bullet location is greater than the spaceship's left side location, and also less than the spaceship's right side location, it's a hit.
|
||||
spaceship_bullet_check | 25561 | LD IX,_PLAYER_BULLET_XPOS | Pick player bullet ypos from player bullet data | |
25565 | LD A,(IX+1) | |||
25568 | CP 16 | Has it reached the spaceship's row (in px)? Can't be a collision if it hasn't | ||
25570 | RET NC | |||
25571 | LD A,(_SPACESHIP_XPOS) | Compare bullet xpos with spaceship xpos. Bullet has to be to the right of spaceship for there to be a collision | ||
25574 | CP (IX+0) | |||
25577 | RET NC | |||
25578 | ADD A,23 | A now contains xpos of right side of spaceship | ||
25580 | CP (IX+0) | Bullet location must be to the left side of that point for the spaceship to be hit. If it isn't the bullet isn't in the spaceship's width so we return. | ||
25583 | RET C | |||
25584 | CALL hit_spaceship | Otherwise it's a hit. Deal with it and set the spaceship flag to "no spaceship" | ||
25587 | XOR A | |||
25588 | LD (_SPACESHIP_DIRECTION),A | |||
25591 | RET |
Prev: 25282 | Up: Map | Next: 25592 |