I've been working on a tower defense game, and I seem to be having trouble while working on area damage.
I have a method in the enemy class that takes away health, and I want to call it from every enemy in range to a specific tower.
enemy class method:
tell me if you need more code from the enemy class
attempt at area damage in tower class:
I don't know how to explain it but it just doesn't work
It's supposed to hurt all enemies within the range every 2 seconds or so (however long the time variable takes to reach attackSpeed)
it doesn't seem to do that
public void hurt(int damage)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * WIP */ public class Crusher extends Tower { public static int cost = 25; public Crusher(){ super();//i dont think u have to worry about this, tell me if u need the Tower class code this.damage = 2; this.range = 75;//in pixels (might change it idk) this.attackSpeed = 4; } int time = (int)(attackSpeed*100); boolean spend = true; public void act() { /** only can be placed on path. * works like crusher from clash of clans builder base */ time--; List <Enemy> prox = getObjectsInRange(range, Enemy.class); if(time < attackSpeed){ Greenfoot.playSound("smash.mp3"); for(Enemy pie : prox){ pie.hurt(damage); } time = (int)(attackSpeed*100); } } } }