Enemy 4 eingefügt
This commit is contained in:
parent
964e684b9a
commit
f67a2573a9
62
src/de/teamteamteam/spacescooter/entity/EnemyFour.java
Normal file
62
src/de/teamteamteam/spacescooter/entity/EnemyFour.java
Normal file
@ -0,0 +1,62 @@
|
||||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EnemyFour extends Enemy{
|
||||
|
||||
private ArrayList<Point> points;
|
||||
private int index =0;
|
||||
private Point nextPoint;
|
||||
private double x;
|
||||
private double y;
|
||||
private double vektorX;
|
||||
private double vektorY;
|
||||
|
||||
public EnemyFour(int x, int y, ArrayList<Point> points) {
|
||||
super(x, y);
|
||||
this.setImage("images/nyancat.png");
|
||||
this.setShootSpeed(4);
|
||||
this.setShootDelay(42);
|
||||
this.setShootSpawn(-10, 10);
|
||||
this.setHealthPoints(5);
|
||||
this.points = points;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
getNextPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
this.x -= vektorX;
|
||||
this.y -= vektorY;
|
||||
this.setPosition((int)x, (int)y);
|
||||
|
||||
if(this.getX() == (int)nextPoint.getX() && this.getY() == (int)nextPoint.getY()){
|
||||
getNextPoint();
|
||||
}
|
||||
}
|
||||
|
||||
private void neuerVektor(){
|
||||
vektorX = (this.getX() - nextPoint.getX());
|
||||
vektorY = (this.getY() - nextPoint.getY());
|
||||
double laenge = Math.sqrt(this.vektorX * this.vektorX + this.vektorY * this.vektorY);
|
||||
vektorX = vektorX/laenge;
|
||||
vektorY = vektorY/laenge;
|
||||
}
|
||||
|
||||
private void getNextPoint(){
|
||||
try{
|
||||
nextPoint = points.get(index);
|
||||
index++;
|
||||
neuerVektor();
|
||||
System.out.println("neuer point");
|
||||
}catch(IndexOutOfBoundsException e){
|
||||
System.out.println("ich bin dann mal weg!!");
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
package de.teamteamteam.spacescooter.screen;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import de.teamteamteam.spacescooter.background.StarBackground;
|
||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||
import de.teamteamteam.spacescooter.entity.EnemyFour;
|
||||
import de.teamteamteam.spacescooter.entity.EnemyThree;
|
||||
import de.teamteamteam.spacescooter.entity.EnemyTwo;
|
||||
import de.teamteamteam.spacescooter.entity.Entity;
|
||||
@ -14,10 +17,16 @@ import de.teamteamteam.spacescooter.entity.Player;
|
||||
|
||||
public class GameScreen extends Screen {
|
||||
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
public GameScreen(Screen parent) {
|
||||
super(parent);
|
||||
points.add(new Point(300,300));
|
||||
points.add(new Point(600,100));
|
||||
points.add(new Point(0,500));
|
||||
this.entities.add(new StarBackground(0, 0));
|
||||
this.entities.add(new Player(200, 300));
|
||||
this.entities.add(new EnemyFour(800, 400, points));
|
||||
this.entities.add(new EnemyThree(650, 300));
|
||||
this.entities.add(new EnemyThree(450, 100));
|
||||
this.entities.add(new EnemyTwo(750, 550));
|
||||
|
Loading…
Reference in New Issue
Block a user