[4.5.6] Repeat With Timer End Action

AllDarnDavey

Active member
So, I like the nice little state machine we have going on for objects. I mean we only have 8 steps, but it's 8bit gaming what do you want. The states can even run code (but only on the first frame), the only thing I wish was more useful was the Repeat end action. If you use Repeat as either the EndActoin or EndAnimation action, your state machine is stuck in an endless loop, and can only escape with something external forcing it out.

Now sometimes that's fine, it's what you want, fireballs jumping out of lava can repeat forever just fine. But it would be nice if we could have the step repeat after every animation cycle and rerun script code, but not forever, just until the action time is up, then follow the EndAction instruction. So I made an EndAction that did just that, it doesn't reset the action timer when it resets the action step, meaning if you use it as an endAnimation the step will repeat (and rerun script code eveytime it does) until the action timer is over, then it'll follow whatever EndAction says. Repeat for a time, but not forever... a repeat action without totally giving up state machine control.

I'm using it for running scripts that need to be re run over multiple frames, but I don't want to loop forever. Things like swapping colors on bosses when hit, or making the object flicker when taking damage.
RepeatWithTimerScripts.gif

Just add the below code to your TimerEndScript.asm file. I currently have it added as a userEnd0_action around line 199. But I might just replace the normal Repeat end_action around line 48 with it, as you can still use this code to repeat forever like the original does, by just setting both EndAction and EndAnimation to it.

Code:
userEnd0_action:
;;; REPEAT WITH TIMER
;;; Repeat after animation without reseting action timer
	LDA Object_action_timer,x ;;get action timer before reset
	CMP #%00000001 ;;force the timer to be an even number, makes returning from looping actions easier
	BEQ +
	STA tempC ;; save action timer to tempC
	LDA Object_frame,x
		LSR
		LSR
		LSR
		AND #%00000111
		STA tempB
	
		TXA 
		STA tempA

		DoObjectAction tempA, tempB  ;;repeat the action
		;arg0 = what object?
		;arg1 = what step behavior?
		LDA tempC
		STA Object_action_timer,x ;;restore old action timer
+:		
		RTS

RepeatWithTimer.PNG
 
Top Bottom