Discuss Scratch

3ncrypt0s
Scratcher
6 posts

How can I check how many clones of a sprite are touching my enemy at any given time?

Hi, I'm currently making a tower defence game, and I'm working on some of the later levels. One of my towers is a laser tower and is essential in late-game survival. I want the damage from lasers to stack, but here's what I have right now in my main enemy loop:
if <touching [laser] ?> then
change [ health] by (-1)
end
(yes, I know there isn't a wait block, that was intentional)
If it touches one or no lasers, it works fine, but for more lasers, it still deals the same amount of damage.
How can I check how many clones of a sprite are touching my enemy at any given time?
TheAnomalousPseudo
Scratcher
1000+ posts

How can I check how many clones of a sprite are touching my enemy at any given time?

If you don't already have ID, make a “this sprite only” variable called “ID” and a global variable called “quantity.” Then, make a list to store whether it should take damage.

when green flag clicked
set [ID v] to (0)
set [quantity v] to (0)
delete all of [takeDamage v]
delete all of [cloneX v]
delete all of [cloneY v]
forever
if <(length of [takeDamage v]) < (quantity)> then
add () to [takeDamage v]
add () to [cloneX v]
add () to [cloneY v]
end
end

when I receive [spawnEnemy v]
if <(ID) = (0)> then
create clone of [myself v]
end

when I start as a clone
change [quantity v] by (1)
set [ID v] to (quantity)
forever
replace item (ID) of [cloneX v] with (x position)
replace item (ID) of [cloneY v] with (y position)
if <(item (ID) of [takeDamage v]) > (0))> then
take damage
replace item (ID) of [takeDamage v] with ((item (ID) of [takeDamage v]) - (1))
end

//then, for the laser:

repeat until <touching [enemy v]?>
move script
end
repeat (length of [takeDamage v] :: list)
set [foo v] to (1) //local
set [holdX v] to (500) //local
set [holdY v] to (500) //local
if <<([abs v] of ((item (foo) of [cloneX v] :: list) - (x position))) < (holdX)> and <([abs v] of ((item (foo) of [cloneY v] :: list) - (y position))) < (holdY)>> then
change [foo v] by (1)
end
end
replace item (foo) of [takeDamage v] with ((item (foo) of [takeDamage v]) + (1))
delete this clone

Last edited by TheAnomalousPseudo (May 19, 2021 23:22:52)



We ought to be careful with that octopus that takes over the servers. He's well armed.
The_Imaginarium
Scratcher
1000+ posts

How can I check how many clones of a sprite are touching my enemy at any given time?

Note: Click twice on the blocks and hold shift + right to see all of them
3ncrypt0s
Scratcher
6 posts

How can I check how many clones of a sprite are touching my enemy at any given time?

Thanks!

Powered by DjangoBB