![]() |
Routines |
| Prev: 49437 | Up: Map | Next: 49597 |
|
Used by the routine at HandlePlayerLegs.
Fires a projectile in the direction that the player is facing, if the fire key is pressed and it was not already being held down from before. There are two object records that are used for projectiles, so nothing is done if both are in use.
The projectile is a copy of the player that is changed into a projectile and moved on by twice its speed along the way that the player is facing. It is thrown away at once if it starts outside the room.
|
||||||||
| FireProjectile | 49446 | LD HL,42927 | Start at the first of the two projectile object records, ObjectsTable_Projectiles. | |||||
| 49449 | LD A,(42807) | Fetch the controls from ControlsPressed. | ||||||
| 49452 | AND %01000000 | Keep only the fire bit. | ||||||
| 49454 | JR NZ,FireProjectile_Pressed | Jump to FireProjectile_Pressed if the fire key is being pressed. | ||||||
| 49456 | XOR A | Clear the flag in FireKeyHeldFlag, to say that the key has been released. | ||||||
| 49457 | LD (42819),A | |||||||
| 49460 | RET | Return. | ||||||
| FireProjectile_Pressed | 49461 | LD A,(42819) | Fetch the flag from FireKeyHeldFlag. | |||||
| 49464 | AND A | Return if the key was already being held down. | ||||||
| 49465 | RET NZ | |||||||
| 49466 | INC A | Set the flag in FireKeyHeldFlag, to say that the key is being held down. | ||||||
| 49467 | LD (42819),A | |||||||
| 49470 | LD BC,32 | Set the size of an object record in BC. | ||||||
| 49473 | LD A,(HL) | Jump to FireProjectile_Create if the first record is free. | ||||||
| 49474 | AND A | |||||||
| 49475 | JR Z,FireProjectile_Create | |||||||
| 49477 | ADD HL,BC | Move on to the second record. | ||||||
| 49478 | LD A,(HL) | Return if that is not free either. | ||||||
| 49479 | AND A | |||||||
| 49480 | RET NZ | |||||||
|
Copy the player to the free record, then change the copy into a projectile.
|
||||||||
| FireProjectile_Create | 49481 | EX DE,HL | Move the address of the free record to DE. | |||||
| 49482 | PUSH DE | Take the free record, using the stack. | ||||||
| 49483 | POP IY | |||||||
| 49485 | PUSH IX | Take the player, using the stack. | ||||||
| 49487 | POP HL | |||||||
| 49488 | LDIR | Copy the player to the projectile. | ||||||
| 49490 | LD (IY+0),150 | Set the type of the projectile to 150, which is the first of its sprites. | ||||||
| 49494 | CALL GetFacingDirection | Call GetFacingDirection to find out which way the player is facing. | ||||||
| 49497 | LD L,A | Set HL to the number of the direction. | ||||||
| 49498 | LD H,0 | |||||||
| 49500 | LD DE,49597 | Take the table of speeds of projectiles, ProjectileSpeeds. | ||||||
| 49503 | ADD HL,HL | Find the entry for the direction, which is two bytes for each direction. | ||||||
| 49504 | ADD HL,DE | |||||||
| 49505 | LD A,(HL) | Fetch the speed along x, and set it as the x speed of the projectile. | ||||||
| 49506 | LD (IY+20),A | |||||||
| 49509 | ADD A,A | Double it, and stash it in E. | ||||||
| 49510 | LD E,A | |||||||
| 49511 | INC HL | Move on to the speed along y. | ||||||
| 49512 | LD A,(HL) | Fetch the speed along y, and set it as the y speed of the projectile. | ||||||
| 49513 | LD (IY+21),A | |||||||
| 49516 | ADD A,A | Double it. | ||||||
| 49517 | ADD A,(IY+2) | Add it to the y position of the projectile. | ||||||
| 49520 | LD (IY+2),A | |||||||
| 49523 | LD A,E | Add the doubled speed along x to the x position of the projectile. | ||||||
| 49524 | ADD A,(IY+1) | |||||||
| 49527 | LD (IY+1),A | |||||||
| 49530 | LD A,(IY+3) | Raise the projectile by 4. | ||||||
| 49533 | ADD A,4 | |||||||
| 49535 | LD (IY+3),A | |||||||
| 49538 | LD (IY+7),20 | Set the flags of the projectile, which make it pushable and mark it to be drawn. | ||||||
| 49542 | LD (IY+12),0 | Clear the collision flags of the projectile. | ||||||
| 49546 | LD (IY+6),8 | Set the size of the projectile along z to 8. | ||||||
|
Make sure that the projectile is inside the room.
|
||||||||
| 49550 | LD HL,(42781) | Fetch the limits of the room from RoomSizeX. | ||||||
| 49553 | LD A,L | Take away the half size along x from the limit along x. | ||||||
| 49554 | SUB (IY+4) | |||||||
| 49557 | LD L,A | |||||||
| 49558 | LD A,H | Take away the half size along y from the limit along y. | ||||||
| 49559 | SUB (IY+5) | |||||||
| 49562 | LD H,A | |||||||
| 49563 | LD A,(IY+1) | Fetch the x position of the projectile. | ||||||
| 49566 | SUB 128 | Take away the middle of the room, 128, and jump to FireProjectile_TestX if the distance from the middle is not negative. | ||||||
| 49568 | JP P,FireProjectile_TestX | |||||||
| 49571 | NEG | Make the distance positive. | ||||||
| FireProjectile_TestX | 49573 | CP L | Jump to FireProjectile_Cancel to give up if the distance is not less than the limit along x. | |||||
| 49574 | JR NC,FireProjectile_Cancel | |||||||
| 49576 | LD A,(IY+2) | Fetch the y position of the projectile. | ||||||
| 49579 | SUB 128 | Take away the middle of the room, 128, and jump to FireProjectile_TestY if the distance from the middle is not negative. | ||||||
| 49581 | JP P,FireProjectile_TestY | |||||||
| 49584 | NEG | Make the distance positive. | ||||||
| FireProjectile_TestY | 49586 | CP H | Jump to FireProjectile_Cancel to give up if the distance is not less than the limit along y. | |||||
| 49587 | JR NC,FireProjectile_Cancel | |||||||
| 49589 | JP PlayProjectileSound | Jump to PlayProjectileSound. | ||||||
| FireProjectile_Cancel | 49592 | LD (IY+0),0 | Free the record, as the projectile would be outside the room. | |||||
| 49596 | RET | Return. | ||||||
| Prev: 49437 | Up: Map | Next: 49597 |