4.5 enemy action step changes direction based on counter

Moehr

New member
posting this just cause someone on the FB group was asking about it and I wanted to give them a link. It's pretty straightforward but also probably poorly written. If someone wants to take a crack at a better version, feel free.

The reason this is set up how it is was to have a single player object control all of the spell FX for one character, with one action step per spell. Advancing an action step normally therefore can't be used as a timer since it would change the graphics of the spell. Instead, I set the end action AI to "repeat" and the animation to "loop".

From there the AI posted below handles a counter used by the player's spells that can be accessed in a number of other routines. I couldn't increment the timer elsewhere for this spell because there's no way to easily predict/control how often the spell AI fires, and if the counter is run down outside of the spell AI, the spell inevitably desynchs.

Code:
note - this is an enemy AI script

;earth - move up, drift, and crash down
+isEarth
INX
LDA Object_type,x
STA temp1
DEX
LDA Object_type,x
CMP temp1
BEQ +leftSideRockToss
    JMP rightSideRockToss

+leftSideRockToss
LDA gameTimerHi
CMP #$01
BNE +nextCheck
    LDA #UPLEFT
    JMP +headingLeft
+nextCheck
CMP #$02
BNE +nextCheck
    LDA #LEFT
    JMP +headingLeft
+nextCheck
CMP #$03
BNE +nextCheck
    LDA #DOWNLEFT
    JMP +headingLeft
+nextCheck
    LDA Object_status,x
    AND #$3F
    STA Object_status,x
    JMP doneSpellAI
+headingLeft
STA temp1
JMP +isMoving

rightSideRockToss:
LDA gameTimerHi
AND #%00000111
CMP #$01
BNE +nextCheck
    LoadObjectSubPalettes #$3B, #$00
    LDA #UPRIGHT
    JMP +headingRight
+nextCheck
CMP #$02
BNE +nextCheck
    LDA #RIGHT
    JMP +headingRight
+nextCheck
CMP #$03
BNE +nextCheck
    LoadObjectSubPalettes #$00, #$00   
    LDA #DOWNRIGHT
    JMP +headingRight
+nextCheck
    LoadObjectSubPalettes #$3B, #$04
    LoadObjectSubPalettes #$3B, #$08
    LoadObjectSubPalettes #$3B, #$12
    LDA #$00
    STA gameTimerHi
    LDA #%10000000
    STA gameTimerLo
    LDA Object_status,x
    AND #$3F
    STA Object_status,x
    JMP doneSpellAI
+headingRight
INC gameTimerHi
STA temp1

then elsewhere, in doHandlePhysics, after this block, I edited as follows to allow for some action-step based checks to alter the max speed of the spells depending on which action step [and therefore which spell sprite] was currently visible. One is a flame that moves at a fair clip, and the earth spell that was asked about in the FB group needed to look more like it was moving in an arc [using the code from the above section].

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;find this chunk
        +notHurt
   
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA ObjectMaxSpeed,y
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;this next bit is added to allow for a context-based modification of max speed for a single action step of a single player object [using player object 05]
        LDA Object_type,x
        CMP #$05
        BNE +notFlameOrEarth
            LDA Object_frame,x
            AND #%00111000
            CMP #%00001000
            BNE +notFlameOrEarth
                LDA #$C0
                STA myMaxSpeed
                LDA #$00
                STA myMaxSpeed+1
        +notFlameOrEarth
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;end of stuff for max accel modulation added by me to doHandlePhysics
        ;;; now high max speed byte is the actual high byte of speed


Then, at the next bit of doHandlePhysics:

Code:
skipDoHdec:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;!!!!!!!!!!!!!!!!!!!!
;;; ***** added by me to run that check against the stones for earth spell!
LDA Object_type,x
CMP #$05
BNE +isNotEarthStone
LDA Object_frame,x
AND #%00111000
CMP #%00011000
BNE +isNotEarthStone
    LDA myMaxSpeed
    LSR
    LSR
    LSR
    STA Object_h_speed_lo,x
    LDA #$00
    STA Object_h_speed_hi,x
+isNotEarthStone
;;;;;;;;;;;;;;;;;;;;; *** done add

Those two bits added to doHandlePhysics are because objects only get one max speed, and in the overhead module, that speed is the same for X and Y values, making it hard to cause an object to move in an arc.
 

Jonny

Well-known member
Do you have an example of this in action? Like a gif or a video. No worries if not. Nice work.
 
Top Bottom