Discuss Scratch

_TheMonoCube
Scratcher
11 posts

My attacking engine for my tower defense sim game isn't working

So when one of the towers kill a enemy, they stop killing them. I don't know what is the problem, I've tried everything. https://scratch.mit.edu/projects/1378692221/ please help me out or remix it to fix the problem
Catscratcher07
Scratcher
1000+ posts

My attacking engine for my tower defense sim game isn't working

Your project is not shared.
_TheMonoCube
Scratcher
11 posts

My attacking engine for my tower defense sim game isn't working

Catscratcher07 wrote:

Your project is not shared.
oh shi mb
Catscratcher07
Scratcher
1000+ posts

My attacking engine for my tower defense sim game isn't working

Right now, your towers are only ever calculating the distance to and damaging the first enemy to spawn. Use a for loop to check the distance from each of the enemies, and set ClosestEnemyDist to the closest enemy's distance, while also storing the id of that enemy so your attack can target it specifically. Additionally, defeated enemies should have their x and y positions set to somewhere far offscreen; by blanking them, you are effectively setting them to x0 y0, resulting in towers close to that position attacking dead enemies.
_TheMonoCube
Scratcher
11 posts

My attacking engine for my tower defense sim game isn't working

Catscratcher07 wrote:

Right now, your towers are only ever calculating the distance to and damaging the first enemy to spawn. Use a for loop to check the distance from each of the enemies, and set ClosestEnemyDist to the closest enemy's distance, while also storing the id of that enemy so your attack can target it specifically. Additionally, defeated enemies should have their x and y positions set to somewhere far offscreen; by blanking them, you are effectively setting them to x0 y0, resulting in towers close to that position attacking dead enemies.
can you make a remix of this cause I don't know how to do ts
10goto10
Scratcher
1000+ posts

My attacking engine for my tower defense sim game isn't working

I remixed your project and added several in-line comments. https://scratch.mit.edu/projects/1378981579/

There are some new variables and some changes to the logic mentioned above and an extra check to skip the dead enemies. Some changes were also made to the enemy sprite to set good initial values for the positions and I removed the delete items from the lists. So, there are a lot of changes to look at.

Powered by DjangoBB