Discuss Scratch

Rickyickerson
Scratcher
80 posts

enemies in a platformer

I'm making a platformer with a side scrolling script. I want to add enemies into the game but I don't know how to make them show up once the player goes to where the enemy is.
imfh
Scratcher
1000+ posts

enemies in a platformer

It depends on what kind of script you are using. Usually this would be done by making the enemies appear when a ScrollX variable is in the right range. If you want more detail you may have to share the project and link so we can look at it.

Scratch to Pygame converter: https://scratch.mit.edu/discuss/topic/600562/
Rickyickerson
Scratcher
80 posts

enemies in a platformer

mstone326
Scratcher
1000+ posts

enemies in a platformer

You can give the koopatrooper a variable called koopatrooperX, I would do for this sprite only so you can add clones later and they can each have their own copy of that variable. Then tell the sprite to go to scrollX + koopatrooperX.

For hiding off screen you can use the absolute value of the koopatrooper's x position, not its variable position or its scrollX. Use its stage x position. If the abs of xpos is > 230 hide, else show

High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
imfh
Scratcher
1000+ posts

enemies in a platformer

Inside your koopatroopa sprite, you can use this script:

when green flag clicked
go to x: (199) y: (-114)
forever
if <<(-740)>(ScrollX)> or <(ScrollX)>(-240)>> then // Check if the player is in range
show
set x to ((ScrollX)+(480))
else
hide
wait (0.1) secs // Optional, might be better for perfomance
end
end

You might want to create a broadcast scroll that runs what is inside the forever loop and only broadcasts when the player is moving so that you aren't unnecessarily running loops.

Scratch to Pygame converter: https://scratch.mit.edu/discuss/topic/600562/
Rickyickerson
Scratcher
80 posts

enemies in a platformer

Do you know how I could modify the script so that the Koopa Troopa moves?
imfh
Scratcher
1000+ posts

enemies in a platformer

You'll need to do something like this. I haven't tested it so it may need tweaking.

when green flag clicked
go to x: (199) y: (-114)
forever
if <<((thisX)+(250))>(ScrollX)> and <(ScrollX)>((thisX)-(250))>> then // Check if the player is in range
show
set x to ((ScrollX)-(thisX))
else
hide
wait (0.1) secs
end
end

Scratch to Pygame converter: https://scratch.mit.edu/discuss/topic/600562/

Powered by DjangoBB