Gegner können sich jetzt bewegen
This commit is contained in:
@@ -2,12 +2,36 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
|
||||
public class Enemy extends Actor
|
||||
{
|
||||
int targetX;
|
||||
int targetY;
|
||||
|
||||
boolean targetReached = false;
|
||||
|
||||
int speed = 3;
|
||||
public Enemy (int targetX, int targetY) {
|
||||
this.targetX = targetX;
|
||||
this.targetY = targetY;
|
||||
}
|
||||
|
||||
int shootTimer;
|
||||
public void act()
|
||||
{
|
||||
shootAtPlayer();
|
||||
if (!targetReached){
|
||||
moveToTargetLocation(targetX, targetY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void moveToTargetLocation(int targetX, int targetY){
|
||||
double dx = targetX - getX();
|
||||
double dy = targetY - getY();
|
||||
double distance = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
||||
if (distance < 2){
|
||||
targetReached = true;
|
||||
}
|
||||
setLocation(getX() + (int)(dx/distance*speed), getY() + (int)(dy/distance*speed));
|
||||
}
|
||||
|
||||
public void shootAtPlayer(){
|
||||
shootTimer++;
|
||||
|
||||
Reference in New Issue
Block a user