Discuss Scratch

Sloth_Windchimes
Scratcher
100+ posts

Aliens Firing (non-continuously), and stopping when killed.

My game= https://scratch.mit.edu/projects/239702178/#player

In this game I have figured out how to make the alien fire, stop firing and wait before firing again when it hits the laser cannon, and stop firing and wait before firing again when it hits the edge. After it does this when it hits the edge, it begins to fire continuously when it fires again if it doesn't hit the cannon. You may have to play the first level to know exactly what I'm talking about.

Also, I do not know how to make the alien stop firing once it is destroyed.

Thanks!
deck26
Scratcher
1000+ posts

Aliens Firing (non-continuously), and stopping when killed.

If you're going to ignore my advice on your other thread where I suggested making the alien bullets be clones of the aliens then you need a variable for each alien or a list to record which aliens are still alive. Then you can easily check whether a new bullet clone starting at that alien's position makes sense. At the moment you have no way for the bullets to know the alien has gone.

Your Firing custom block tells the bullet to repeatedly fire. Change the main script to this and get rid of the Firing custom block.

in pseudo code because I find it quicker

repeat until touching cannon
go to start position
wait random
show
repeat until touching cannon or touching edge
change y by -10
end
if touching (cannon)
your code here
end
if touching (edge)
hide
end
end
drchubbington
Scratcher
100+ posts

Aliens Firing (non-continuously), and stopping when killed.

deck26 wrote:

If you're going to ignore my advice on your other thread where I suggested making the alien bullets be clones of the aliens then you need a variable for each alien or a list to record which aliens are still alive. Then you can easily check whether a new bullet clone starting at that alien's position makes sense. At the moment you have no way for the bullets to know the alien has gone.

Your Firing custom block tells the bullet to repeatedly fire. Change the main script to this and get rid of the Firing custom block.

in pseudo code because I find it quicker

repeat until touching cannon
go to start position
wait random
show
repeat until touching cannon or touching edge
change y by -10
end
if touching (cannon)
your code here
end
if touching (edge)
hide
end
end

delete this clone

when green flag clicked
forever
Be awesome!
end
deck26
Scratcher
1000+ posts

Aliens Firing (non-continuously), and stopping when killed.

drchubbington wrote:

deck26 wrote:

If you're going to ignore my advice on your other thread where I suggested making the alien bullets be clones of the aliens then you need a variable for each alien or a list to record which aliens are still alive. Then you can easily check whether a new bullet clone starting at that alien's position makes sense. At the moment you have no way for the bullets to know the alien has gone.

Your Firing custom block tells the bullet to repeatedly fire. Change the main script to this and get rid of the Firing custom block.

in pseudo code because I find it quicker

repeat until touching cannon
go to start position
wait random
show
repeat until touching cannon or touching edge
change y by -10
end
if touching (cannon)
your code here
end
if touching (edge)
hide
end
end

delete this clone
Not sure that helps. Where are you suggesting that should go?
Sloth_Windchimes
Scratcher
100+ posts

Aliens Firing (non-continuously), and stopping when killed.

deck26 wrote:

drchubbington wrote:

deck26 wrote:

If you're going to ignore my advice on your other thread where I suggested making the alien bullets be clones of the aliens then you need a variable for each alien or a list to record which aliens are still alive. Then you can easily check whether a new bullet clone starting at that alien's position makes sense. At the moment you have no way for the bullets to know the alien has gone.

Your Firing custom block tells the bullet to repeatedly fire. Change the main script to this and get rid of the Firing custom block.

in pseudo code because I find it quicker

repeat until touching cannon
go to start position
wait random
show
repeat until touching cannon or touching edge
change y by -10
end
if touching (cannon)
your code here
end
if touching (edge)
hide
end
end

delete this clone
Not sure that helps. Where are you suggesting that should go?



Sorry… I wasn't attempting to ignore your advice I just didnt understand at all.
deck26
Scratcher
1000+ posts

Aliens Firing (non-continuously), and stopping when killed.

Sloth_Windchimes wrote:

Sorry… I wasn't attempting to ignore your advice I just didnt understand at all.
If a sprite has a costume that is a gun and another that is a bullet you can use cloneIDs to get the sprite to behave differently according to what type of object it is. That means you can get the gun (or clones of it) to create clones which are bullets.

The advantage is that the bullet is created at the same position as the gun that created it and pointing in the same direction so you don't have to try to work anything like that out as you would if the bullet is a separate sprite.

May seem beyond you at the moment but it's actual not that difficult.

Last edited by deck26 (Oct. 10, 2018 09:50:54)

Sloth_Windchimes
Scratcher
100+ posts

Aliens Firing (non-continuously), and stopping when killed.

Okay, yes I understand. Thanks!
Sloth_Windchimes
Scratcher
100+ posts

Aliens Firing (non-continuously), and stopping when killed.

deck26 wrote:

Sloth_Windchimes wrote:

Sorry… I wasn't attempting to ignore your advice I just didnt understand at all.
If a sprite has a costume that is a gun and another that is a bullet you can use cloneIDs to get the sprite to behave differently according to what type of object it is. That means you can get the gun (or clones of it) to create clones which are bullets.

The advantage is that the bullet is created at the same position as the gun that created it and pointing in the same direction so you don't have to try to work anything like that out as you would if the bullet is a separate sprite.

May seem beyond you at the moment but it's actual not that difficult.


Thing is, the way i have it now it fires and points in the right direction and everything works, I just don't know how to make it stop firing after one bullet and how to make it stop firing once the alien is dead.
deck26
Scratcher
1000+ posts

Aliens Firing (non-continuously), and stopping when killed.

Easiest option is probably to have a list with one item per alien. Set it to 1 initially but when each alien dies it resets the corresponding value to 0. The bullet clone then checks the list item corresponding to its value of alien_bullet_ID and only fires if it sees a 1.

Powered by DjangoBB