Discuss Scratch

SnitchSpirit
Scratcher
24 posts

Clones as rewards

For my maze project, I am planning on adding golden coins as rewards. Since, I didn't want to replace them I was trying to create a clones randomly throughout the maze, Here is what I have so far: https://scratch.mit.edu/projects/260759781/#editor. I would appreciate some help.
cheesytoasties
Scratcher
80 posts

Clones as rewards

Well, Before you do that you should make sure the apple reappears after you hide it when the backdrop switches to “You Win!”. No idea on the whole cloning thing though…

Me in a nutshell?

Pfft, I don't think I'd fit…
Plus I'm allergic.

Wait, that's not what you meant?
Oh okay,
RokCoder
Scratcher
1000+ posts

Clones as rewards

You'd be better to check for collision with the apple in the clone code than the way round that you're doing it now. That way you can delete the clone when it's been collected. Also, your clones are currently hidden and you're creating way too many (as you'll see when you show them).


Scratch dabbling for fun…

-ShadowOfTheFuture-
Scratcher
1000+ posts

Clones as rewards

Not sure if there's something in particular that you need help with, but I'll try my best to give some help:

First of all, I'd suggest centering the coin's costume on the coin itself instead of a space that's far the the right of it. That way, you'll be able to position the coin way more accurately.

Also, I'm pretty sure you don't want the coin to keep spawning clones forever. Instead of this:

when green flag clicked
wait (1) secs
forever
create clone of [myself v]
end

You probably want something more like this:

when green flag clicked
repeat () // how many clones do you want?
create clone of [myself v]
end

I noticed that the clone's position is randomized when it's created. I don't know if the clones are only supposed to spawn over half the screen, but if they aren't, you should probably change the “10” in the second blank of the first “pick random” block to “240”.

go to x: (pick random (-240) to (240)) y: (pick random (-180) to (180)) // -240 to 240 instead of -240 to 10

If the clones are supposed to go anywhere on the screen, you could even just use this block:

go to [random position v]

If you want the clones to be collectible, you'd need to put a <touching [apple v]?> statement under the “when I start as a clone” hat, so that the cloned coins can sense when the player is touching (collecting) them. (I'm fairly sure that sprites can't detect the clones of other sprites, someone correct me if I'm wrong on that). Then make the clone change the “rewards” variable and delete itself if it's touching the player.

You can do this one of two ways:

when I start as a clone // first way
... // other code
forever
if <touching [apple v]?> then
change [rewards v] by (1)
delete this clone
end
end

when I start as a clone // second way, I recommend
... // other code
wait until <touching [apple v]?>
change [rewards v] by (1)
delete this clone

I personally recommend the second way if the clones aren't going to do much else, because it might help reduce lag.

One other thing: you want the clones to show (so that 1. the player can see them, and 2. they can be collected), so you need to add a “show” block under “when I start as a clone”.

Some other things that're not related to the coin sprite:

I looked at your apple sprite and saw a ton of “when green flag clicked” statements scattered everywhere. Try condensing them all into one script under a single “when green flag clicked” block. That will make your code much more efficient and will prevent the need to click the green flag multiple times to get it to initialize properly.

when green flag clicked // you can combine your multiple scripts into one
...
forever
if <...> then
...
end
if <...> then
...
end
end

You also used a lot of “when () key pressed” hat blocks; a better way might be to instead use the <key [ v] pressed?> boolean, which is found in the blue sensing category and will make the apple's motion much smoother. The boolean also paves the way for you to improve your collision detection, which to put it bluntly is very glitchy.

if <key [ v] pressed?> then // gives you smoother motion
...
end

Finally, I'm not sure why you have the below script in the apple. It doesn't seem to do anything useful and only serves to hide the apple as soon as the game begins, thus rendering it unplayable, so I'd suggest getting rid of it.

when green flag clicked // useless script?
hide
forever
wait (1) secs
end

Of course, these are all just suggestions. Whether you choose to implement them is up to you.

Dear god this took me so long to type up

Hope this helped!

Last edited by -ShadowOfTheFuture- (Nov. 11, 2018 21:48:35)


<Insert uncreative signature here>









██       ██  ██            ██  ██       ██
██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
███ ███ ██ ████ ██ ███ ███
█████████ █████ █████ █████████

“Though the seasons come and go, and sunshine turns to snow, we will always have tomorrow up ahead.”
SnitchSpirit
Scratcher
24 posts

Clones as rewards

Thank you. I did want the apple and banana to hide during the You win page.
SnitchSpirit
Scratcher
24 posts

Clones as rewards

Thank you!

Powered by DjangoBB