Discuss Scratch

pleasestopdeleteme
Scratcher
10 posts

Trying to add a way to attack the enemy with projectiles in my game.

https://scratch.mit.edu/projects/1366345334

The star sprites would be the projectiles. How do I code it so the protagonist fires them as such?
ClarkeGhost
Scratcher
100+ posts

Trying to add a way to attack the enemy with projectiles in my game.

To do this efficiently without cluttering your project with dozens of sprites, you should use clones.
First, add this to your Protagonist sprite so it creates a clone whenever you press the shoot key:

when green flag clicked
forever
if <key [space v] pressed?> then
create clone of [Star v]
wait (0.3) secs
end
end

Next, go into your Star sprite. You need two quick scripts.
The first one just hides the original star when the game starts:

• When green flag clicked -> hide

The second script tells each clone exactly where to spawn, which way to face, and how fast to move:

when I start as a clone
go to [Protagonist v]
point in direction ([direction v] of [Protagonist v]
show
repeat until <touching [edge v]?>
move (10) steps
end
delete this clone

Note: If the stars are spawning a bit off-center from your player, open up the Star's costume editor, select the whole star, and make sure it's snapped perfectly to the center crosshair of the canvas.
pleasestopdeleteme
Scratcher
10 posts

Trying to add a way to attack the enemy with projectiles in my game.

Thank ClarkeGhost, I updated it. But how do I make it so that the enemies disappear when hit by the projectiles.

Powered by DjangoBB