Discuss Scratch

Gamdapiko24
Scratcher
98 posts

Enemy keeps spawning on player

I am making a game where you use the arrow keys to accelerate a player (black circle) in any direction. When it hits a wall, it bounces in the mirrored direction. The catch is that every three seconds a red circle (enemy) will spawn randomly on the screen and if you touch it, you die. I don't really have a kill screen yet, so right now, a variable named “game over” sets to 1 and the game stops.

My issue is with the enemy spawning. I set it to before it clones itself, it will keep spawning in a random spot until it is not touching the border or the player. But it just ignores that for some reason and does it anyway. I test this by setting the “wait 3 seconds block” to 0 seconds so they can spawn and I do not move the player sprite at all. But an enemy always spawns on it. There are rare occasions where it reaches the clone limit before it spawns on the player sprite or the border, but those are rare.

Here is my game: https://scratch.mit.edu/projects/1088253138/

All I want you to do is tell me how I can keep it from ignoring me and not making it spawn on the border or the player sprite.

If you have any questions about how something works or where something is, please tell me. My code is not very complicated but I know where everything is.

If you want it to stop it from stopping the game when dead, remove the last if block from the player sprite.

The enemy sprite is where I want you to fix everything.

Thank you.
jonathasgmc32
Scratcher
30 posts

Enemy keeps spawning on player

The “hide” block causes interactions with the “touch?” block to always return false, subject to the conditions you set. One possible solution is to set a “100% ghost effect” while the main actor is shown, so that he will become invisible.

Another solution is to set the ghost effect block to “100%” as soon as the clone is created, make it show, change its position, and only after it is in the correct position, trigger the code to apply damage and set the ghost effect to 0%.

Last edited by jonathasgmc32 (Nov. 2, 2024 21:08:14)

Gamdapiko24
Scratcher
98 posts

Enemy keeps spawning on player

Thank you!!! That worked!

Powered by DjangoBB