From f67a2573a967b7031d5c655dcfb6e89e646851ba Mon Sep 17 00:00:00 2001 From: Sosch Date: Tue, 4 Nov 2014 10:01:13 +0100 Subject: [PATCH] =?UTF-8?q?Enemy=204=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spacescooter/entity/EnemyFour.java | 62 +++++++++++++++++++ .../spacescooter/screen/GameScreen.java | 9 +++ 2 files changed, 71 insertions(+) create mode 100644 src/de/teamteamteam/spacescooter/entity/EnemyFour.java diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyFour.java b/src/de/teamteamteam/spacescooter/entity/EnemyFour.java new file mode 100644 index 0000000..efddfde --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/EnemyFour.java @@ -0,0 +1,62 @@ +package de.teamteamteam.spacescooter.entity; + +import java.awt.Point; +import java.util.ArrayList; + +public class EnemyFour extends Enemy{ + + private ArrayList 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 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(); + } + } + +} diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 6d8d718..7aef9ad 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -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 points = new ArrayList(); + 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));