Parte wrote...
This is the player in my prepare
Player_Test1 player_test1 = new Player_Test1(movement_test21); addObject(player_test1,100,100);
Player_Test1 player_test1 = new Player_Test1(movement_test21); addObject(player_test1,100,100);
Player_Test1 player_test1 = new Player_Test1(movement_test21); addObject(player_test1,100,100);
if (player_test1.getWorld() != null)
if (player_test1.getWorld() != null)
public class Enemy_Test2 extends Animal { //instance fields /** * Assigns SimpleTimer the variable of timer to this class. */ private SimpleTimer timer = new SimpleTimer(); /** * turnPhase is assigned to hold a boolean value */ private boolean turnPhase; /** * phasteTimer is assigned to hold a numerical value of -1 */ private int phaseTimer = -1; /** * Actor is assigned to be the variable pursued */ private Actor pursued; /** * obstacleTimer is assigned to hold a numerical value */ private int obstacleTimer; /** * bulletTimer is assigned to hold a numerical value */ private int bulletTimer; private boolean rangeOccur; public void act() { if (getObjectsInRange(650, Player_Test1.class).isEmpty() && los.obstructedView(this, pursued, Walls.class)) { pursue(); } else { randomMovement(); } } /** * Method summary: This method makes this class move forward at a randomly selected distance then to stop for a randomly selected amount of time only then to instantly turn a random amount of degrees to then stop for a randomly selected amount of time to only move foward again a randomly selected distance (loop). This method also able to detect when this class is in contact with a wall, if this class is in contact with a wall the class will turn away from the wall. */ public void randomMovement() { // control code (when out of range of or path obstructed toward player) int sign = (int)Math.signum(phaseTimer); // '1' means moving or turning and '-1' means stopped after moving or turning phaseTimer -= sign; // step toward zero if (phaseTimer == 0) { if (sign == -1) { if (turnPhase) phaseTimer = 50+Greenfoot.getRandomNumber(400); else phaseTimer = 1; turnPhase = !turnPhase; } else { if (turnPhase) phaseTimer = -(50+Greenfoot.getRandomNumber(400)); else phaseTimer = -(50+Greenfoot.getRandomNumber(30)); } } if (sign > 0) { if (turnPhase) turn(Greenfoot.getRandomNumber(360)); else move(1); } if (atWorldEdge() || isTouching(Walls.class) || isTouching(BulletPassableWalls.class)) { turn(160+Greenfoot.getRandomNumber(180)-90); } } /** * Method summary: This method will get the coordinates of the pursued (Player_Test1.class) and will continuously turn towards those coordinates and move foward at a move speed of 2 and will execute the shoot method. This method also able to detect when this class is in contact with a wall, if this class is in contact with a wall the class will turn away from the wall. */ public void pursue() { int x = getX(), y = getY(); turnTowards(pursued.getX(), pursued.getY()); move(1); shoot(); if (atWorldEdge() || isTouching(Walls.class)) { turn(160+Greenfoot.getRandomNumber(180)-90); } if (isTouching(Walls.class) || isTouching(BulletPassableWalls.class)) { setLocation(x, y); } } /** * This method will execute the shootBullet method every 360 milliseconds that elapse and will play the sound "Pistol Shot.mp3" every time this happens. */ public void shoot() { if (timer.millisElapsed() >= 360) { shootBullet(); timer.mark(); Greenfoot.playSound("Pistol Shot.mp3"); } } /** * Method summary: This method spawns an Enemy_Bullet_Test1 class on this classes coordinates that is in the world and will rotate the Enemy_Bullet_Test1 class towards Player_Test1's coordinates. */ public void shootBullet() { Enemy_Bullet_Test1 enemy_bullet = new Enemy_Bullet_Test1(); enemy_bullet.setRotation(getRotation()); getWorld().addObject(enemy_bullet, getX(), getY()); } }
private SimpleTimer timer = new SimpleTimer(); private Actor pursued; private int bulletTimer;
public void act() { if (!getObjectsInRange(650, Player_Test1.class).isEmpty()) { if (pursued == null) { pursued = getObjectsInRange(650, Player_Test1.class).get(0); } if (!los.obstructedView(this, pursued, Walls.class)) { pursue(); } else { randomMovement(); } } else { pursued = null; randomMovement(); } }