So. In my game, I want to have pits that the player can fall down, and for them to play a little falling animation. This effect can be done in multiple ways, many of which would lead to a Wile E. Coyote effect as the player only starts falling once they've fully walked onto the pit tile; while this would ultimately be acceptable, I'm wondering if it's possible for it to instead start the animation as the player starts walking into the pit (or is already partway through).
In descending order of complexity, the following features would be good to implement:
0 - Player walks into pit tile, screen goes black, sound effect plays, they land somewhere. The most basic pit, looking for something better than this.
1 - Player walks into pit tile, an animation of them falling down occurs, fade to black. Should be easy to do, and should be satisfactory.
2 - Player starts walking into the pit tile, animation starts playing when they're mid-way through the tile.
3 - As above, but plays a different animation depending on what direction they're heading as they walk into the pit. Should be easy to do, if you've created pit #2?
4 - As above, but the animation starts right as the player begins to walk into the pit tile. I imagine the script would have to be already active when the player's in a tile adjacent to the pit, and then checking for the keypress that'd send them into it.
There was a bit of discussion in the Q&A sub-discord on this; what's the etiquette for copying and pasting them to the forums?
This is the pits.
Moderators: marionline, SDHawk
- Hedera
- Slime Knight
- Posts: 175
- Joined: Tue May 17, 2011 11:38 am
- Location: a dying forest (all forests are dying)
This is the pits.
- Attachments
-
- The Immortal .gif courtesy of i-mockery
- immortaldeaths06.gif (301.85 KiB) Viewed 5134 times
Last edited by Hedera on Wed Apr 21, 2021 3:15 am, edited 1 time in total.
Checking the tile you're on once you're over halfway onto seems simple:
But actually the above code is not symmetric whether you're approaching from the left or right, because if you're exactly half-way between tiles (possible if the walk speed is 1, 5 or 10) then it conts as the tile to the right.
Getting to about 3.8 on your scale is the easiest place to stop: create an animation that triggers one tick after the hero begins to move onto the tile. If you really want to go all the way to 4 then you need to use the Hero will move script on the wiki. The script largely works but there are edgecases that break it, so I recommend against using it if you can avoid it. Most importantly it doesn't support mouse controls at all!
First some useful scripts:
So to figure out which tile the player is walking onto:
You have to do this check every tick, using either a timer or a while loop, and stop checking once the animation has finished.
However if you used "hero will move" instead then you could just use an on-keypress script.
You can check the hero direction in the same way to decide which animation to play; animations are another subject.
EDIT (8/5/21: fixed bug)
Code: Select all
if (read zone (ZONEID, (hero pixel x (me) + 10) / 20, (hero pixel y (me) + 10) / 20) then (...)
Getting to about 3.8 on your scale is the easiest place to stop: create an animation that triggers one tick after the hero begins to move onto the tile. If you really want to go all the way to 4 then you need to use the Hero will move script on the wiki. The script largely works but there are edgecases that break it, so I recommend against using it if you can avoid it. Most importantly it doesn't support mouse controls at all!
First some useful scripts:
So to figure out which tile the player is walking onto:
Code: Select all
if ((hero pixel x (me), mod, 20) || (hero pixel y (me), mod, 20)) then (
# The hero is partway between tiles. Figure out the destination tile
variable(x, y)
x := hero pixel x (me) / 20 # Rounds to the tile to the left
y := hero pixel y (me) / 20 # Rounds to the tile above
if (hero direction(me) == down) then (y += 1)
if (hero direction(me) == right) then (x += 1)
if (read zone(ZONEID, x, y)) then (
# Stepping onto a pit, start animation here
)
)
However if you used "hero will move" instead then you could just use an on-keypress script.
You can check the hero direction in the same way to decide which animation to play; animations are another subject.
EDIT (8/5/21: fixed bug)
Last edited by TMC on Fri May 07, 2021 1:00 pm, edited 2 times in total.
Come to think of it, the script I posted could break when using mouse movement of multiple tiles at a time. I've edited my post to fix the bug. (It assumed that "heroiswalking(me)" is true only when you're already partway between tiles, but when making multitile movements you might be aligned to the tile grid.)
- Hedera
- Slime Knight
- Posts: 175
- Joined: Tue May 17, 2011 11:38 am
- Location: a dying forest (all forests are dying)
(coming back to this after not doing any work for a couple weeks )TMC wrote:You have to do this check every tick, using either a timer or a while loop, and stop checking once the animation has finished.
However if you used "hero will move" instead then you could just use an on-keypress script.
Here's what I have so far: two scripts, the first being the one you did inside a while loop, and the second being a placeholder animation for actually falling down the pit and dying. test pit check is used as an autorun script for the maps that have pits. It doesn't seem to trigger the second one, though, or else it does and it's not doing anything. Or possibly both. I don't know.
Code: Select all
plotscript, test pit check, begin # All credit to TMC for this script
while (current map == (3 || 7)) # this script only runs on maps 3 and 7 at the moment, so it forms a tautology
do (
if ((hero pixel x (me), mod, 20) || (hero pixel y (me), mod, 20))
then (
variable(x, y)
x := hero pixel x (me) / 20
y := hero pixel y (me) / 20
if (hero direction(me) == up) then (y += 1)
if (hero direction(me) == right) then (x += 1)
if (read zone((4 || 5 || 6), x, y)) # zone 4 is the pit proper, zones 5 and 6 are for disappearing pits
then (
test pit fall
)
)
)
end
plotscript, test pit fall, begin
set hero z (leader, -2) # This is a temporary "fall down and die" "animation", and should be replaced asap
wait (1)
set hero z (leader, -10)
wait (1)
fade screen out (63, 0, 0)
wait (1)
game over
end
- Bob the Hamster
- Lord of the Slimes
- Posts: 7684
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Code: Select all
read zone((4 || 5 || 6), x, y)
Code: Select all
read zone(4, x, y) || read zone(5, x, y) || read zone(6, x, y)
Also, I noticed a bug in the script I gave you (which I didn't, and still haven't, tested):
should be
Code: Select all
if (hero direction(me) == up) then (y += 1)
Code: Select all
if (hero direction(me) == down) then (y += 1)
Last edited by TMC on Fri May 07, 2021 12:59 pm, edited 1 time in total.