Discuss Scratch

bambamom
Scratcher
3 posts

Clones shooting projectiles

I've been making a new game, a simple shooter, mostly for the purpose of learning scratch. Its been going well, and there aren't too many bugs, but there is one serious problem. I have an enemy who keeps a safe distance from you and shoots at you, but there is a problem with the projectiles. Because this enemy is a clone, the bullet comes from the side of the screen, where I have the original copy hidden. When the clones open fire, the bullets come from the side of the screen, not the enemies. The separate sprite for the projectile does not know which units are clones, and spawns from the original.


How do I differentiate clones from each other, so that a different sprite can tell them apart, and interact with them separately?
deck26
Scratcher
1000+ posts

Clones shooting projectiles

Have a local variable CloneID which is changed (by the calling script) each time you create a clone. You can then check the value when doing anything with that clone. You can also use lists to store the x/y positions of the clones so you know where each one is. Each clone can tell if it is touching a sprite so you should be able to do what you want.
bambamom
Scratcher
3 posts

Clones shooting projectiles

deck26 wrote:

Have a local variable CloneID which is changed (by the calling script) each time you create a clone. You can then check the value when doing anything with that clone. You can also use lists to store the x/y positions of the clones so you know where each one is. Each clone can tell if it is touching a sprite so you should be able to do what you want.

I don't get what you are trying to say (I don't know what a calling script is, and google does not seem to yield an answer). I want to have clones shoot projectiles, and I sort of acheived this with two variables of the X and Y coordinates of the clones. BUT, that only works with one clone at a time. Could you explain how a CloneID changed by the calling script would work?
deck26
Scratcher
1000+ posts

Clones shooting projectiles

By the calling script I meant the script that creates the clone. If you have

setCloneIDto1 repeatcreatecloneofmyselfchangeCloneIDby1
with CloneID as a local variable then each clone gets a unique ID number. If you also have
whenIstartasacloneadd0to x-listadd0to y-list
then you've created lists to hold the x,y positions for the clones. So if CloneID=5 then item 5 of x-list will be the x-position of the clone. Obviously as the clone moves around you need to replace the items in the lists with the current values.

So that's how you keep track of the positions of the clones.

I'll look at the next stage in another post once I've had chance to think about it.
deck26
Scratcher
1000+ posts

Clones shooting projectiles

So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.

So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.

setindexto1 repeatuntilindex>lengthofx-listsetfirextoitemindexofx-list setfireytoitemindexofy-list fireabulletfromfirex,fireychangeindexby1

You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
joshyrooster
Scratcher
3 posts

Clones shooting projectiles

mousetouchingcolor?
joshyrooster
Scratcher
3 posts

Clones shooting projectiles

Sorry Just Testing something there^
joshyrooster
Scratcher
3 posts

Clones shooting projectiles

now im having the problem that i cant make the bullets go in the direction of my clone
deck26
Scratcher
1000+ posts

Clones shooting projectiles

joshyrooster wrote:

now im having the problem that i cant make the bullets go in the direction of my clone
Please don't practice Scratchblocks in a topic like this - there's a sticky topic at the top of the forum dedicated to trying out Scratchblocks.

You should really start your own topic. The easiest way to handle bullets is to make them clones of the thing firing them (even if they are also clones) so they inherit the direction and position.
LokoCoffee
Scratcher
3 posts

Clones shooting projectiles

deck26 wrote:

So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.

So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.

setindexto1 repeatuntilindex>lengthofx-listsetfirextoitemindexofx-list setfireytoitemindexofy-list fireabulletfromfirex,fireychangeindexby1

You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
So, you dont NEED firex and firey, so what do I put there instead ( This is from 2015 but I'm having the same problem )

Last edited by LokoCoffee (March 13, 2021 15:21:35)

LokoCoffee
Scratcher
3 posts

Clones shooting projectiles

I don't understand the list thing
ninjaMAR
Scratcher
1000+ posts

Clones shooting projectiles

LokoCoffee wrote:

deck26 wrote:

So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.

So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.

setindexto1 repeatuntilindex>lengthofx-listsetfirextoitemindexofx-list setfireytoitemindexofy-list fireabulletfromfirex,fireychangeindexby1

You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
So, you dont NEED firex and firey, so what do I put there instead ( This is from 2015 but I'm having the same problem )

LokoCoffee wrote:

I don't understand the list thing
Please don't necropost. If your having the same problem, make a new topic
LokoCoffee
Scratcher
3 posts

Clones shooting projectiles

ninjaMAR wrote:

LokoCoffee wrote:

deck26 wrote:

So how do we handle the firing. You don't say if they only fire when within a certain distance or all the time. I'll go for the latter for simplicity.

So in the bullet sprite you refer to each clone in turn. NB the x-list and y-list in my previous post need to be visible to all sprites.

setindexto1 repeatuntilindex>lengthofx-listsetfirextoitemindexofx-list setfireytoitemindexofy-list fireabulletfromfirex,fireychangeindexby1

You don't necessarily need the firex and firey variables; I just thought it made the explanation easier.
So, you dont NEED firex and firey, so what do I put there instead ( This is from 2015 but I'm having the same problem )

LokoCoffee wrote:

I don't understand the list thing
Please don't necropost. If your having the same problem, make a new topic
sorry I did not know that
Scratch-Bytes
Scratcher
12 posts

Clones shooting projectiles

You can also do this by the enemies temporarily setting an ‘I am a bullet’ variable, and spawning a clone of themselves, then setting it back.

It does mean your enemy code now has to act like an enemy, and a bullet but if everything runs from a single ‘when I start as a clone’ cap, it's not too bad to just do an ‘if I am a bullet … else …’ block.

Unfortunately it's not easy to convince young scratchers that the (initially) much more complicated new-bullet-list clone message queue method is a better way than this hack.

Last edited by Scratch-Bytes (Oct. 15, 2023 04:37:41)

BladiPetrov
Scratcher
100+ posts

Clones shooting projectiles

I'll make this clear. I didn't understand anything above. OK so the enemies' code when shooting will be this:

......... Code before shooting. . . Code before shootingsetshot xtoxpositionsetshot ytoypositionbroadcastshoot. . . Code after shooting (if there is)

The bullet's code will be:

whenIreceiveshootgotox:shotxy:shotycreatecloneofmyselfwhenIstartasaclonepointtowardsplayer Or whatever. . . Bullet movement code and other things
deck26
Scratcher
1000+ posts

Clones shooting projectiles

BladiPetrov wrote:

I'll make this clear. I didn't understand anything above. OK so the enemies' code when shooting will be this:

......... Code before shooting. . . Code before shootingsetshot xtoxpositionsetshot ytoypositionbroadcastshoot. . . Code after shooting (if there is)

The bullet's code will be:

whenIreceiveshootgotox:shotxy:shotycreatecloneofmyselfwhenIstartasaclonepointtowardsplayer Or whatever. . . Bullet movement code and other things
Please create your own new topic - you can refer to this one if necessary. many people won't read as far as your post, just respond to the original question so having your own topic makes it more likely the responses are to your post.
HugoThePelican
Scratcher
38 posts

Clones shooting projectiles

use some lists

addxpositiontolistaddypositiontolistadddirectiontolist
gotox:item1oflisty:item2oflist)pointindirectionitem3oflist

Powered by DjangoBB