Leichte Vereinfachung an der Entity-Api.
This commit is contained in:
parent
4ebe78b848
commit
65a4d2a682
|
@ -1,6 +1,5 @@
|
|||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
|
||||
public abstract class CollidableEntity extends Entity implements Collidable{
|
||||
|
||||
public CollidableEntity(int x, int y) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue