I've recently started experimenting with Pulpscript and have successfully created a basic 1-bit Zelda-inspired game. In it, players can attack enemies using the confirm event. I'm looking to enhance the gameplay by implementing a whirlwind attack feature. Could anyone assist me in scripting this so that the sword tile changes orientation at 90, 180, 270, and 360 degrees? Any help would be greatly appreciated!
I wish you could've explained how your attack script works, but this should do it. I should mention that wsNum is there to change the sword tile depending on the crank's angle and that the tile is being drawn instead of being swapped as it is much easier to handle if it moves so fast.
on draw do
draw "sword {wsNum}" at wsX,wsY
end
on crank do
if event.aa<45 then
// up
wsNum = 0
wsOffsetY = -1
wsOffsetX = 0
elseif event.aa<135 then
// right
wsNum = 1
wsOffsetY = 0
wsOffsetX = 1
elseif event.aa<225 then
// down
wsNum = 2
wsOffsetY = 1
wsOffsetX = 0
elseif event.aa<315 then
// left
wsNum = 3
wsOffsetY = 0
wsOffsetX = -1
end
// Display
wsX = event.px
wsY = event.py
wsX += wsOffsetX
wsY += wsOffsetY
end
If you want to, you can extend this and make it work diagonally
if event.aa<30 then
// North
wsNum = 0
wsOffsetX = 0
wsOffsetY = -1
elseif event.aa<60 then
// North-East
wsNum = 1
wsOffsetX = 1
wsOffsetY = -1
elseif event.aa<120 then
// East
wsNum = 2
wsOffsetX = 1
wsOffsetY = 0
elseif event.aa<150 then
// South-East
wsNum = 3
wsOffsetX = 1
wsOffsetY = 1
elseif event.aa<210 then
// South
wsNum = 4
wsOffsetX = 0
wsOffsetY = 1
elseif event.aa<240 then
// South-West
wsNum = 5
wsOffsetX = -1
wsOffsetY = 1
elseif event.aa<300 then
// West
wsNum = 6
wsOffsetX = -1
wsOffsetY = 0
elseif event.aa<330 then
// North-West
wsNum = 7
wsOffsetX = -1
wsOffsetY = -1
end
Unfortunately, the code doesn't work for me - I even tried it on a fresh project. When I try to play it, the screen inside of the web emulator stays black.
Here is my attack script:
on confirm do
swordX = event.x
swordY = event.y
swordX += event.dx
swordY += event.dy
if event.dx==1 then
swordTile = "swordRight"
elseif event.dx==-1 then
swordTile = "swordLeft"
elseif event.dy==1 then
swordTile = "swordDown"
elseif event.dy==-1 then
swordTile = "swordUp"
end
tileAtSwordPos = name swordX,swordY
if tileAtSwordPos=="white" then
call "swingSword"
elseif tileAtSwordPos=="enemy" then
call "swingSword"
enemiesRemaining--
if enemiesRemaining<=0 then
emit "enemiesDefeated"
end
end
end
on swingSword do
ignore
tell swordX,swordY to
swap swordTile
wait 0.2 then
swap "white"
listen
end
end
end