diff --git a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java index db85bfd..7f15103 100644 --- a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java @@ -1,6 +1,5 @@ package de.teamteamteam.spacescooter.entity; - public abstract class CollidableEntity extends Entity implements Collidable{ public CollidableEntity(int x, int y) { diff --git a/src/de/teamteamteam/spacescooter/entity/Entity.java b/src/de/teamteamteam/spacescooter/entity/Entity.java index a087808..21cb79a 100644 --- a/src/de/teamteamteam/spacescooter/entity/Entity.java +++ b/src/de/teamteamteam/spacescooter/entity/Entity.java @@ -1,5 +1,8 @@ package de.teamteamteam.spacescooter.entity; +import java.awt.Graphics; +import java.awt.image.BufferedImage; + public abstract class Entity implements Updateable, Paintable { /** @@ -7,6 +10,7 @@ public abstract class Entity implements Updateable, Paintable { */ protected int x; protected int y; + private BufferedImage img; /** * Constructor. @@ -25,5 +29,20 @@ public abstract class Entity implements Updateable, Paintable { return this.y; } + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + } + public BufferedImage getImage() { + return this.img; + } + + public void setImage(BufferedImage img) { + this.img = img; + } + + public void paint(Graphics g) { + g.drawImage(this.img, this.x, this.y, null); + } } diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 792904e..3d2856b 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -1,6 +1,5 @@ package de.teamteamteam.spacescooter.entity; -import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.IOException; @@ -25,11 +24,9 @@ public class Player extends ShootingEntity { public Player(int x, int y) { super(x, y); - this.x = 200; - this.y = 300; - this.shootDelay = 40; - this.shootSpawnX = 32; - this.shootSpawnY = 16; + this.setImage(Player.img); + this.setShootDelay(40); + this.setShootSpawn(32, 16); } public void update() { @@ -52,10 +49,6 @@ public class Player extends ShootingEntity { } } - public void paint(Graphics g) { - g.drawImage(img, this.x, this.y, null); - } - public void collideWith(Collidable entity) { // TODO Auto-generated method stub diff --git a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java index dc4d757..5417d06 100644 --- a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java @@ -4,10 +4,10 @@ import de.teamteamteam.spacescooter.screen.Screen; public abstract class ShootingEntity extends LivingEntity { - protected int shootDelay; - protected int currentShootDelay; - protected int shootSpawnX; - protected int shootSpawnY; + private int shootDelay; + private int currentShootDelay; + private int shootSpawnX; + private int shootSpawnY; public ShootingEntity(int x, int y) { super(x, y); @@ -25,4 +25,13 @@ public abstract class ShootingEntity extends LivingEntity { this.currentShootDelay = this.shootDelay; } } + + public void setShootDelay(int shootDelay) { + this.shootDelay = shootDelay; + } + + public void setShootSpawn(int x, int y) { + this.shootSpawnX = x; + this.shootSpawnY = y; + } } diff --git a/src/de/teamteamteam/spacescooter/entity/Shot.java b/src/de/teamteamteam/spacescooter/entity/Shot.java index 139d85d..64bfeb2 100644 --- a/src/de/teamteamteam/spacescooter/entity/Shot.java +++ b/src/de/teamteamteam/spacescooter/entity/Shot.java @@ -8,11 +8,16 @@ public abstract class Shot extends CollidableEntity { protected int collisionCount; - public Shot(int x, int y, BufferedImage img) { - super(x - img.getWidth() / 2, y - img.getHeight() / 2); + public Shot(int x, int y) { + super(x, y); this.collisionCount = 1; } + public void setImage(BufferedImage img) { + super.setImage(img); + this.setPosition(this.x - this.getImage().getWidth() / 2, this.y - this.getImage().getHeight() / 2); + } + public void collideWith(Collidable entity) { this.collisionCount--; if(this.collisionCount == 0) { diff --git a/src/de/teamteamteam/spacescooter/entity/SingleShot.java b/src/de/teamteamteam/spacescooter/entity/SingleShot.java index d03deda..108bcab 100644 --- a/src/de/teamteamteam/spacescooter/entity/SingleShot.java +++ b/src/de/teamteamteam/spacescooter/entity/SingleShot.java @@ -1,6 +1,5 @@ package de.teamteamteam.spacescooter.entity; -import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; @@ -21,16 +20,12 @@ public class SingleShot extends Shot { public SingleShot(int x, int y) { - super(x, y, SingleShot.img); + super(x, y); + this.setImage(img); } public void update() { this.x += 2; } - public void paint(Graphics g) { - g.drawImage(SingleShot.img, this.x, this.y, SingleShot.img.getWidth(), SingleShot.img.getHeight(), null); - } - - }