I need help with my tower defense game

I am making a tower defense game I got the movement of the enemy down but I cant get the tower to work. My Project1-11-2022_16-38-18.wick

Your game looks good so far! If you want your tower to shoot enemies, you will need some basic trigonometry knowledge. It’s just useful for gamedev in general. Try looking up “sine and cosine”, and perhaps “polar coordinates”. This will be useful for telling how far away an enemy is, what direction the bullet should move etc.

You will also most likely want to learn about Javascript arrays, so that you can create a list of all your cloned enemys.

Let me know if you’ve got a more specific question.

I want the towers to wait a second and then shoot in a fixed position, example: the quad shooter waits 1 second and then shoots in a + shape.

Do you mean like this?

My Project1-18-2022_13-01-38.wick (5.6 KB)

It took me while to do because I forgot how to make it calculate pi so the thing shooting can rotate in the direction where the enemy is

It a bit laggy since I didnt make it if the bullets are out of the screen they disappear and also changed some code since I found some bugs and was to lazy to fix it ;-;

sort of, I meant that it shoots 4 bullets in each direction, not that the bullets move in a + shape

Ahh I see.

are you making the update?

So before we even spawn bullets, I fixed a bug in the clone code. Each clone of the tower was also creating a clone! They were just on top of each other, so you couldn’t see. I changed it to:

this.timer = 10
if (this.isClone) {
this.x = 341.842
this.y = 281.575
} else{
this.clone()
}

Then I put code, in the update for the tower, which spawns 4 bullets.

TowerDefenseExample1.wick (5.5 KB)

1 Like

now I cant get the bullets to hit the enemy and kill it. I think its something about that the bullets are clones and not the original. My Project1-18-2022_16-56-17.wick (6.4 KB)

You need to add each bullet to a collection, so that the enemy can test collision with every bullet.
To add bullets is something like:
cb = bullet.clone()
cb.x = this.x
cb.y = this.y
cb.right = true
project.bullets.push(cb)

And to test them all

function testHit(bullet){
if (e.hits(bullet)) {
e.hp -= 1
bullet.remove()
}
}

if (this.isClone) {
project.bullets.forEach(testHit)
}

I’m afraid you would need an array for enemies too.

wick doesn’t really have features to help easily manage duplicates of an object.

ok I will do that when I can (im on my alternate computor I dont have all my files (computor not profile))

I got the bullets killing the enemys but I cant get the enemys to turn My Project1-19-2022_10-03-10.wick

The clone of the enemy is no longer titled “e”, so you will likely need another array for enemies.

I found out that the problem was I typed it out wrong and it was trying to call the bullets an enemy. My Project1-21-2022_18-01-45.wick but now I found out that if you make multiple enemys it doesn’t make them turn.