Discuss Scratch

Banana_God
New to Scratch
4 posts

Need help with enemy cloning

I am learning to code with the book How to Code in 10 Easy Lessons. I am stuck building a platform game with cloning enemies. I followed the book, and made spiders, but they all just stack on top of each other (instead of showing up around the platforms), and they don't decrease the energy of the main sprite. Can someone tell me what I'm doing wrong?
Banana_God
New to Scratch
4 posts

Need help with enemy cloning

H4K
Scratcher
100+ posts

Need help with enemy cloning

replace this
when I start as a clone
change [enemy counter v] by (1)
go to x: (item (enemy counter) of [x start v] :: list) y: (item (enemy counter) of [y start v] :: list)
point in direction (-90 v)
show
go to front
forever
if <touching color [#003fff] ?> then
move (2) steps
if on edge, bounce
else
point in direction ((0) - (direction))
move (4) steps
end
if <touching [BananaGod v] ?> then
change [energy v] by (-10)
end
end

when green flag clicked
insert [-17] at (1 v) of [x start v]
insert [-159] at (1 v) of [y start v]
insert [-69] at (2 v) of [x start v]
insert [-42] at (2 v) of [y start v]
insert [-115] at (3 v) of [x start v]
insert [41] at (3 v) of [y start v]
insert [131] at (4 v) of [x start v]
insert [119] at (4 v) of [y start v]
set [enemy counter v] to [0]
set rotation style [left-right v]
set size to (20) %
hide
repeat (4)
create clone of [myself v]
end
with this
when I start as a clone
go to x: (item (enemy counter) of [x start v] :: list) y: (item (enemy counter) of [y start v] :: list)
point in direction (-90 v)
show
go to front
forever
change y by (-1)
if <touching color [#003fff] ?> then
move (2) steps
if on edge, bounce
else
point in direction ((0) - (direction))
move (4) steps
end
change y by (1)
if <touching [BananaGod v] ?> then
change [energy v] by (-10)
end
end

when green flag clicked
add [-17] to [x start v]
add [-159] to [y start v]
add [-69] to [x start v]
add [-42] to [y start v]
add [-115] to [x start v]
add [41] to [y start v]
add [131] to [x start v]
add [119] to [y start v]
set [enemy counter v] to [0]
set rotation style [left-right v]
set size to (20) %
hide
repeat (4)
change [enemy counter v] by (1)
create clone of [myself v]
end

My PC specs (for bugs & glitches):
- Intel Core i9-9980XE
- 64 GB DDR4-3200
- Nvidia GeForce RTX 2080 Ti (x2)

This is a signature










Last edited by Kaj (March 16, 2880 00:00:00)



















Banana_God
New to Scratch
4 posts

Need help with enemy cloning

Thanks for the solution for the cloning problem, but I still have a problem. The energy does not decrease when BananaGod is hit. If you can help i would appreciate it.
awesomeawesxomeman3
Scratcher
62 posts

Need help with enemy cloning

Banana_God wrote:

Thanks for the solution for the cloning problem, but I still have a problem. The energy does not decrease when BananaGod is hit. If you can help i would appreciate it.

this is because energy is a local variable. If you simpy recreate it and make sure that “For all sprites” is ticked, it will work

Banana_God
New to Scratch
4 posts

Need help with enemy cloning

Thanks for the solution. I really appreciate the help thanks.

Powered by DjangoBB