Well, I really got carried away and rewrote the script to do any jump one could want, up, down, level, diagonal, any distance, and you can adjust the constants like the strength of gravity without completely breaking it. So now I can point people at this in the future. There's also some animation code in there, which might need adjusting for the way you're drawn your walkabouts.
Code: Select all
define constant(1, gravity)
# Make a hero jump a certain number of tiles in the X, Y and Z directions,
# possibly diagonally.
# 'z tiles' is the amount to travel upwards (negative for downwards),
# e.g. -1 to fall to a platform that's one tile lower,
# 0 for a jump between two level platforms, 2 to gain 2 tiles height, etc.
script, jump hero, who, x tiles, y tiles, z tiles = 0, begin
# How hard do we have to jump upwards? This part might need some adjusting,
# and if 'initial vz' isn't large enough when jumping upwards, the hero will get
# jerked to the destination
variable(initial vz)
if (z tiles < 0) then (initial vz := 4) # Just hop over the edge (assuming we don't jump far)
else if (z tiles == 0) then (initial vz := 6) # Jumping straight
else (initial vz := 6 + z tiles * 2) # Jumping upwards
# First calculate ahead of time how long it's going to take to jump
# Keep dropping until we've fallen to the desired z value on the way down (vz is negative)
variable(ticks, z, vz)
vz := initial vz
while (vz >= 0 || z > z tiles * 20) do (
z += vz
vz -= gravity
ticks += 1
)
# Move in an arc using puthero
camera follows slice (lookup slice(sl:walkabout sprite component, get hero slice(who)))
variable(startx, starty, i)
startx := hero X (who)
starty := hero Y (who)
vz := initial vz
# Skip one tick: the last frame is when we realign, not inside the for loop
for (i, 1, ticks -- 1) do (
put hero (who, 20 * start x + 20 * x tiles * i / ticks, 20 * start y + 20 * y tiles * i / ticks)
set hero Z (who, hero Z (who) + vz)
vz -= gravity
# For no walking animation during the jump, comment this line:
if (i < 5) then (set hero frame (who, (i/2, mod, 2)))
wait
)
# Realign the hero, converting Z displacement to Y position
set hero position (who, start x + x tiles, start y + y tiles -- z tiles)
set hero Z (who, 0)
set hero frame (who, 1) # Ideally, change this to the 'standing' instead of 'stepping' walk frame
camera follows hero (who)
end
Here's a convenient script to test it:
Code: Select all
plotscript, onkeypress test jump, begin
if (keyval(key:1) > 1) then (
do a jump(1, 0)
) else if (keyval(key:2) > 1) then (
do a jump(2, 0)
) else if (keyval(key:3) > 1) then (
do a jump(3, 0)
) else if (keyval(key:d) > 1) then (
do a jump(1, -1) # down
) else if (keyval(key:p) > 1) then (
do a jump(1, -3) # plummet
) else if (keyval(key:u) > 1) then (
do a jump(1, 1) # up
)
end
script, do a jump, distance, z, begin
switch (hero direction(me)) do (
case(south) jump hero(me, 0, distance, z)
case(north) jump hero(me, 0, -1*distance, z)
case(east) jump hero(me, distance, 0, z)
case(west) jump hero(me, -1*distance, 0, z)
)
end