Hello! I have a little projectile in the dungeon for a game I'm making, but I have a problem with the projectile. I have the projectile move by telling the tile in front of it to swap to the projectile, and having the projectile swap to the floor tile. I decided to try to make it so instead of swapping to one floor tile, it will swap back to whatever tile was originally there, before the projectile got there. But I couldn't figure out how to do this, and got the below. How might I solve this problem? Thanks!
I would use the draw
function to move the proyectiles instead of swapping them with the floor tiles.
I've done a similar thing in a game I'm slowly working on, where the player's flying character has a shadow so I store the original tile before replacing it with the shadow, then when the shadow moves I put the original tile back.
So, I think what you could do is look at the tile in front like you're doing now (e.g. the projectile's coordinates + 1) and store it in a variable e.g. projectile1floor (for the first projectile) then after the projectile has moved away, swap those coordinates with the projectile1floor.
It's been a wee while since I coded this so apologies if it's not totally helpful!
Hey there. I have done this in my game Cooking for Crabtopia. Here is roughly the code that you are looking for. In mine, I was having leaves fall and swap with whatever tile they previously were covering. The code is below.
The game is free, feel free to go check it out, run directly to the left to get to the tree/leaf catching minigame to see how it works. Linked below.
on leafMove do
// This makes it not destroy the bottom 2 parts of the floor
if event.y==12 then
swap oldUnderlyingTile
leaf--
else
// Below moves the leaf downwards and swaps the background to what it should be
plantX = event.x
plantY = event.y
tell plantX,plantY to
swap oldUnderlyingTile
end
plantY++
underlyingTile = id plantX,plantY
if event.px==plantX then
if event.py==plantY then
leaves++
waitTimerLeaf1 = random 0,2
wait waitTimerLeaf1 then
leaf = 0
end
swap oldUnderlyingTile
else
tell plantX,plantY to
swap "leaf"
end
end
else
tell plantX,plantY to
swap "leaf"
end
end
oldUnderlyingTile = underlyingTile
end
end
In case you need the function from the on loop in the game function, the pertinent stuff is below.
if event.room=="tree" then
// This keeps the player pushed down where it should be
playerY = event.py
if playerY<=11 then
playerY++
tell "player" to
goto event.px,playerY
end
end
// This is the timer to make the leaves move
fElapsedLeaf = event.frame
fElapsedLeaf /= leafInterval
fElapsedLeafFloor = floor fElapsedLeaf
if fElapsedLeaf==fElapsedLeafFloor then
emit "leafMove"
end
// The below are the on loop functions to keep the leaves spawning as needed
if leaf==0 then
tell "leaf" to
call "leafSpawn"
end
end
if leaf2==0 then
tell "leaf2" to
call "leaf2Spawn"
end
end
if leaf3==0 then
tell "leaf3" to
call "leaf3Spawn"
end
end
end
so don't make the tiles "move" really, just make them progress.
make each tile do something like this:
floorA > floorB > floorC > projectile > floorA > floorB > floorC > projectile > floorA etc
and then offset them so that the projectile seems to move across them
then you can make floorA, B and C all look the same to the player and they won't know the difference.
you'll then need to make another set for the parts of the hole.