Enemy 2 und 3 eingefügt

This commit is contained in:
Sosch 2014-10-31 11:00:17 +01:00
parent 617d0c2da1
commit 7563048cca
3 changed files with 95 additions and 5 deletions

View File

@ -0,0 +1,55 @@
package de.teamteamteam.spacescooter.entity;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;
import de.teamteamteam.spacescooter.screen.Screen;
import de.teamteamteam.spacescooter.utility.GameConfig;
public class EnemyThree extends Enemy{
private double newY;
private double ySpeed = 0.4;
public EnemyThree(int x, int y) {
super(x, y);
Random random = new Random();
this.setImage("images/nyancat.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootSpawn(-10, 10);
this.setHealthPoints(5);
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
this.newY = this.getY();
}
@Override
public void update() {
super.update();
this.setPosition(this.getX()-1, this.getY());
if(this.getX() < 0-getWidth()){
this.remove();
Screen.currentScreen.addEntity(new EnemyThree(0, 0));
}
if(!this.isAlive()){
Screen.currentScreen.addEntity(new EnemyThree(0, 0));
}
LinkedList<Entity> list = Screen.currentScreen.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
Entity entity = i.next();
if(entity instanceof Player){
Player player = (Player) entity;
if(this.y < player.getY()){
this.newY += ySpeed;
this.setPosition(this.getX(), (int) newY);
}else if(this.y > player.getY()){
this.newY -= ySpeed;
this.setPosition(this.getX(), (int) newY);
}
}
}
}
}

View File

@ -0,0 +1,34 @@
package de.teamteamteam.spacescooter.entity;
import java.util.Random;
import de.teamteamteam.spacescooter.screen.Screen;
import de.teamteamteam.spacescooter.utility.GameConfig;
public class EnemyTwo extends Enemy{
public EnemyTwo(int x, int y) {
super(x, y);
Random random = new Random();
this.setImage("images/nyancat.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootSpawn(-10, 10);
this.setHealthPoints(5);
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
}
@Override
public void update() {
super.update();
this.setPosition(this.getX()-1, this.getY());
if(this.getX() < 0-getWidth()){
this.remove();
Screen.currentScreen.addEntity(new EnemyTwo(0, 0));
}
if(!this.isAlive()){
Screen.currentScreen.addEntity(new EnemyTwo(0, 0));
}
}
}

View File

@ -7,7 +7,8 @@ import java.util.LinkedList;
import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.EnemyOne; import de.teamteamteam.spacescooter.entity.EnemyThree;
import de.teamteamteam.spacescooter.entity.EnemyTwo;
import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.Player;
@ -17,10 +18,10 @@ public class GameScreen extends Screen {
super(parent); super(parent);
this.entities.add(new StarBackground(0, 0)); this.entities.add(new StarBackground(0, 0));
this.entities.add(new Player(200, 300)); this.entities.add(new Player(200, 300));
this.entities.add(new EnemyOne(650, 300)); this.entities.add(new EnemyThree(650, 300));
this.entities.add(new EnemyOne(450, 100)); this.entities.add(new EnemyThree(450, 100));
this.entities.add(new EnemyOne(750, 550)); this.entities.add(new EnemyTwo(750, 550));
this.entities.add(new EnemyOne(150, 250)); this.entities.add(new EnemyTwo(150, 250));
} }
@Override @Override