From 27f1f486d5602b691ec045bf12d05046dee4a910 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 28 Oct 2014 15:35:17 +0100 Subject: [PATCH] =?UTF-8?q?Enemies=20k=C3=B6nnen=20jetzt=20schie=C3=9Fen.?= =?UTF-8?q?=20Wir=20auch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spacescooter/entity/Enemy.java | 8 ++++++- .../spacescooter/entity/EnemyOne.java | 24 ++++++++++++++----- .../spacescooter/entity/Player.java | 4 +++- .../spacescooter/entity/ShootingEntity.java | 13 ++++++++-- .../spacescooter/entity/Shot.java | 16 +++++++++++-- .../spacescooter/entity/SingleShot.java | 8 ++----- .../spacescooter/screen/GameScreen.java | 5 ++++ 7 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/entity/Enemy.java b/src/de/teamteamteam/spacescooter/entity/Enemy.java index 5300ef2..7782d1b 100644 --- a/src/de/teamteamteam/spacescooter/entity/Enemy.java +++ b/src/de/teamteamteam/spacescooter/entity/Enemy.java @@ -1,9 +1,15 @@ package de.teamteamteam.spacescooter.entity; +import java.util.Random; + public abstract class Enemy extends ShootingEntity { public Enemy(int x, int y) { super(x, y); + Random r = new Random(); + this.name = "EnemyOne"; + this.willShoot = r.nextBoolean(); + this.setShootDirection(Shot.LEFT); } protected String name; @@ -11,7 +17,7 @@ public abstract class Enemy extends ShootingEntity { public void update() { super.update(); - if(willShoot) + if(willShoot == true) this.shoot(); } diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java index 59f375c..ccf246e 100644 --- a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java @@ -1,16 +1,28 @@ package de.teamteamteam.spacescooter.entity; -import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.IOException; + +import javax.imageio.ImageIO; public class EnemyOne extends Enemy { + private static BufferedImage img; + + static { + try { + img = ImageIO.read(Player.class.getClassLoader().getResourceAsStream("images/nyancat.png")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } public EnemyOne(int x, int y) { super(x, y); - } - - public void paint(Graphics g) { - // TODO Auto-generated method stub - + this.setImage(EnemyOne.img); + this.setShootSpeed(2); + this.setShootDelay(42); + this.setShootSpawn(0, 32); } @Override diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 3d2856b..416913c 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -27,8 +27,10 @@ public class Player extends ShootingEntity { this.setImage(Player.img); this.setShootDelay(40); this.setShootSpawn(32, 16); + this.setShootDirection(Shot.RIGHT); + this.setShootSpeed(2); } - + public void update() { super.update(); int off = 3; diff --git a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java index 5417d06..5e97f8e 100644 --- a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java @@ -8,10 +8,11 @@ public abstract class ShootingEntity extends LivingEntity { private int currentShootDelay; private int shootSpawnX; private int shootSpawnY; + private int shootDirection; + private int shootSpeed; public ShootingEntity(int x, int y) { super(x, y); - this.shootDelay = 10; this.currentShootDelay = 0; } @@ -21,11 +22,19 @@ public abstract class ShootingEntity extends LivingEntity { protected void shoot() { if(this.currentShootDelay == 0) { - Screen.currentScreen.addEntity(new SingleShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY)); + Screen.currentScreen.addEntity(new SingleShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY, this.shootDirection, this.shootSpeed)); this.currentShootDelay = this.shootDelay; } } + public void setShootDirection(int direction) { + this.shootDirection = direction; + } + + public void setShootSpeed(int speed) { + this.shootSpeed = speed; + } + public void setShootDelay(int shootDelay) { this.shootDelay = shootDelay; } diff --git a/src/de/teamteamteam/spacescooter/entity/Shot.java b/src/de/teamteamteam/spacescooter/entity/Shot.java index 64bfeb2..81e2208 100644 --- a/src/de/teamteamteam/spacescooter/entity/Shot.java +++ b/src/de/teamteamteam/spacescooter/entity/Shot.java @@ -4,12 +4,19 @@ import java.awt.image.BufferedImage; public abstract class Shot extends CollidableEntity { + public static final int RIGHT = 1; + public static final int LEFT= -1; + protected int damageValue; protected int collisionCount; + private int speed; + private int direction; - public Shot(int x, int y) { + public Shot(int x, int y, int shootDirection, int shootSpeed) { super(x, y); + this.direction = shootDirection; + this.speed = shootSpeed; this.collisionCount = 1; } @@ -21,11 +28,16 @@ public abstract class Shot extends CollidableEntity { public void collideWith(Collidable entity) { this.collisionCount--; if(this.collisionCount == 0) { - //scoot is over + //TODO: scoot is over } } public int getDamageValue() { return this.damageValue; } + + public void update() { + this.x += this.direction * this.speed; + } + } diff --git a/src/de/teamteamteam/spacescooter/entity/SingleShot.java b/src/de/teamteamteam/spacescooter/entity/SingleShot.java index 108bcab..956010f 100644 --- a/src/de/teamteamteam/spacescooter/entity/SingleShot.java +++ b/src/de/teamteamteam/spacescooter/entity/SingleShot.java @@ -19,13 +19,9 @@ public class SingleShot extends Shot { } - public SingleShot(int x, int y) { - super(x, y); + public SingleShot(int x, int y, int shootDirection, int shootSpeed) { + super(x, y, shootDirection, shootSpeed); this.setImage(img); } - - public void update() { - this.x += 2; - } } diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index e0f3c91..31a5b18 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -8,6 +8,7 @@ import java.util.LinkedList; import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.control.Keyboard; +import de.teamteamteam.spacescooter.entity.EnemyOne; import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Player; @@ -17,6 +18,10 @@ public class GameScreen extends Screen { super(parent); this.entities.add(new StarBackground(0, 0)); this.entities.add(new Player(200, 300)); + this.entities.add(new EnemyOne(650, 300)); + this.entities.add(new EnemyOne(450, 100)); + this.entities.add(new EnemyOne(750, 550)); + this.entities.add(new EnemyOne(150, 250)); } @Override