Hi y'all,
I'm new to pulp script and novice overall in programming language and game design.
What I'm trying to do is to add sprites to the room layer that all have different effects. I have moving crates, animated death shuriken and a TnT barrel that one day may actually roll like in Donkey Kong Country and upon touching something, go BOOM!
I'm having trouble with how I would script the barrel to move in a line to a destination. I have accomplished the "moving" by modifying the script I used for the crate:
on interact do
// Determine destination coordinated of crate
DesX = event.x
DesY = event.y
if event.dy==1 then // if players recent up movment
DesY+=5 // then change var y is incremented by 1
elseif event.dy==-1 then // if player recent down movment
DesY-=5 // decrement 1
elseif event.dx==1 then
DesX+=5
elseif event.dx==-1 then
DesX-=5
end // parts of interact event are limited to the direction "pushed"
As you can imagine, currently the barrel "jumps" 5 increments. I just can't figure out how to swap white tiles in the intermittent spaces to give the appearance of the barrel "moving" or "sliding". The remaining script for the crate is simply insufficient for this.
I'm pouring over other example pulp script looking for examples that I can learn from, and I just haven't found the right ones or maybe I've been looking in the wrong places?
If y'all have seen this someplace else, I would appreciate a friendly point in the right direction! Any help would be greatly appreciated 
There is multiple ways to do this, but I'll explain the one I think is the best.
We will have a static barrel waiting for being pushed. On interact it will change for a moving barrel. The barrel will handle its self movement, so it needs to know where to move. There could be multiple barrels so we can't use a variable to store the direction because they'll be sharing it. Instead, we will use the name of the tile as that variable. So we create 4 different moving barrels, and the code for the static one will be like this:
// STATIC BARREL
on interact do
if event.dx==1 then
swap "barrelRight"
call "continue"
elseif event.dx==-1 then
swap "barrelLeft"
call "continue"
elseif event.dy==1 then
swap "barrelDown"
call "continue"
elseif event.dy==-1 then
swap "barrelUp"
call "continue"
end
end
We are going to use the event continue
to make the barrel move by itself. Now we need a timer for the movement. In my opinion the best timer to handle this kind of movement is play
. Using play
will reproduce the tile animation and then stop in the last frame, but it let's us to use a then
when it finishes. Play
is better than wait
because you can stop what happens after it by replacing the tile, using play again, or going to another room (so the barrel will not try to replace a tile even in another room). For example, the code for "barrelUp" will be:
on enter do
call "continue" // in case we go out of the room, when we enter again it will continue
end
on continue do
play "barrelUp" then // We use play as a timer, so FPS determines the speed
desX = event.x
desY = event.y
desY-- // Destiny up
desSolid = solid desX,desY
if desSolid==0 then //If destiny is not solid, the barrel moves
tell desX,desY to
swap "barrelUp"
call "continue" // Continue the moving loop
end
swap "white"
else // Else, the barrel explodes
play "explosion" then
swap "white"
end
end
end
end
on interact do
mimic "barrelStatic" // If the player is faster than the barrel, we could re-direct it
end
I did this example project so you can test and tweak things if you want 
BarrelExample.json.zip (3.3 KB)
1 Like
Thanks so much!! You've given me so much to unpack....like literal pieces to put together that simply weren't there yesterday!!
It's interesting in my mind how before I was thinking about "movement" because your script doesn't really plot anything along an axis (as I was thinking it had to be!). Rather the solid==0 check and the continue loop are the "line". Very neat. It's really a very artful thing, programming, and I appreciate that about the example you've mocked up. You are an artist, sir!

1 Like