Discuss Scratch

Daydreamin
New to Scratch
13 posts

General problems with my code

Hello guys,

I've been trying to make a “Space Invaders” themed game, but different in that there's not a set amount of enemies per line and column that drop down every once in awhile; I'm trying to make them spawn at different times and randomly so people don't know what to expect, and to speed it up so that the longer the game goes on the faster they begin to spawn and the harder it gets. I might possibly include a boss too depending on how everything works.


The problem I'm having right now is I have both my laser and the asteroid/giga (alien) set to delete themselves whenever they collide with each other, but sometimes when the laser collides with the asteroid, it goes straight through it instead of deleting them both, and the giga almost never disappears at all.
Would you guys be willing to lend me a hand with this? ;w;

As well, I was talking with my Comp.Science teacher about how to incorporate a fire rate so one could not hold down spacebar the entire game, but neither of us could figure out how to do it - would somebody know how to do that? I'm imagining the spaceship would only shoot a certain amount of times per second regardless of how much the spacebar is pressed down, but also no lag when firing.

If you could explain it to me as well, I'd greatly appreciate it. You can see I was fiddling around with fire rate in my scripts if you check, but I couldn't get it to work.

Daydreamin

Project URL: http://scratch.mit.edu/projects/12629803/
Daydreamin
New to Scratch
13 posts

General problems with my code

Also, I haven't filled out instructions yet because I'm not entirely done the game, but it's arrow keys to move and spacebar to shoot. I figured out velocity myself and am glad with that result
Centrifugal
Scratcher
500+ posts

General problems with my code

For fire rate…
When gf clicked
forever
if <key space pressed>
Insert whatever scripts you have for firing here
Wait (however many seconds you want before you can shoot again) secs
Helpful?

Last edited by Centrifugal (Sept. 30, 2013 00:50:39)


Settlers of Inland - Age of Ƭɍeasoƞ

Centrifugal
Scratcher
500+ posts

General problems with my code

For your second problem Giga is not sensing the lasers because she glides for 5 secs then checks then glides for another fives seconds and checks if the lasers are touching her - to fix this make a separate script for checking to see if the lasers have hit her and another for gliding. If Giga hides once a laser has hit people won't notice the gliding.

Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

The fire rate script makes sense, but when I input that on the page with the other button commands it makes the spaceship halt for one second whenever I press spacebar, and if I do it on the laser sprite script then it doesn't do anything. I tried moving my spaceship script over to the laser page and have it trigger there, but when I did that the spaceship didn't fire at all.

I'll try the second option you gave me right now.
Centrifugal
Scratcher
500+ posts

General problems with my code

Daydreamin wrote:

The fire rate script makes sense, but when I input that on the page with the other button commands it makes the spaceship halt for one second whenever I press spacebar, and if I do it on the laser sprite script then it doesn't do anything. I tried moving my spaceship script over to the laser page and have it trigger there, but when I did that the spaceship didn't fire at all.

I'll try the second option you gave me right now.
Simple fix - have the if space key pressed be a separate script - the wait one firerate delays the rest of the script it's attached to.

Last edited by Centrifugal (Sept. 30, 2013 01:14:30)


Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

I'm trying the second one but I can't get it to work as well. :'(

This is what I have so far:

On spaceship page:
If spacebar is pressed:
set shotX to x position
set shotY to Y position
create clone of sprite9 (laser sprite)


on laser page:

when I start as a clone
go to x: pick random -200 to 200 y: pick random 100 to 170
repeat until touching sprite9 (laser sprite)
show
glide 5 secs to x: ranpick dom -200 to 200 y: pick random 100 to 170j
forever
if touching sprite9 then
hide


I've tried moving around the forever block and no avail. Dx this is a lot harder than I imagined.
Centrifugal
Scratcher
500+ posts

General problems with my code

Daydreamin wrote:

I'm trying the second one but I can't get it to work as well. :'(

This is what I have so far:

On spaceship page:
If spacebar is pressed:
set shotX to x position
set shotY to Y position
create clone of sprite9 (laser sprite)


on laser page:

when I start as a clone
go to x: pick random -200 to 200 y: pick random 100 to 170
repeat until touching sprite9 (laser sprite)
show
glide 5 secs to x: ranpick dom -200 to 200 y: pick random 100 to 170j
forever
if touching sprite9 then
hide


I've tried moving around the forever block and no avail. Dx this is a lot harder than I imagined.
I'm talking about the script on Giga - not on the laser

Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

Centrifugal wrote:

Daydreamin wrote:

The fire rate script makes sense, but when I input that on the page with the other button commands it makes the spaceship halt for one second whenever I press spacebar, and if I do it on the laser sprite script then it doesn't do anything. I tried moving my spaceship script over to the laser page and have it trigger there, but when I did that the spaceship didn't fire at all.

I'll try the second option you gave me right now.
Simple fix - have the if space key pressed be a separate script - the wait one firerate delays the rest of the script it's attached to.


OMG. How did I not think of this before?!?! Haha wow.
Daydreamin
New to Scratch
13 posts

