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

#1 2012-07-24 09:29:11

jono3814
New Scratcher
Registered: 2012-07-18
Posts: 17

shooting...

my character needs to be able to shoot... how can i make him do that ? i want it so whenever i press space bar he will shoot...

also i want to know how another character can randomly shoot, but the bullets slowly randomly at times come towards the 1st character so he will have to dodge them.....

Offline

 

#2 2012-07-24 09:46:38

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

Re: shooting...

A script like this will shoot a bullet from the character:

when key [space v] pressed
go to [my character v]
point towards [mouse-pointer v]
show
repeat until <<touching [edge v]?> or <touching [enemy v]?>>
move (10) steps
end
hide
For shooting back:

when gf clicked
forever
hide
wait (pick random (2) to (4.5)) secs
go to [enemy v]
point towards [my character v]
show
repeat until <<touching [edge v]?> or <touching [my character v]?>>
move (10) steps
end


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

Offline

 

#3 2012-07-25 08:49:50

jono3814
New Scratcher
Registered: 2012-07-18
Posts: 17

Re: shooting...

For my character sprite why is it that i can only shot once and then it doesnt shoot again... how can i make it so whenever i press space bar he will shoot?

Offline

 

#4 2012-07-25 09:04:37

powerpoint56
Scratcher
Registered: 2012-04-19
Posts: 500+

Re: shooting...

Well, the issue is, there is only one sprite that is shooting. It will keep moving until it hits the edge or another sprite, then it will let you shoot. But while it's moving it won't let you. I suppose you could make a bunch of other bullets...

Edit: But the issue with that is that they'd all shoot at once if they all had the same script as MoreGamesNow...

Last edited by powerpoint56 (2012-07-25 09:06:13)


http://i48.tinypic.com/2072ctw.gif

Offline

 

#5 2012-07-25 10:30:35

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: shooting...

Here's are some scripts I made that would work:

Example:

when gf clicked
set [bullets? v] to [0]
forever
if < <key [space v] pressed> and <[bullets] < [4]>>
 change [bullets] by (1)
 wait until <not <key [space v] pressed> >
You can have [wait till space is not pressed], or you can have [wait 1 second].

Bullet 1:


when gf clicked
forever
if <(bullets?) = 1>
 go to [my character v]
 point towards [mouse-pointer v]
 show
  repeat until <<touching [edge v]?> or <touching [enemy v]?>>
  move (10) steps
  end
 change [bullets] by (-1)
end
hide
Bullet 2:


when gf clicked
forever
if <(bullets?) = 2>
 go to [my character v]
 point towards [mouse-pointer v]
 show
  repeat until <<touching [edge v]?> or <touching [enemy v]?>>
  move (10) steps
  end
 change [bullets] by (-1)
end
hide
Bullet 3:


when gf clicked
forever
if <(bullets?) = 3>
 go to [my character v]
 point towards [mouse-pointer v]
 show
  repeat until <<touching [edge v]?> or <touching [enemy v]?>>
  move (10) steps
  end
 change [bullets] by (-1)
end
hide
Bullet 4:


when gf clicked
forever
if <(bullets?) = 4>
 go to [my character v]
 point towards [mouse-pointer v]
 show
  repeat until <<touching [edge v]?> or <touching [enemy v]?>>
  move (10) steps
  end
 change [bullets] by (-1)
end
hide
I hope that this helps!

Last edited by ErnieParke (2012-07-25 10:48:19)


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2012-07-25 10:49:31

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

Re: shooting...

when gf clicked
set [bullet# v] to (0)
forever if <key [space v] pressed?>
broadcast (join[shoot](bullet#))
change [bullet# v] by (1)
set [bullet# v] to ((bullet#) mod (number of bullets you have))
wait (0.2) secs
Each bullet gets a script like the one below (but with "shoot" + bullet_number_of_sprite)

When I receive [shoot0 v]
go to [character v]
point towards [mouse-pointer v]
repeat until <touching [edge v]?>
move (5) steps
end
It should be noted that the longer your bullets, the faster you can shoot them without having them pass through something without touching it.

The exact number of bullets you'll need will vary based on bullet speed.  On the bright side, Scratch 2.0 will allow you to only use one bullet sprite (with cloning), though the script may become more complex.

Last edited by MoreGamesNow (2012-07-25 10:49:57)


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

Offline

 

#7 2012-07-29 19:18:56

maxamillion321
Scratcher
Registered: 2011-06-17
Posts: 500+

Re: shooting...

Make another sprite that's the missle. You'll have to hide the bullet first. Here's how you do it.
Missle:

<when[space bar]key pressed>
show
go to [Sprite 2 v]
Enemy:
when gf clicked
if <touching [Sprite 3]>
[(do other scripts you need to do here)]

Last edited by maxamillion321 (2012-07-29 19:42:28)

Offline

 

#8 2012-07-29 19:34:55

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: shooting...

Scratch seems to be cutting off part of the end my post when I put my message at the bottom of the quote, so I'm putting it up here:
Going to Sprite 2 will not work because of the fact that the player won't see the bullet going there, just that it suddenly appeared there, though this is a good idea!

maxamillion321 wrote:

Make another sprite that's the missle. You'll have to hide the bullet first. Here's how you do it.
Missle:

<when[space bar]key pressed>
show
go to [Sprite 2 v]
Enemy:
when gf clicked
if <touching [Sprite 3]>
[(do other scripts you need to do here)]
(do other scripts)

Last edited by ErnieParke (2012-07-29 19:38:35)


http://i46.tinypic.com/35ismmc.png

Offline

 

#9 2012-07-29 22:57:12

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: shooting...

There are more complex scripts, using 1s1s engines


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer