i have no clue why and its super annoying ;c
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList; /** * Write a description of class enemy here. * * @author (your name) * @version (a version number or a date) */ public class enemy extends Actor { boolean metlocation = false; int health = 100; String face = "front"; //punching stuff boolean hit = false; boolean punchready = true; int def_punch_Val = 10; int def_punch_Val2 = 20; int timer = def_punch_Val; int timer2 = def_punch_Val+10; public static int num = 0; int tempvalFrontX; int tempvalFrontY; boolean runonce = false; int downOG = 100; int downcounter = downOG; int moverCounter = 20; //combo int punchcombotimer = 20; int hitcounter = 0; boolean resethit = false; boolean hit_check1 = false; int timer3 = 20; boolean stopattack = false; //public ArrayList<object> storage = new ArrayList<object>(); //animation GifImage LeftWalk = new GifImage("enemy-wl.gif"); GifImage RightWalk = new GifImage("enemy-wr.gif"); /** * Act - do whatever the enemy wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setImage("hit-L.png"); getWorld().showText("moverCounter= "+moverCounter, 100, 100); getWorld().showText("hit= "+hit, 110, 100); getWorld().showText("x"+"left".equals(face), 110, 150); if(isTouching(fistHitbox.class)) { hit_check1 = true; stopattack = true; if (resethit == false){ hitcounter++; resethit = true; } }else{stopattack = false;} if (hit_check1 == true) { timer3--; if(timer3 <= 0) { if(isTouching(fistHitbox.class) == false) { hit_check1 = false; hitcounter = 0; resethit = false; timer3 = 20; hit = true; stopattack = false; } } } if(hit == false){ test2(1); } if(hit == true) { if (runonce == false){ //front tempvalFrontX = getX(); tempvalFrontY = getY(); runonce = true; } if("front".equals(face)){ setImage("hit-up.png"); punchready= false; if(moverCounter >= 0){ setLocation(getX(), getY()+3); moverCounter--; }else { setImage("down.png"); downcounter--; if(downcounter <= 0) { //reset stats for next punch health = health - 10; hit = false; downcounter= downOG; moverCounter = 20; runonce = false; } } } if("back".equals(face)){ punchready= false; setImage("hit-down.png"); if(moverCounter >= 0){ setLocation(getX(), getY()-3); moverCounter--; }else { setImage("down.png"); downcounter--; if(downcounter <= 0) { //reset stats for next punch health = health - 10; hit = false; downcounter= downOG; moverCounter = 20; runonce = false; } } } if("left".equals(face)){ setImage("hit-R.png"); punchready= false; if(moverCounter >= 0){ setLocation(getX()+3, getY()); moverCounter--; }else { setImage("down.png"); downcounter--; if(downcounter <= 0) { //reset stats for next punch health = health - 10; hit = false; downcounter= downOG; moverCounter = 20; runonce = false; } } } if("right".equals(face)){ setImage("hit-L.png"); punchready= false; if(moverCounter >= 0){ setLocation(getX()-3, getY()); moverCounter--; }else { setImage("down.png"); downcounter--; if(downcounter <= 0) { //reset stats for next punch health = health - 10; hit = false; downcounter= downOG; moverCounter = 20; runonce = false; } } } } if(health <= 0) { num = num + 1; getWorld().addObject(new deadgoon(), getX(), getY()); getWorld().removeObject(this); } } void punch() { if(punchready == true){ if("front".equals(face)){ getWorld().addObject(new enemypunch(), getX(), getY()-10); punchready = false; } if("back".equals(face)){ getWorld().addObject(new enemypunch(), getX(), getY()+10); punchready = false; } if("left".equals(face)){ getWorld().addObject(new enemypunch(), getX()+10, getY()); punchready = false; } if("right".equals(face)){ getWorld().addObject(new enemypunch(), getX()-10, getY()); punchready = false; } } if (punchready == false) { timer--; timer2--; if(timer<= 0) { if(getWorld().getObjects(enemypunch.class).size()>=1){ getWorld().removeObject(getWorld().getObjects(enemypunch.class).get(0)); } } if(timer2<=0) { //this is how long till next punch is thrown timer = def_punch_Val; timer2 = def_punch_Val2; punchready= true; } } } void test2(int speed) { //make sure no punches left after moving if(metlocation == false) { if(getWorld().getObjects(enemypunch.class).size()>=1){ if (Greenfoot.getRandomNumber(1) == 1 ) { getWorld().addObject(new health(), getX(), getY()); } getWorld().removeObject(getWorld().getObjects(enemypunch.class).get(0)); } } //moving if(isTouching(playerhitbox.class)) { metlocation = true; if (stopattack == false){ punch(); } setImage("hit.png"); getImage().scale(100, 100); } else{metlocation = false;} if(metlocation == false){ if(getWorld().getObjects(Player.class).get(0).getX() >= getX()) { move(speed); face = "right"; setImage(LeftWalk.getCurrentImage()); getImage().scale(100, 100); //getImage().scale(10, 10); } if(getWorld().getObjects(Player.class).get(0).getY() <= getY()) { setLocation(getX(), getY()-speed); face = "front"; setImage("front.png"); getImage().scale(100, 100); //getImage().scale(10, 10); } if(getWorld().getObjects(Player.class).get(0).getY() == getY()) { //metlocationx = true; } if(getWorld().getObjects(Player.class).get(0).getY() >= getY()) { setLocation(getX(), getY()+speed); face = "back"; setImage("back2.png"); getImage().scale(100, 100); //getImage().scale(10, 10); } if(getWorld().getObjects(Player.class).get(0).getX() <= getX()) { move(-speed); face = "left"; setImage(RightWalk.getCurrentImage()); getImage().scale(100, 100); //getImage().scale(10, 10); } } } }