General problems with my code

Centrifugal wrote:

Daydreamin wrote:

I'm trying the second one but I can't get it to work as well. :'(

This is what I have so far:

On spaceship page:
If spacebar is pressed:
set shotX to x position
set shotY to Y position
create clone of sprite9 (laser sprite)


on laser page:

when I start as a clone
go to x: pick random -200 to 200 y: pick random 100 to 170
repeat until touching sprite9 (laser sprite)
show
glide 5 secs to x: ranpick dom -200 to 200 y: pick random 100 to 170j
forever
if touching sprite9 then
hide


I've tried moving around the forever block and no avail. Dx this is a lot harder than I imagined.
I'm talking about the script on Giga - not on the laser

Whoops, I meant giga page, not laser script. That's so that giga floats around in the top part of the screen randomly. The laser (should) always go straight up.
Centrifugal
Scratcher
500+ posts

General problems with my code

Daydreamin wrote:

Centrifugal wrote:

Daydreamin wrote:

The fire rate script makes sense, but when I input that on the page with the other button commands it makes the spaceship halt for one second whenever I press spacebar, and if I do it on the laser sprite script then it doesn't do anything. I tried moving my spaceship script over to the laser page and have it trigger there, but when I did that the spaceship didn't fire at all.

I'll try the second option you gave me right now.
Simple fix - have the if space key pressed be a separate script - the wait one firerate delays the rest of the script it's attached to.


OMG. How did I not think of this before?!?! Haha wow.
Yeah, though bundling scripts can be efficient it's best to start with small individual scripts and then combine - glad to be useful

Settlers of Inland - Age of Ƭɍeasoƞ

Centrifugal
Scratcher
500+ posts

General problems with my code

when I start as a clone
go to x: pick random -200 to 200 y: pick random 100 to 170
repeat until touching sprite9 (laser sprite)
show
glide 5 secs to x: ranpick dom -200 to 200 y: pick random 100 to 170j your problem is that in the five seconds this is happening the sprite isn't
checking if it's hit.

forever
if touching sprite9 then
hide

Last edited by Centrifugal (Sept. 30, 2013 01:22:33)


Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

Centrifugal wrote:

when I start as a clone
go to x: pick random -200 to 200 y: pick random 100 to 170
repeat until touching sprite9 (laser sprite)
show
glide 5 secs to x: ranpick dom -200 to 200 y: pick random 100 to 170j your problem is that in the five seconds this is happening the sprite isn't
checking if it's hit.

forever
if touching sprite9 then
hide

Mhm. I thought by having a forever block underneath it or separated it it would solve the problem, but it didn't… Or would it work if I had the forever block encompassing what's underneath “When I start as a clone” block?
Centrifugal
Scratcher
500+ posts

General problems with my code

Daydreamin wrote:

Centrifugal wrote:

when I start as a clone
go to x: pick random -200 to 200 y: pick random 100 to 170
repeat until touching sprite9 (laser sprite)
show
glide 5 secs to x: ranpick dom -200 to 200 y: pick random 100 to 170j your problem is that in the five seconds this is happening the sprite isn't
checking if it's hit.

forever
if touching sprite9 then
hide

Mhm. I thought by having a forever block underneath it or separated it it would solve the problem, but it didn't… Or would it work if I had the forever block encompassing what's underneath “When I start as a clone” block?
Separate the forever if touching sprite9 then hide from the rest of the script and make it its own script.

Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

Do you mean this?

http://i.imgur.com/YQsE0Ki.png

^ that was unsuccessful so it must be something else you're referring to I guess
Centrifugal
Scratcher
500+ posts

General problems with my code

Daydreamin wrote:

Do you mean this?

http://i.imgur.com/YQsE0Ki.png

^ that was unsuccessful so it must be something else you're referring to I guess
? Actually that was what I meant… let me think a second

Last edited by Centrifugal (Sept. 30, 2013 01:41:25)


Settlers of Inland - Age of Ƭɍeasoƞ

Centrifugal
Scratcher
500+ posts

General problems with my code

Got it!!! Move the “show” out of the repeat until block and move it above it

Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

I thought what you said would work but it doesn't… asdf… does “touching sprite9” mean the same thing as “if it touched sprite9” ?
Centrifugal
Scratcher
500+ posts

General problems with my code

Daydreamin wrote:

I thought what you said would work but it doesn't… asdf… does “touching sprite9” mean the same thing as “if it touched sprite9” ?
DUH… My mistake (again) its not working cause' its touching a clone not a sprite- You can still use the touching color block to fix this- replace all instinces of touching sprite9 with if touching color (whatever color your laser is) BTW touching sprite9 only counts if the sprite is currently touching sprite9

Last edited by Centrifugal (Sept. 30, 2013 01:53:18)


Settlers of Inland - Age of Ƭɍeasoƞ

Daydreamin
New to Scratch
13 posts

General problems with my code

Alright, will try that. I wish it was easier to select colour though.

Powered by DjangoBB