Rotated D-Pad Controls

Hey everyone! I’m currently working on a small pulp game and wanted to have one room where the controls are rotated by 90° (up is actually left, left is actually down, etc.).

I’ve managed to write code where I can make the individual components of this work. As in, I can override a single D-Pad direction and it works (albeit with the player eventually clipping into black/wall tiles, but that’s another issue altogether, I assume). An example of this would be (player script):

on update do
	
	if event.dy==-1 then // player just moved up, but is moving left
		upX = event.x
		upY = event.y
		upX -= 1
		upY += 1
		goto upX,upY
	end
	
end

However, as soon as I put the code together to have it apply to more than one direction, it stops working and the player character is frozen in place. This is what my code looks like (again, player script):

on update do
	
	if event.dy==-1 then // player just moved up, but is moving left
		upX = event.x
		upY = event.y
		upX -= 1
		upY += 1
		goto upX,upY
	elseif event.dy==1 then // player just moved down, but is moving right
		downX = event.x
		downY = event.y
		downX += 1
		downY -= 1
		goto downX,downY
	elseif event.dx==1 then // player just moved right, but is moving up
		rightX = event.x
		rightY = event.y
		rightX -= 1
		rightY -= 1
		goto rightX,rightY
	elseif event.dx==-1 then // player just moved left, but is moving down
		leftX = event.x
		leftY = event.y
		leftX += 1
		leftY += 1
		goto leftX,leftY
	end
	
end

I’ve also tried having each direction override be separate (with “if” and “end” rather than the “elseif” variants), but that didn’t make a difference.

Neither did separately emitting “left”/”right”/… based on the dx/dy events and then calling on them with “on left do”/”on right do”/… and having the adjusted movement sections in there (inspired by this thread).

Anyone got any ideas on how I could make this work?

goto has this side-effect where the player’s update function is called after moving, so you want to check if its only called once after moving. Here’s how I would’ve done it.

on update do
 if rotateOnce==0 then
  call "rotateMove"
 end
end

on rotateMove do
 rotateOnce = 1

 rX = event.px
 rY = event.py
 if event.dy==-1 then // player just moved up, but is moving left
 	 rX -= 1
	 rY += 1
 elseif event.dy==1 then // player just moved down, but is moving right
	 rX += 1
	 rY -= 1
 elseif event.dx==1 then // player just moved right, but is moving up
	 rX -= 1
	 rY -= 1
 elseif event.dx==-1 then // player just moved left, but is moving down
	 rX += 1
	 rY += 1
 end

 rSolid = solid rX,rY
 if rSolid==1 then // stay still if tile is solid
	 rX = event.px
	 rY = event.py
	 rX -= event.dx
	 rY -= event.dy
 end
 goto rX,rY
 rotateOnce = 0
end

I also tried to fix your problem of checking solid tiles, though it’s not perfect, as the player can move diagonally after hitting a solid tile. You might also need to make your own interact function to make it work with the rotated controls.

Thank you so much for both the solution and explanation, and getting me started on the solid tile issue!

I had no idea about the side-effect, so I don’t think I’d have been able to figure this out.

I also appreciate seeing your condensed code for the movement overrides, I hope I can learn from your example!