![]() |
Routines |
Prev: 25737 | Up: Map | Next: 25853 |
This routine produces, on occasion, a new alien bullet. The value at _ALIENS_FIRE_RATE is used to throttle the firing rate. If it determines that a new alien bullet is due from one of the alien rows which still has aliens in it, the player ship's xpos is found and a bit of randomisation is used to focus the new bullet at somewhere around that xpos. This biases the new bullet towards attacking the player. Rather cleverly, the bullet collision detection routine is used to see if the bullet can appear from where the randomisation has positioned it. Instead of taking the player's bullet and seeing if it has collided with an alien, the new randomised alien bullet position is used to see if it could have emanated from an alien. If the routine says "yes, that's a collision" then the bullet could have come from that alien and it's allowed to fire. If not the bullet would appear from thin air so that's not allowed. Good idea that.
Used by the routine at move_alien_bullets.
|
||||||||||
generate_alien_bullets | 25749 | CALL update_cycler_values | Churn the "randomisation" | |||||||
25752 | LD A,(_CYCLER_1) | Pick up barrier cycler | ||||||||
25755 | LD B,A | Put in B | ||||||||
25756 | LD A,(_ALIENS_FIRE_RATE) | Pick up rate of fire. If it's zero the aliens aren't firing, so just return. | ||||||||
25759 | OR A | |||||||||
25760 | RET Z | |||||||||
25761 | CP B | Throttle alien firing. If rand is greater than rate of fire, return. The higher the the rate of fire value, the less likely we are to return, hence more bullets | ||||||||
25762 | RET C | |||||||||
25763 | LD A,(_LOWEST_ACTIVE_ALIEN_ROW) | Lowest row of aliens with some aliens in it | ||||||||
25766 | LD (_ALIENS_FIRING_LOOP),A | Loop that many times | ||||||||
25769 | LD A,(_PLAYER_XPOS) | Find middle of player ship cx | ||||||||
25772 | ADD A,7 | |||||||||
25774 | LD B,A | Into B | ||||||||
25775 | LD A,(_CYCLER_3) | Pick up a random value in the range 0 to 15 | ||||||||
25778 | AND 15 | |||||||||
25780 | ADD A,B | Add to ship xpos | ||||||||
25781 | LD (_ALIENS_FIRING_XPOS),A | Stash | ||||||||
25784 | LD A,(_CYCLER_2) | Another random number | ||||||||
25787 | CP 127 | Two to one to skip next bit | ||||||||
25789 | JR NC,ab_loop | |||||||||
Two to one, replace the previous xpos value with a randomised one
|
||||||||||
25791 | LD A,(_CYCLER_3) | Pick up random again | ||||||||
25794 | LD (_ALIENS_FIRING_XPOS),A | Stash, replacing previous | ||||||||
ab_loop | 25797 | LD A,(_ALIENS_FIRING_LOOP) | Fetch loop counter | |||||||
25800 | PUSH IX | IX must be passed in | ||||||||
25802 | CALL find_alien_row_data | Address of alien row 'A's data | ||||||||
25805 | LD A,(IX+1) | Row ypos | ||||||||
25808 | LD (_ALIENS_FIRING_YPOS),A | Save it here | ||||||||
25811 | LD A,(_ALIENS_FIRING_XPOS) | Pick firing xpos up again | ||||||||
25814 | CALL bullet_alien_coll_xaxis | Collision check - does it match an alien location? | ||||||||
25817 | POP IX | Restore IX | ||||||||
25819 | JR NZ,ab_new_alien_bullet | NZ means collision, which would mean the bullet emanated from an xpos where there's an alien. We're good to start a bullet there. | ||||||||
25821 | LD A,(_ALIENS_FIRING_LOOP) | If we didn't generate a bullet loop back and have another go. | ||||||||
25824 | DEC A | |||||||||
25825 | LD (_ALIENS_FIRING_LOOP),A | |||||||||
25828 | JP P,ab_loop | |||||||||
25831 | RET | |||||||||
If we arrive here we need to generate a new alien bullet
|
||||||||||
ab_new_alien_bullet | 25832 | LD A,(_ALIENS_FIRING_YPOS) | Fetch bullet cy back | |||||||
25835 | INC A | Add 2, then multiply by 8 That makes the ypos at the alien's feet | ||||||||
25836 | INC A | |||||||||
25837 | SLA A | |||||||||
25839 | SLA A | |||||||||
25841 | SLA A | |||||||||
25843 | LD (IX+1),A | That becomes the alien bullet's cy location | ||||||||
25846 | LD A,(_ALIENS_FIRING_XPOS) | Pick up new bullet xpos | ||||||||
25849 | LD (IX+0),A | That becomes the alien bullet's cx location | ||||||||
25852 | RET |
Prev: 25737 | Up: Map | Next: 25853 |