Discuss Scratch

mr-dash332
Scratcher
21 posts

Enemy Spawning Code

So I want to make the enemy only spawn when the screen is at a certain position. I need it to be a range of positions. If you click on my enemy sprite I have were the range of Spawning should start. I can clarify something if you need me to.


Project:
https://scratch.mit.edu/projects/976234831/editor/
PhiPhenomenon
Scratcher
500+ posts

Enemy Spawning Code

You gave where the enemies should start spawning, but you don't have a limit to where they should stop. Should the enemies only spawn when the players are inside of the first room?

Anyway, here's what you can do with the limits you have right now:

when green flag clicked
forever
if <(Enemy SX) > [287]> then
show
else
hide
end
end
mr-dash332
Scratcher
21 posts

Enemy Spawning Code

Yeah they should only spawn one enemy one that red circle, but I want the enemy to also despawn if you get far enough away. In the variable “Enemy SX”
The “S” stands for screen and the "X stands for the X position of that enemy on the screen. So I want it to only spawn if the player can see the red circle. The red circle is just so I know where the enemy is going to spawn.
PhiPhenomenon
Scratcher
500+ posts

Enemy Spawning Code

mr-dash332 wrote:

Yeah they should only spawn one enemy one that red circle, but I want the enemy to also despawn if you get far enough away.
How far away should the player be? Can you give bounds to when the enemy should despawn?
mr-dash332
Scratcher
21 posts

Enemy Spawning Code

If the player leaves the room the enemy should despawn. I'm also thinking of moving the enemy to the center if it would make the spawning and despawning easier. (Also thank you so much for the help)
PhiPhenomenon
Scratcher
500+ posts

Enemy Spawning Code

The room where the enemy spawns has exits only on the left and right, so the Enemy SY variable won't need to be used. I approximate the left side of the room is SX = 700 and the right side is SX = 200. Of course, if you want to use your original number (SX = 287), you can do that too.

when green flag clicked
forever
if <<(Enemy SX) > [200]> and <(Enemy SX) < [700]>> then
show
else
hide
end
end

mr-dash332 wrote:

(Also thank you so much for the help)

Last edited by PhiPhenomenon (March 6, 2024 23:46:51)

mr-dash332
Scratcher
21 posts

Enemy Spawning Code

OK that's super helpful. Ill see if it works.
mr-dash332
Scratcher
21 posts

Enemy Spawning Code

How would I make it scroll with the background while going after the player
PhiPhenomenon
Scratcher
500+ posts

Enemy Spawning Code

mr-dash332 wrote:

How would I make it scroll with the background while going after the player
What do you mean? Currently, it's just a circle that shows up on the screen.
mr-dash332
Scratcher
21 posts

Enemy Spawning Code

I want it to go to the red circle and forever go after the player. I want it to move at half the speed as the player.
PhiPhenomenon
Scratcher
500+ posts

Enemy Spawning Code

Your enemy sprite variables seem to be inconsistent with how the other variables, like Player X and SCROLL X, work. I'm going to make two new variables Enemy X and Enemy Y so it'll be easier to work with.

mr-dash332 wrote:

I want it to go to the red circle and forever go after the player. I want it to move at half the speed as the player.

Sorry for the big image. Exported directly from the editor because I didn't wanna write scratchblocks. You can change how fast the enemy moves by editing the numbers next to the sine and cosine.
mr-dash332
Scratcher
21 posts

Enemy Spawning Code

I'm doing this on my school computer so I cant even see the image. Don't know why they have it blacked out
mr-dash332
Scratcher
21 posts

Enemy Spawning Code

I understand being too lazy to write scratch blocks.
grasblok
Scratcher
1 post

Enemy Spawning Code

qferyegfeiujtvgFYadugqh2diudfghizds rhuygu skiJW
Respwan if stRTA PRAESEad
rehagygv
enter
wehgyuahhhjhcjka
<trdtrcjnbgc>
yt<yftsdftusrdfg765sdftrdrasduetsresxcrr424356.com.yt.com>
michaeljackson1365
Scratcher
1000+ posts

Enemy Spawning Code

grasblok wrote:

qferyegfeiujtvgFYadugqh2diudfghizds rhuygu skiJW
Respwan if stRTA PRAESEad
rehagygv
enter
wehgyuahhhjhcjka
<trdtrcjnbgc>
yt<yftsdftusrdfg765sdftrdrasduetsresxcrr424356.com.yt.com>
Sorry, you've necroposted.

Powered by DjangoBB