[4.5] Move left, right, up or down AI monster scripts

JFranco

New member
Hey gang,

If you're looking for AI Monster scripts to move your monster left, right, up or down -- here's a solution that worked for me:

MoveLeft.asm
Code:
	TXA	
	STA tempA
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC

MoveRight.asm
Code:
	TXA													
	STA tempA											
	LDA #%00000011 ;; "right"									
	TAY													
	LDA DirectionTable,y										
	STA tempB											
	LDA FacingTable,y										
	STA tempC											
	StartMoving tempA, tempB, #$00							
	ChangeFacingDirection tempA, tempC


MoveUp.asm
Code:
	TXA	
	STA tempA
	LDA #%00000001  ;; goes up
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC

MoveDown.asm
Code:
	TXA	
	STA tempA
	LDA #%00000000  ;; "down"
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC


Cheers,
Justin
 

TolerantX

New member
Thank you JFranco for these scripts! They are extremely helpful! I had trouble with the move left script and fixed it:

Code:
	TXA	
	STA tempA
	LDA #$02
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC
 

Lother

Member
Great ! But how to make it work in the ArcadePlatformer module ? Because when I check "Ignore gravity" for the go up or go down the monster stays in place.
 

mouse spirit

Well-known member
I believe this is for adventure, meaning no gravity is involved. It may be a more involved process in the physics to make stuff "fly" how you want in your game. But it also could be an option already,im not sure as i have not watched all the vids yet..
 

AllDarnDavey

Active member
Lother said:
Great ! But how to make it work in the ArcadePlatformer module ? Because when I check "Ignore gravity" for the go up or go down the monster stays in place.

Looks like it should work, make sure you set a max speed and acceleration speed in the monster object details. That's usually my mistake, it should be moving, and I find out I have my max speed set to zero.
 

twin paradox

New member
Thank you for these but I wanted to piggy-back on Lother's comment that the Up/Down movement scripts do not seem to work in the Platform module. I have the Ignore Gravity flag set and I have given the monsters speed and acceleration and they still won't move up and down. I am going to dig around in the ladder tile code to see if that can maybe be applied in some way.
 

PasseGaming

Active member
I don't think they work in the scrolling shooter module either. Though I can't be sure as the monster is actually never on screen when I arrive. So I'm assuming it's either because it works and they moved off screen or it's doing something funky and not appearing. I've seen monsters not appear on screen before depending on the action steps I gave it so I cant be sure either way. It's frustrating as I need my boss monster to move up and down while shooting at the player and I can't seem to pull it off.
 
Lother said:
These two settings are set, but my monster can only move left and right.

This appears to make it work if you edit doHandlePhysics_ArcadePlatformBase.asm, paste code over doneWithGravity bit.
Code:
doneWithGravity:

VerticalMovement:
	LDA Object_direction,x
	AND #%00100000
	BEQ +noVertMovement
		;; there is vertical movement
		LDA Object_direction,x
		AND #%00010000
		BEQ +isUpMovement
			;; is down movement
			LDA Object_y_lo,x
			CLC
			ADC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			ADC myMaxSpeed+1;Object_v_speed_hi,x
			STA yHold_hi
				CLC
				ADC self_bottom
				CMP #BOUNDS_BOTTOM ;#240
			
				BCS doBottomBounds
					JMP +noVertMovement
				doBottomBounds:
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$00
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
		+isUpMovement
			LDA Object_y_lo,x
			SEC
			SBC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			SBC myMaxSpeed+1;Object_v_speed_hi,x
			BCC +doTopBounds ;; helps if top bounds is zero. 
			STA yHold_hi
			CMP #BOUNDS_TOP
				BEQ +doTopBounds
				BCC +doTopBounds
					JMP +noVertMovement
				+doTopBounds
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$02
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
	+noVertMovement
skipPhysics:
 

Lother

Member
UltraNarwhal said:
Lother said:
These two settings are set, but my monster can only move left and right.

This appears to make it work if you edit doHandlePhysics_ArcadePlatformBase.asm, paste code over doneWithGravity bit.
Code:
doneWithGravity:

VerticalMovement:
	LDA Object_direction,x
	AND #%00100000
	BEQ +noVertMovement
		;; there is vertical movement
		LDA Object_direction,x
		AND #%00010000
		BEQ +isUpMovement
			;; is down movement
			LDA Object_y_lo,x
			CLC
			ADC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			ADC myMaxSpeed+1;Object_v_speed_hi,x
			STA yHold_hi
				CLC
				ADC self_bottom
				CMP #BOUNDS_BOTTOM ;#240
			
				BCS doBottomBounds
					JMP +noVertMovement
				doBottomBounds:
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$00
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
		+isUpMovement
			LDA Object_y_lo,x
			SEC
			SBC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			SBC myMaxSpeed+1;Object_v_speed_hi,x
			BCC +doTopBounds ;; helps if top bounds is zero. 
			STA yHold_hi
			CMP #BOUNDS_TOP
				BEQ +doTopBounds
				BCC +doTopBounds
					JMP +noVertMovement
				+doTopBounds
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$02
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
	+noVertMovement
skipPhysics:

Ok that works perfectly, thanks.
 

Yan

Member
Does anyone know a way to adapt UltraNarwhal's fix to work with "doHandlePhysics_PlatformBase.asm" instead of "doHandlePhysics_ArcadePlatformBase.asm"? I've been having some trouble making it work with a game that has scrolling.
 

Craigery

Member
Does anyone know a way to adapt UltraNarwhal's fix to work with "doHandlePhysics_PlatformBase.asm" instead of "doHandlePhysics_ArcadePlatformBase.asm"? I've been having some trouble making it work with a game that has scrolling.
Paste the code in doHandlePhysics_PlatformBase, just below Line 444.
doneWithH:
you can remove
VerticalMovement:
So right after what we pasted should the Object_vulnerability check. I tried moving a monster up and down and it seems to work for me.
 
  • Like
Reactions: Yan
I'm curious why you have it written to destroy an object that uses Up or Down if it's not the player?

Code:
                CPX player1_object
                    BEQ +isPlayer
                        DestroyObject
                        JMP skipPhysics

I had to comment those lines out to get it to work with my monster. Otherwise it would just disappear the instant the screen loaded.
 
Top Bottom