Leichte Vereinfachung an der Entity-Api.

This commit is contained in:
Jan Philipp Timme 2014-10-28 15:15:21 +01:00
parent 4ebe78b848
commit 65a4d2a682
6 changed files with 44 additions and 24 deletions

View File

@ -1,6 +1,5 @@
package de.teamteamteam.spacescooter.entity;
public abstract class CollidableEntity extends Entity implements Collidable{
public CollidableEntity(int x, int y) {

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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);
}
}