Discuss Scratch

merpderp123
Scratcher
64 posts

tower defence game needs help

I need to make my tower defence so the towers point towards the enemies in their shooting area. the towers are clones and the enemies are clones.
the project is called “coolio (full)” if you help and it works without changing most of the scripts you will get a follow from me

Last edited by merpderp123 (Aug. 10, 2016 23:33:41)

drmcw
Scratcher
1000+ posts

tower defence game needs help

One of the most commonly asked questions. A search would bring up plenty of results.

https://scratch.mit.edu/projects/18248372/
merpderp123
Scratcher
64 posts

tower defence game needs help

drmcw wrote:

One of the most commonly asked questions. A search would bring up plenty of results.

https://scratch.mit.edu/projects/18248372/
I cant search it doesn't work
drmcw
Scratcher
1000+ posts

tower defence game needs help

Well I gave a link to a solution as well.
merpderp123
Scratcher
64 posts

tower defence game needs help

drmcw wrote:

One of the most commonly asked questions. A search would bring up plenty of results.

https://scratch.mit.edu/projects/18248372/
I would need to change a lot of the scripts
merpderp123
Scratcher
64 posts

tower defence game needs help

drmcw wrote:

One of the most commonly asked questions. A search would bring up plenty of results.

https://scratch.mit.edu/projects/18248372/
its very confusing I cant tell witch scripts I need
drmcw
Scratcher
1000+ posts

tower defence game needs help

It's well commented and is there for understanding the method not just taking scripts. Basically using the fact that broadcasts are received by all clones, so can use a broadcast and get each clone to calculate which is closest to a certain point.
merpderp123
Scratcher
64 posts

tower defence game needs help

bump
Seahorse1998
Scratcher
4 posts

tower defence game needs help

Here's a tower defense game I made using clone towers and clone enemies: https://scratch.mit.edu/projects/49008862/
Basically I have the lead balloon save its coordinates, then a separate sprite called a target goes to those coordinates and the towers shoot at the target. Each balloon has its own variable called “progress.” The lead balloon has the greatest progress, and the code tells that balloon to save its coordinates. When the lead balloon is destroyed or reaches the end, the variable is also deleted so the target goes to the next lead balloon. Hope this helps!
ggenije
Scratcher
500+ posts

tower defence game needs help

It's very complicated (difficylity from 1 to 5 is 4.5(not 3D hah)!!!)you'll need :

enemy_counter (global) =1
enemy_ID(local)

on enemy:make clone of me:
set enemy_loading to 1(not very important in begginning if game is simple and fast)
when maked of clone_1:
enemy_ID=enemy_counter
enemy_counter++(increase by 1)
add enemy_x (start of map)
add enemy_y (start of map)
add enemy_alive(1)

make this for tower but
tower_counter (global) =1
tower_ID(local)
and same :

so now you have number for every clone

now add 3 lists
enemy_x (x coord of enemy)
enemy_y ( y coord of enemy)
enemy_alive(is enmey alive so does tower shot it)

and two lists
tower_x
tower_y

now you'll need local variable “target” so you find a target for tower
now for tower when is maked clone of him

Tip x^2 is x*x

target=0
(i=0
while not;(i>sizeof(enemy_x))
{
;i++
(pythagorins teorem if(x*x)+(y*y)>r*r)(r range of tower)
if((tower_x(ID)-enemy_x(i))^2+tower_y(ID)-enemy_y(i))^2>1024(for example bust be range^2))
{
target=i;
i=sizeof(enemy_x) this is to break loop

}
}

now

if(target!=0)not 0
{
point to (youllneed atan2 function for this)enemy_x(target) enemy_y target

}

now you'll need bullet so make tower->bullet list so you can transfer information of tower to bullet(x , y eventyally type of bullet and important TARGET)

list tower->bullet

when bullet maked as clone
go toX: tower->bullet(1)Y: tower->bullet(2)
and point to enemy_x(tower->bullet(3)) enemy_y(tower->bullet(3))
when(contact enemy)
{
enemy_hp(target)-=10 or what you want hp or else if you want like layers
enemy_recivedamage(target)=1
or destroy enemy
and then destroy bullet
}
AND that is what all you need for tower shoting an enemy
for enemy following path you''ned two lists of x and y of maps and local variable on enemy zone so enemy knows what point to point and move

Not simple???
This can be easy bugged if don't maked right like(forget to place target somoewhere or whatever)


Powered by DjangoBB