Prev: F2F7 Up: Map Next: F4E6
F309: Update an object by its state: guards, the troll, the wraith, the floating things and the knight
Used by the routine at CHE3D.
The author's I6: the rest of the dispatch that CHE3D (CHE3D) begins, which tests the low nibble of the object's state (+14) in turn and comes here for state 6 and up. Each case chooses a direction in C and a sprite in HL, and leaves by one of three doors into the movement code: ANIM (in KNIGHT_CONTROLS), which picks a frame from a run of them, SET_SPRITE_AND_MOVE (ANIMATE_AND_MOVE), which shows HL as it is, or MOVE_IN_DIRECTION (ANIMATE_AND_MOVE), which leaves the sprite alone. From there the object is moved in direction C, collides, lands, and is redrawn.
The states handled here, with the object types whose templates (TEMPLATES) start them in each: 6 and 10 (types 26 and 33): a guard. Within 30 of the knight along the floor it chases him (STEER); further off, a state-6 guard walks to and fro along x and a state-10 one along y, turning back at whatever stops it. Its frames depend on the way it walks: SPRITE9F3C, SPRITEA110, SPRITEA554 or SPRITEA728, three each. The guards of state 9 (type 27), which materialise first (CHE3D), use the same frames and always chase. 7 (type 13): the troll, which chases, turning its frames (SPRITE8BB8 facing the viewer, SPRITE8E64 facing away). 11 (type 45): a wraith, which chases and has one frame each way, SPRITE5E88 and SPRITE5F08. 12 (type 51): hangs in the air where it is and flickers through three small frames from SPRITE5B00. 13 (type 52): wanders, diagonally if it has no way of its own yet, and turns back off whatever it meets; frames from SPRITE5B30. 14 (type 40): hangs where it is and flickers through three frames from SPRITE6104. 15 (type 56, one in room 61): stands still until the thing of kind 11 lies in the room, when it takes the wraith's frames and state and chases the knight from then on (measured: it becomes state 11 for good). The door out of room 61 waits for the same thing (BUMPED). 8: the knight -- KNIGHT_UPDATE, below. Any other (1 or 2, which no object that is updated has): moves the way +13 says, with no sprite change.
The knight (the author's I8, KNIGHT_UPDATE) comes here on every pass on which he is not in the air: in the air, CHE3D carries him on in the direction +18 holds. First, if he has just landed from a long fall, it costs him LIFE: IY+$14 counts the passes he fell for, and each pass over 20 -- each two units over 40 -- takes a point (measured: a fall of 50 cost 5, of 60 cost 10, of 40 nothing). Then the keys. Any key but the number keys goes to the action keys: X to V pick up (PICK_UP), CAPS SHIFT and Z drop, and the rest walk, jump and fight (KNIGHT_CONTROLS). With no key, the Kempston joystick (when 9 has turned it on) goes to KNIGHT_CONTROLS too. With neither, he stands: facing the viewer or away, with now and then a fidget of 14 passes (bit 3 of IY+$17) after a random wait of 128 to 255.
The drop (Krumlinde's MainLoop_DropItemCheck, at the CAPS SHIFT row test) takes the thing in the place in use and puts it down just beside him on the side he faces: past his own width or depth when he faces the way the axis grows, past the thing's own when he faces back. Its top is set level with his, so it starts in the air. If the thing's box there meets anything (FIND_OBSTACLE), BLOCKED (message 1, IY+$07) and nothing changes. Otherwise the place is emptied, the thing moved there, its weight -- its +16 less 16, and never below nought -- taken off CARRIED_WEIGHT (IY+$12), its carried flag cleared, and it is given one pass going up (state bit 4 with +13 = $12) after which it falls to the floor like anything else. The object table is told it is in this room now (SET_THING_ROOM) and the panel's box for the place is emptied (CLEAR_THING_BOX). With 46 or more object records in use the drop key is ignored (not worked out why).
Input
A The state's low nibble
E The whole state, +14
C Its direction, +13 (KNIGHT_CONTROLS has the bits)
HL Its sprite, +4 and +5
IX Its record; the working copy of its +0 to +18 is at IY+$64 to IY+$76
CREATURE_UPDATE F309 CP $06 States 6 and 10: a guard
F30B JR Z,GUARD_MOVES
F30D CP $0A
F30F JR NZ,CREATURE_UPDATE_4
GUARD_MOVES F311 CALL STEER The author's I601. Keep course, or aim at the knight (D is how far he is, when it aimed)
F314 LD A,D Not aimed this pass, or the knight within 30: go the way STEER said
F315 AND A
F316 JR Z,GUARD_FRAMES
F318 CP $1E
F31A JR C,GUARD_FRAMES
F31C LD (IX+OBJ_COUNT),$01 Far off: look again next pass
F320 LD A,E A state-6 guard walks along x
F321 AND $0F
F323 CP $06
F325 LD A,(WORK_DIRECTION)
F328 JR Z,CREATURE_UPDATE_0
F32A AND $C3 State 10: keep its y direction (and the low bits); with none, go up y ($40) and turn back when stopped (bit 0)
F32C LD C,A
F32D AND $C0
F32F JR NZ,GUARD_FRAMES
F331 LD C,$41
F333 JR GUARD_FRAMES
CREATURE_UPDATE_0 F335 AND $0F State 6 (the author's I602): keep its x direction; with none, go down x ($04) and turn back when stopped
F337 LD C,A
F338 JR NZ,GUARD_FRAMES
F33A LD C,$05
This entry point is used by the routine at CHE3D.
GUARD_FRAMES F33C LD HL,SPRITE9F3C The author's I600, which the materialised guards of state 9 use too (CHE3D). Frames by the way it goes: down y, or standing, SPRITE9F3C
F33F BIT 3,C Up x: SPRITEA110 (the author's I60 is the next test)
F341 JR Z,CREATURE_UPDATE_1
F343 LD HL,SPRITEA110
CREATURE_UPDATE_1 F346 BIT 2,C Down x: SPRITEA554 (I61 is the next)
F348 JR Z,CREATURE_UPDATE_2
F34A LD HL,SPRITEA554
CREATURE_UPDATE_2 F34D BIT 6,C Up y: SPRITEA728 (a later test wins over an earlier one)
F34F JR Z,CREATURE_UPDATE_3
F351 LD HL,SPRITEA728
CREATURE_UPDATE_3 F354 LD DE,$009C The author's I62: frames of 24 by 26, 156 bytes apart; step through them
F357 JP ANIM
CREATURE_UPDATE_4 F35A CP $0B The author's I11. State 11: a wraith
F35C JR NZ,CREATURE_UPDATE_6
WRAITH_MOVES F35E CALL STEER The author's I1110 (state 15 comes here too). Keep course, or aim at the knight
F361 CALL MIWRAI Turn its two frames (SPRITE5E88) to face the way it goes; HL is the first
F364 BIT 6,E Facing away (bit 6 of the state clear): the second frame, 128 bytes on (SPRITE5F08)
F366 JR NZ,CREATURE_UPDATE_5
F368 LD DE,$0080
F36B ADD HL,DE
CREATURE_UPDATE_5 F36C JP SET_SPRITE_AND_MOVE Show that frame (no animation) and move
CREATURE_UPDATE_6 F36F CP $0C The author's I12. State 12: the small floating thing
F371 JR NZ,CREATURE_UPDATE_9
F373 LD DE,$0010 Frames of 8 by 8, 16 bytes apart, from SPRITE5B00
F376 LD HL,SPRITE5B00
CREATURE_UPDATE_7 F379 LD C,$02 No way to go, and bit 1: it does not fall
CREATURE_UPDATE_8 F37B SET 4,(IX+OBJ_FRAME) Make sure the run is at least three frames (the last frame, bits 3-5 of +17, at least 2)
F37F JP ANIM Step through the frames
CREATURE_UPDATE_9 F382 CP $0D State 13
F384 JR NZ,CREATURE_UPDATE_11
F386 LD A,C With no x or y direction of its own, go down x and up y ($45), turning back when stopped
F387 AND $CC
F389 JR NZ,CREATURE_UPDATE_10
F38B LD C,$45
CREATURE_UPDATE_10 F38D LD DE,$005C Frames of 16 by 23 from SPRITE5B30
F390 LD HL,SPRITE5B30
F393 JR CREATURE_UPDATE_8
CREATURE_UPDATE_11 F395 CP $0E State 14
F397 JR NZ,CREATURE_UPDATE_12
F399 LD HL,SPRITE6104 Frames of 16 by 10 from SPRITE6104, hanging still
F39C LD DE,$0028
F39F JR CREATURE_UPDATE_7
CREATURE_UPDATE_12 F3A1 CP $0F State 15
F3A3 JR NZ,CREATURE_UPDATE_13
F3A5 XOR A Unless the thing of kind 11 lies in the room (bit 1 of IY+$11, set by CHE3D): stand quite still, not even falling. (This skips the clearing of C: C still holds +13, which is nought for this figure)
F3A6 BIT 1,(IY+THINGS_NOTED-V)
F3AA JP Z,ANIMATE_AND_MOVE_3
F3AD LD E,$0B Then be a wraith. The wraith's case writes the state it is given, so it stays one (measured, by putting the thing of kind 11 in room 61: the figure took the wraith's frame and state 11 and came for the knight)
F3AF JR WRAITH_MOVES
CREATURE_UPDATE_13 F3B1 CP $07 State 7: the troll
F3B3 JR NZ,KNIGHT_UPDATE
F3B5 RES 4,(IX+OBJ_KIND) Clear bit 4 of its +12, which makes a touch cost the knight 10 LIFE (OBJECTS_MEET): the troll's object-table records have it set, so it lasts only until the troll's first pass (the working copy keeps it for that pass)
F3B9 CALL STEER Keep course, or aim at the knight
F3BC CALL MITRO Turn its frames (SPRITE8BB8) to face the way it goes
F3BF BIT 6,E Facing away: the frames that start 684 bytes on (SPRITE8E64)
F3C1 JR NZ,CREATURE_UPDATE_14
F3C3 LD DE,$02AC
F3C6 ADD HL,DE
CREATURE_UPDATE_14 F3C7 LD DE,$00E4 Frames of 24 by 38, 228 bytes apart
F3CA JP ANIM
This entry point is used by the routine at CHE3D.
KNIGHT_UPDATE F3CD CP $08 The author's I8. Any state not handled above just moves the way +13 says
F3CF JP NZ,MOVE_IN_DIRECTION
F3D2 LD A,(IY+FALL_COUNT-V) State 8, the knight, on the ground. A fall of more than 20 passes (IY+$14, counted by ANIMATE_AND_MOVE) costs a LIFE point a pass over
F3D5 SUB $14
F3D7 CALL NC,DECLIF
F3DA LD (IY+FALL_COUNT-V),$00 Start the count again
F3DE LD C,$01 Standing: no way to go (bit 0 alone)
F3E0 LD A,$18 Any key but 1-5 and 6-0: the action and movement keys
F3E2 CALL INPUT
F3E5 JR NZ,PICK_OR_DROP
F3E7 CALL IN31 No key: the Kempston joystick, if it is on (IN31)
F3EA JP NZ,STICK_DIRECTION
F3ED LD C,(IX+OBJ_DIRECTION) Nothing pressed. C = the way he was going, which matters only if he stands on something that moves
F3F0 LD A,(WORK_ANIMATION) Back to the first frame of a run (+17's bits 0-2)
F3F3 AND $F8
F3F5 LD (IX+OBJ_FRAME),A
F3F8 DEC (IX+OBJ_COURSE) Count down to a change of stance (+18)
F3FB JR NZ,CREATURE_UPDATE_15
F3FD LD A,(GAME_FLAGS) Start or end a fidget (bit 3 of IY+$17)
F400 XOR $08
F402 LD (GAME_FLAGS),A
F405 BIT 3,A A fidget lasts 14 passes...
F407 LD (IX+OBJ_COURSE),$0E
F40B JR NZ,CREATURE_UPDATE_15
F40D LD A,R ...and the stillness between them 128 to 255, at random
F40F OR $80
F411 LD (IX+OBJ_COURSE),A
CREATURE_UPDATE_15 F414 RES 1,(IY+GAME_FLAGS-V) His sword is not out
F418 BIT 4,E Riding on something that moves (state bit 4): keep his sprite and go with it
F41A JR NZ,CREATURE_UPDATE_18
F41C BIT 6,E Facing the viewer: SPRITE91CA, or SPRITE99C8 in a fidget
F41E JR Z,CREATURE_UPDATE_16
F420 LD HL,SPRITE91CA
F423 BIT 3,(IY+GAME_FLAGS-V)
F427 JR Z,CREATURE_UPDATE_17
F429 LD HL,SPRITE99C8
F42C JP CREATURE_UPDATE_17
CREATURE_UPDATE_16 F42F LD HL,SPRITE93F8 Facing away: SPRITE93F8, or SPRITE9A82 in a fidget
F432 BIT 3,(IY+GAME_FLAGS-V)
F436 JP Z,CREATURE_UPDATE_17
F439 LD HL,SPRITE9A82
CREATURE_UPDATE_17 F43C LD C,$01 Stand still
CREATURE_UPDATE_18 F43E JP SET_SPRITE_AND_MOVE Show the frame, and move (or not)
PICK_OR_DROP F441 LD A,$FE Krumlinde's MainLoop_DropItemCheck. A key is down, so no fidget
F443 RES 3,(IY+GAME_FLAGS-V)
F447 CALL INPUT Nothing on the CAPS SHIFT to V row: walk, jump or fight (KNIGHT_CONTROLS)
F44A JP Z,KNIGHT_CONTROLS
F44D AND $1C X, C or V: pick up (PICK_UP)
F44F JP NZ,PICK_UP
DROP_THING F452 LD A,(IY+OBJECT_COUNT-V) CAPS SHIFT or Z: drop. Not with 46 records or more in use: then read the walking keys instead
F455 CP $2E
F457 JP NC,WALK_KEYS
F45A LD H,$FF The place in use (SELECTED, IY+$1E) is empty: nothing to drop; just redraw him
F45C LD L,(IY+SELECTED-V)
F45F LD E,(HL)
F460 INC HL
F461 LD D,(HL)
F462 LD A,E
F463 OR D
F464 JP Z,REDRAW_THIS_OBJECT
F467 DEC HL Keep the place's address; IX = the thing; B, D, H = where he is
F468 PUSH HL
F469 PUSH DE
F46A POP IX
F46C CALL WORKING_POSITION
F46F LD E,(IY+WORK_BEHAVIOUR-V) Which way he faces: bits 5 and 6 of his state
F472 BIT 5,E
F474 JR NZ,CREATURE_UPDATE_20
F476 BIT 6,E
F478 JR NZ,CREATURE_UPDATE_19
F47A LD A,B Up x (neither bit): put it past his width
F47B ADD A,(IY+REPEATS+$01-V)
F47E LD B,A
F47F JR DROP_TEST
CREATURE_UPDATE_19 F481 LD A,H Down y (bit 6): its own depth short of him
F482 SUB (IX+OBJ_LEN_Z)
F485 LD H,A
F486 JR DROP_TEST
CREATURE_UPDATE_20 F488 BIT 6,E Down x (both bits): its own width short of him
F48A JR Z,CREATURE_UPDATE_21
F48C LD A,B
F48D SUB (IX+OBJ_LEN_X)
F490 LD B,A
F491 JR DROP_TEST
CREATURE_UPDATE_21 F493 LD A,H Up y (bit 5): past his depth
F494 ADD A,(IY+REPEAT_FROM+$01-V)
F497 LD H,A
DROP_TEST F498 LD C,(IX+OBJ_LEN_X) Krumlinde's DropItem_TestPlacement. Would the thing's own box there meet anything? (It is still marked as carried, so it does not meet itself)
F49B LD E,(IX+OBJ_HEIGHT)
F49E LD L,(IX+OBJ_LEN_Z)
F4A1 PUSH IX
F4A3 CALL FIND_OBSTACLE
F4A6 EXX Keep the place's address in the other register set
F4A7 POP IX
F4A9 POP HL
F4AA EXX
F4AB JR NC,DROP_COMMIT Something is there: BLOCKED
F4AD LD (IY+MESSAGE-V),$01
F4B1 JR KNIGHT_DONE
DROP_COMMIT F4B3 EXX Krumlinde's DropItem_Commit. Empty the place
F4B4 XOR A
F4B5 LD (HL),A
F4B6 INC HL
F4B7 LD (HL),A
F4B8 EXX
F4B9 CALL ISO_MOVE Move the thing to the spot (its top level with his, so it starts in the air)
F4BC LD A,(IX+OBJ_WEIGHT) Its weight: +16 less 16, and nought if that is below it
F4BF AND $1F
F4C1 SUB $10
F4C3 JR NC,CREATURE_UPDATE_22
F4C5 XOR A
CREATURE_UPDATE_22 F4C6 LD L,A
F4C7 LD A,(CARRIED_WEIGHT) Off what he carries (CARRIED_WEIGHT, IY+$12)
F4CA SUB L
F4CB LD (CARRIED_WEIGHT),A
F4CE RES 5,(IX+OBJ_WEIGHT) No longer carried
F4D2 SET 4,(IX+OBJ_STATE) For one pass it goes where +13 says: up, and not falling (bits 4 and 1); then it falls
F4D6 LD (IX+OBJ_DIRECTION),$12
F4DA LD C,(IY+ROOM-V) The object table: it is in this room now
F4DD CALL SET_THING_ROOM
F4E0 CALL CLEAR_THING_BOX Empty the panel's box for the place
This entry point is used by the routines at PICK_UP and PICK_UP_LOOK_ON.
KNIGHT_DONE F4E3 JP REDRAW_THIS_OBJECT The author's DOE: the way out of the knight's actions. Redraw him, and the pass is over for him
Prev: F2F7 Up: Map Next: F4E6