diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java index a29b52c..7768516 100644 --- a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java @@ -23,6 +23,7 @@ public class EnemyOne extends Enemy { this.setShootSpeed(2); this.setShootDelay(42); this.setShootSpawn(-17, 32); + this.setHealthPoints(5); } @Override diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index cf17400..6e853ac 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -1,33 +1,76 @@ package de.teamteamteam.spacescooter.entity; +import java.awt.Rectangle; +import java.util.LinkedList; + import de.teamteamteam.spacescooter.screen.Screen; -public abstract class LivingEntity extends Entity { +public abstract class LivingEntity extends Entity implements Collidable { public LivingEntity(int x, int y) { super(x, y); } + private int collisionDamage; + + public Rectangle getCollisionBox() { + return new Rectangle(this.getX(), this.getY(), this.getWidth(), + this.getHeight()); + } + + public void update() { + if(!(this instanceof ShootingEntity)) return; //Only check collisions for ShootingEntity. + LinkedList entities = Screen.currentScreen.getEntities(); + for (Entity e : entities) { + if (e.equals(this)) //Do not collide with myself! + continue; + if(!(e instanceof Collidable)) //Do not collide with non-collidable! + continue; + Collidable ce = (Collidable) e; + if (ce.getCollisionBox().intersects(this.getCollisionBox())) { + this.collideWith(ce); + } + } + } + + /** + * Handle collisions based on what we collide with. + */ + public void collideWith(Collidable entity) { + + } + + public void setCollisionDamage(int d) { + this.collisionDamage = d; + } + + public int getCollisionDamage() { + return this.collisionDamage; + } + private int healthPoints; private int shieldPoints; - + public boolean isAlive() { return healthPoints > 0; } - + public void takeDamage(int damage) { - //TODO: shield and health logic + if(this instanceof Shot) { + System.out.println("Shot took damage: " + damage + "left: "+this.getHealthPoints()+" (" + this + ")"); + } + // TODO: shield and health logic this.healthPoints -= damage; - if(this.isAlive() == false) { + if (this.isAlive() == false) { System.out.println(this + " ist gestorben. RIP"); Screen.currentScreen.removeEntity(this); } } - + public void setHealthPoints(int hp) { this.healthPoints = hp; } - + public int getHealthPoints() { return this.healthPoints; } @@ -35,7 +78,7 @@ public abstract class LivingEntity extends Entity { public void setShieldPoints(int sp) { this.shieldPoints = sp; } - + public int getShieldPoints() { return this.shieldPoints; } diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 15ed84f..da1d66b 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -28,6 +28,7 @@ public class Player extends ShootingEntity { this.setShootSpawn(50, 16); this.setShootDirection(Shot.RIGHT); this.setShootSpeed(2); + this.setHealthPoints(100); } public void update() { diff --git a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java index 7066f6f..b1b6bac 100644 --- a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java @@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity; import de.teamteamteam.spacescooter.screen.Screen; -public abstract class ShootingEntity extends CollidableEntity { +public abstract class ShootingEntity extends LivingEntity { private int shootDelay; private int currentShootDelay; diff --git a/src/de/teamteamteam/spacescooter/entity/Shot.java b/src/de/teamteamteam/spacescooter/entity/Shot.java index 81e2208..aa777dc 100644 --- a/src/de/teamteamteam/spacescooter/entity/Shot.java +++ b/src/de/teamteamteam/spacescooter/entity/Shot.java @@ -2,12 +2,12 @@ package de.teamteamteam.spacescooter.entity; import java.awt.image.BufferedImage; -public abstract class Shot extends CollidableEntity { +public abstract class Shot extends LivingEntity { public static final int RIGHT = 1; public static final int LEFT= -1; - protected int damageValue; + private int damageValue; protected int collisionCount; private int speed; @@ -25,17 +25,14 @@ public abstract class Shot extends CollidableEntity { 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) { - //TODO: scoot is over - } - } - public int getDamageValue() { return this.damageValue; } + public void setDamageValue(int dmg) { + this.damageValue = dmg; + } + 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 956010f..bf321d2 100644 --- a/src/de/teamteamteam/spacescooter/entity/SingleShot.java +++ b/src/de/teamteamteam/spacescooter/entity/SingleShot.java @@ -22,6 +22,7 @@ public class SingleShot extends Shot { public SingleShot(int x, int y, int shootDirection, int shootSpeed) { super(x, y, shootDirection, shootSpeed); this.setImage(img); + this.setDamageValue(5); } }