Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help with enemy cloning
- 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?
- H4K
- Scratcher
100+ posts
Need help with enemy cloning
replace this
when I start as a clonewith this
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
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
- 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
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.
- Discussion Forums
- » Help with Scripts
- » Need help with enemy cloning