This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-14 18:33:18

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Making sprite go to edge of screen

So, currently I'm designing a shooter game where you are fixed in the center of the field and you rotate to shoot at enemies. I want the enemies to appear from the edges of the screen and move towards the center, but I can't figure out how to make the enemy go to a random position on the edges of the screen.
Can anyone tell me how to do that?


Here's what my current script for the enemy is:

when gf clicked
hide
go to x: (pick random (-240) to (240)) y: ( ? )
Sorry if my question is confusing. Usually when I have questions like this, I think of them partly with words and partly with pictures, so it's hard to explain them fully in text.
(I need a screenshot function for my brain XP)

Last edited by Zangooser (2012-08-14 18:33:54)


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/O0efo.png&link2=http://i.imgur.com/B1KzK.png

Offline

 

#2 2012-08-14 18:34:55

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Making sprite go to edge of screen

Any position on the edge?


http://i47.tinypic.com/2iaa73k.png

Offline

 

#3 2012-08-14 18:36:21

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: Making sprite go to edge of screen

berberberber wrote:

Any position on the edge?

Yeah, any random position, as long as it's not in the middle of the screen.


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/O0efo.png&link2=http://i.imgur.com/B1KzK.png

Offline

 

#4 2012-08-14 18:46:05

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Making sprite go to edge of screen

Hmm...that IS hard...'course, I'm probably overcomplicating things.  tongue


http://i47.tinypic.com/2iaa73k.png

Offline

 

#5 2012-08-14 18:48:36

beyblade4
Scratcher
Registered: 2011-08-02
Posts: 1000+

Re: Making sprite go to edge of screen

I don't get it? Do you want them to appear from the left and right edges, from any edge, or what?


http://blocks.scratchr.org/API.php?user=beyblade4&action=projects&type=newest&return=image&num=NUMBER

Offline

 

#6 2012-08-14 18:54:32

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: Making sprite go to edge of screen

beyblade4 wrote:

I don't get it? Do you want them to appear from the left and right edges, from any edge, or what?

Any edge on the bottom, top, or side. They're all going to be going the same place (the middle), but I don't want them to all come from the same place, or else the player will eventually figure it out and will know where to aim each time.


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/O0efo.png&link2=http://i.imgur.com/B1KzK.png

Offline

 

#7 2012-08-14 18:59:40

beyblade4
Scratcher
Registered: 2011-08-02
Posts: 1000+

Re: Making sprite go to edge of screen

Zangooser wrote:

beyblade4 wrote:

I don't get it? Do you want them to appear from the left and right edges, from any edge, or what?

Any edge on the bottom, top, or side. They're all going to be going the same place (the middle), but I don't want them to all come from the same place, or else the player will eventually figure it out and will know where to aim each time.

Okay, I am a really good programmer (but not an expert yet), I will first have to do some experiments and get back to you on that, I have the idea but I need to test it out!


http://blocks.scratchr.org/API.php?user=beyblade4&action=projects&type=newest&return=image&num=NUMBER

Offline

 

#8 2012-08-14 19:06:31

beyblade4
Scratcher
Registered: 2011-08-02
Posts: 1000+

Re: Making sprite go to edge of screen

Here, this seems to work.

http://i46.tinypic.com/1rahc3.gif

or use this instead of When gf Clicked

when I receive [The Name of It v]

Last edited by beyblade4 (2012-08-14 19:09:07)


http://blocks.scratchr.org/API.php?user=beyblade4&action=projects&type=newest&return=image&num=NUMBER

Offline

 

#9 2012-08-14 19:58:54

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Making sprite go to edge of screen

Or, without variables:

when I receive [go to edge v]
if<(pick random (0) to (1)) = (0)>
go to x:(((pick random (0) to (1))*(480))-(240)) y:(pick random (-180) to (180))
else
go to x:(pick random (-180) to (180)) y:(((pick random (0) to (1))*(360))-(180))
end


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer