Prev: DA7A Up: Map Next: DB68
DAB7: Throw Item
Used by the routine at UpdatePlayerLegs.
Throws the last item that was picked up, if the fire button has been pressed and the previous throw has finished. An item that belongs to a monster (items 01 to 04) is dropped into the object for the monster. Any other item becomes a shot, in one of the two objects from ObjectTable_Shots; if both are busy, the one that was not used last is turned into a burst.
Input
E Controls
ThrowItem DAB7 LD HL,$BBC8 Fetch the time left before another item can be thrown.
DABA LD A,(HL)
DABB AND A
DABC JR Z,ThrowItem_Ready
DABE DEC (HL) Count down the time and return if it has not run out.
DABF RET
ThrowItem_Ready DAC0 BIT 3,E Return if the fire button has not been pressed.
DAC2 RET Z
DAC3 LD HL,$BC0D Point HL at the last place in the inventory, and set a counter of eleven places.
DAC6 LD B,$0B
ThrowItem_Find DAC8 LD A,(HL) Jump to ThrowItem_Found if there is an item in this place.
DAC9 AND A
DACA JR NZ,ThrowItem_Found
DACC DEC HL Move to the place before it and loop back until all of the places have been checked.
DACD DJNZ ThrowItem_Find
DACF RET Return.
An item has been found. Monster items are dropped; any other item becomes a shot.
ThrowItem_Found DAD0 CP $05 Jump to ThrowItem_Drop if the item is one of the monster items (01 to 04).
DAD2 JR C,ThrowItem_Drop
DAD4 LD IY,$BCAE Point IY at the first shot, and set the size of an object to 10 bytes.
DAD8 LD DE,$0010
DADB LD C,$02 Set a counter of two shots.
ThrowItem_Shot DADD LD A,(IY+$00) Jump to ThrowItem_Free if this shot is free.
DAE0 AND A
DAE1 JR Z,ThrowItem_Free
DAE3 ADD IY,DE Move on to the next shot and loop back until both have been checked.
DAE5 DEC C
DAE6 JR NZ,ThrowItem_Shot
DAE8 LD HL,$BCAE Choose the shot that was not used last.
DAEB LD A,($BBF4) Fetch which shot was used last (00 or 10).
DAEE AND $10
DAF0 LD C,A
DAF1 LD B,$00 Set the offset of the shot.
DAF3 ADD HL,BC Point at the shot.
DAF4 LD A,(HL) Fetch the type of the shot, and subtract 50.
DAF5 SUB $50
DAF7 CP $10
DAF9 RET NC Return if the shot has not got a type of 50 to 5F.
DAFA LD (HL),$0C Turn the shot into a burst.
DAFC RET Return.
This shot is free, so the item is copied from the player into it.
ThrowItem_Free DAFD LD A,($BBF4) Change the shot that was used last.
DB00 XOR $10
DB02 LD ($BBF4),A
DB05 PUSH BC Keep the counter and the place in the inventory.
DB06 PUSH HL
DB07 LD A,(HL) Fetch the item and remove it from the inventory.
DB08 LD (HL),$00
DB0A LD HL,$BC8E Use the player as the source of the copy.
DB0D PUSH IY Use the shot as the destination of the copy (using the stack).
DB0F POP DE
DB10 LD BC,$0010 Copy the player into the shot.
DB13 LDIR
DB15 ADD A,A Make the type of the shot from the item.
DB16 ADD A,A
DB17 ADD A,$3C
ThrowItem_Set DB19 LD (IY+$00),A Set the type of the object.
DB1C LD (IY+$05),$0C Set the speed of the object to 0C.
DB20 LD A,$10 Set the width and the depth of the object to 10.
DB22 LD (IY+$08),A
DB25 LD (IY+$09),A
DB28 LD (IY+$0C),$F8 Set the X offset of the sprite.
DB2C LD (IY+$0D),$04 Set the Y offset of the sprite.
DB30 LD A,$02 Set the time before the next throw to two frames.
DB32 LD ($BBC8),A
DB35 POP HL Restore the inventory place and the counter from the stack.
DB36 POP BC
DB37 LD A,B Work out the number of the place counted from the start of the inventory.
DB38 NEG
DB3A ADD A,$0C
DB3C LD B,A
DB3D CALL DrawInventoryItem Redraw the item in the inventory tube.
DB40 JP PlaySweepSound Jump to PlaySweepSound.
The item is one of the monster items, which is dropped into the object for the monster.
ThrowItem_Drop DB43 PUSH BC Keep the counter, the place in the inventory and the item.
DB44 PUSH HL
DB45 PUSH AF
DB46 LD (HL),$00 Remove the item from the inventory.
DB48 NEG Work out the offset of the object from the number of the item.
DB4A ADD A,$04
DB4C ADD A,A
DB4D ADD A,A
DB4E ADD A,A
DB4F ADD A,A
DB50 LD HL,$BD1E Find the object for the monster.
DB53 CALL AddAToHL
DB56 PUSH HL Point IY at the object, and keep the address of the object.
DB57 PUSH HL
DB58 POP IY
DB5A POP DE
DB5B LD HL,$BC8E Copy the player into the object.
DB5E LD BC,$0010
DB61 LDIR
DB63 POP AF Make the type of the object from the item, and jump to ThrowItem_Set.
DB64 ADD A,$07
DB66 JR ThrowItem_Set
Prev: DA7A Up: Map Next: DB68