diff --git a/res/sounds/bad_explosion1.wav b/res/sounds/bad_explosion1.wav new file mode 100644 index 0000000..115044f Binary files /dev/null and b/res/sounds/bad_explosion1.wav differ diff --git a/res/sounds/bad_explosion2.wav b/res/sounds/bad_explosion2.wav new file mode 100644 index 0000000..ffaff66 Binary files /dev/null and b/res/sounds/bad_explosion2.wav differ diff --git a/res/sounds/powerup_pickup.wav b/res/sounds/powerup_pickup.wav new file mode 100644 index 0000000..a1b7aba Binary files /dev/null and b/res/sounds/powerup_pickup.wav differ diff --git a/res/sounds/shot_hit_something.wav b/res/sounds/shot_hit_something.wav new file mode 100644 index 0000000..2adaa7b Binary files /dev/null and b/res/sounds/shot_hit_something.wav differ diff --git a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java new file mode 100644 index 0000000..5984cc0 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java @@ -0,0 +1,46 @@ +package de.teamteamteam.spacescooter.entity; + +import de.teamteamteam.spacescooter.entity.spi.Collidable; + +/** + * The CollidableEntity provides pure methods to handle collisions. + */ +public abstract class CollidableEntity extends Entity implements Collidable { + + /** + * Damage other LivingEntities take when colliding with this. + */ + private int collisionDamage; + + + /** + * Default constructor. + */ + public CollidableEntity(int x, int y) { + super(x, y); + } + + + /** + * Handle collisions based on what the LivingEntity collided with. + * Triggers damage calculations for itself only. + * Override to add specific behaviour, e.g. a Player picking up Items. + */ + public abstract void collideWith(Collidable entity); + + + /** + * Set the collision damage of the Entity. + */ + public void setCollisionDamage(int d) { + this.collisionDamage = d; + } + + /** + * Get the current collision damage of the Entity. + */ + public int getCollisionDamage() { + return this.collisionDamage; + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index de38a41..b800063 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -1,8 +1,7 @@ package de.teamteamteam.spacescooter.entity; -import java.awt.Rectangle; - import de.teamteamteam.spacescooter.datastructure.Score; + import de.teamteamteam.spacescooter.entity.enemy.Enemy; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; @@ -11,18 +10,13 @@ import de.teamteamteam.spacescooter.gui.Credits; import de.teamteamteam.spacescooter.utility.GameConfig; /** - * A LivingEntity is an Entity that is able to take damage. - * It can collide with other Collidable Entities. - * It knows about its collision box, which is based on width and height. - * Also, it contains the generic logic about health points and shield points and - * takes care of damage calculations. + * A LivingEntity is an Entity that is able to take damage and to collide with + * stuff. (See CollidableEntity) It can collide with other Collidable Entities. + * It knows about its collision box, which is based on width and height. Also, + * it contains the generic logic about health points and shield points and takes + * care of damage calculations. */ -public abstract class LivingEntity extends Entity implements Collidable, Hittable { - - /** - * Damage other LivingEntities take when colliding with this. - */ - private int collisionDamage; +public abstract class LivingEntity extends CollidableEntity implements Hittable { /** * The LivingEntities health points. @@ -35,7 +29,7 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl private int shieldPoints; /** - * The LivingEntities shield points. + * The score points awarded if the LivingEntity dies. */ private int ScorePoints; @@ -47,52 +41,30 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl super(x, y); } - /** - * Create a Rectangle containing all information to check for - * intersection with other Rectangles. - */ - public Rectangle getCollisionBox() { - return new Rectangle(this.getX(), this.getY(), this.getWidth(), - this.getHeight()); - } - - /** - * Handle collisions based on what the LivingEntity collided with. - * Triggers damage calculations for itself only. - * Override to add specific behaviour, e.g. a Player picking up Items. + * Handle collisions based on what the LivingEntity collided with. Triggers + * damage calculations for itself only. Override to add specific behaviour, + * e.g. a Player picking up Items. */ public void collideWith(Collidable entity) { - if(entity instanceof Shot) { + if (entity instanceof Shot) { Shot s = (Shot) entity; - if(this instanceof Enemy && s.getDirection() == Shot.LEFT) return; - if(this instanceof Player && s.getDirection() == Shot.RIGHT) return; + if (this instanceof Enemy && s.getDirection() == Shot.LEFT) + return; + if (this instanceof Player && s.getDirection() == Shot.RIGHT) + return; this.takeDamage(s.getDamageValue()); } - if(entity instanceof Player && (!(this instanceof Player))) { + if (entity instanceof Player && (!(this instanceof Player))) { Player player = (Player) entity; this.takeDamage(player.getCollisionDamage()); } - if(entity instanceof Enemy && (!(this instanceof Enemy))) { + if (entity instanceof Enemy && (!(this instanceof Enemy))) { Enemy enemy = (Enemy) entity; this.takeDamage(enemy.getCollisionDamage()); } } - /** - * Set the collision damage of the Entity. - */ - public void setCollisionDamage(int d) { - this.collisionDamage = d; - } - - /** - * Get the current collision damage of the Entity. - */ - public int getCollisionDamage() { - return this.collisionDamage; - } - /** * Determine whether the LivingEntity is still alive. */ @@ -101,37 +73,39 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl } /** - * Process incoming damage by calculating remaining health points - * and shield points. - * Also check for the need of triggering an explosion if dead. + * Process incoming damage by calculating remaining health points and shield + * points. Also check for the need of triggering an explosion if dead. */ public void takeDamage(int damage) { - //Skip everything if already dead. - if(this.isAlive() == false) return; + // Skip everything if already dead. + if (this.isAlive() == false) + return; // TODO: shield and health logic this.healthPoints -= damage; if (this.isAlive() == false) { - //Set the correct values for gui indicators + // Set the correct values for gui indicators this.healthPoints = 0; this.shieldPoints = 0; Score.addScore(ScorePoints); if(this instanceof Enemy){ // Add 1 credit for the shop Credits.setCredits(Credits.getCredits() + 1); } - if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP"); + if (GameConfig.DEBUG) + System.out.println(this + " ist gestorben. RIP"); this.die(); } } /** - * The default way the LivingEntity explodes. - * Override this method for a different explosion behaviour. + * The default way the LivingEntity explodes. Override this method for a + * different explosion behaviour. */ - public void explode() {} - + public void explode() { + } + /** - * The default way the LivingEntity dies. - * Override this method for a different death behaviour. + * The default way the LivingEntity dies. Override this method for a + * different death behaviour. */ public void die() { this.explode(); diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index f77c72c..3c060a0 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -4,7 +4,7 @@ import java.awt.event.KeyEvent; import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.KeyboardListener; -import de.teamteamteam.spacescooter.entity.item.Items; +import de.teamteamteam.spacescooter.entity.item.Item; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.sound.SoundSystem; @@ -57,13 +57,15 @@ public class Player extends ShootingEntity implements KeyboardListener { } } + /** + * Determine what will happen if a Player collides with an Item. + */ @Override public void collideWith(Collidable entity) { super.collideWith(entity); - if(this instanceof Player && entity instanceof Items){ - Items item = (Items) entity; - item.setHealthPoints(0); - item.remove(); + if(this instanceof Player && entity instanceof Item){ + //Item item = (Item) entity; + //Apply cool item effects here ... } } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java index 15e088f..d7f3b0f 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java @@ -6,7 +6,7 @@ import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator; import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion; -import de.teamteamteam.spacescooter.entity.item.Items; +import de.teamteamteam.spacescooter.entity.item.Item; import de.teamteamteam.spacescooter.screen.Screen; import de.teamteamteam.spacescooter.utility.GameConfig; @@ -39,7 +39,7 @@ public class EnemyThree extends Enemy{ */ @Override public void die() { - if(random.nextInt(10) < 5) Items.create(getX(), getY()); + if(random.nextInt(10) < 5) Item.create(getX(), getY()); new EnemyThree(0, 0); super.die(); } diff --git a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java index 0a21761..11619af 100644 --- a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java +++ b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java @@ -1,6 +1,7 @@ package de.teamteamteam.spacescooter.entity.explosion; import de.teamteamteam.spacescooter.entity.Animation; +import de.teamteamteam.spacescooter.sound.SoundSystem; public class ExplosionOne extends Animation { @@ -17,5 +18,6 @@ public class ExplosionOne extends Animation { }; this.configure(images, 10); this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + SoundSystem.playSound("sounds/bad_explosion1.wav"); } } diff --git a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java index 2121a3a..7ca3797 100644 --- a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java @@ -1,6 +1,7 @@ package de.teamteamteam.spacescooter.entity.explosion; import de.teamteamteam.spacescooter.entity.Animation; +import de.teamteamteam.spacescooter.sound.SoundSystem; public class ExplosionTwo extends Animation { @@ -26,6 +27,7 @@ public class ExplosionTwo extends Animation { }; this.configure(images, 10); this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + SoundSystem.playSound("sounds/bad_explosion2.wav"); } } diff --git a/src/de/teamteamteam/spacescooter/entity/item/Items.java b/src/de/teamteamteam/spacescooter/entity/item/Item.java similarity index 54% rename from src/de/teamteamteam/spacescooter/entity/item/Items.java rename to src/de/teamteamteam/spacescooter/entity/item/Item.java index be29048..47a3b04 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/Items.java +++ b/src/de/teamteamteam/spacescooter/entity/item/Item.java @@ -1,33 +1,43 @@ package de.teamteamteam.spacescooter.entity.item; import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator; +import de.teamteamteam.spacescooter.entity.CollidableEntity; import de.teamteamteam.spacescooter.entity.Entity; -import de.teamteamteam.spacescooter.entity.LivingEntity; import de.teamteamteam.spacescooter.entity.Player; +import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.screen.Screen; +import de.teamteamteam.spacescooter.sound.SoundSystem; -public abstract class Items extends LivingEntity { +public abstract class Item extends CollidableEntity { private ConcurrentIterator entityIterator; - public Items(int x, int y) { + + public Item(int x, int y) { super(x, y); - this.setHealthPoints(1); this.entityIterator = Screen.currentScreen.createEntityIterator(); } + /** + * If an item collides with a player, play the powerup pickup sound and remove the item. + */ + public void collideWith(Collidable entity) { + if(entity instanceof Player) { + SoundSystem.playSound("sounds/powerup_pickup.wav"); + this.remove(); + } + } + public void update(){ this.transpose(-1, 0); - if(this.getX() < 0-getWidth()){ + if(this.getX() < 0-this.getWidth()){ this.remove(); }; - if(!this.isAlive()){ - entityIterator.reset(); - while(entityIterator.hasNext()) { - Entity e = entityIterator.next(); - if(e instanceof Player){ - itemCollected((Player) e); - } + entityIterator.reset(); + while(entityIterator.hasNext()) { + Entity e = entityIterator.next(); + if(e instanceof Player){ + itemCollected((Player) e); } } } diff --git a/src/de/teamteamteam/spacescooter/entity/item/TestItem1.java b/src/de/teamteamteam/spacescooter/entity/item/TestItem1.java index ad83bcd..cd400b0 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/TestItem1.java +++ b/src/de/teamteamteam/spacescooter/entity/item/TestItem1.java @@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity.item; import de.teamteamteam.spacescooter.entity.Player; -public class TestItem1 extends Items{ +public class TestItem1 extends Item { public TestItem1(int x, int y) { super(x, y); @@ -13,4 +13,5 @@ public class TestItem1 extends Items{ public void itemCollected(Player player) { player.setShootDamage(player.getShootDamage()+5); } + } diff --git a/src/de/teamteamteam/spacescooter/entity/item/TestItem2.java b/src/de/teamteamteam/spacescooter/entity/item/TestItem2.java index c1eea28..3943e11 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/TestItem2.java +++ b/src/de/teamteamteam/spacescooter/entity/item/TestItem2.java @@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity.item; import de.teamteamteam.spacescooter.entity.Player; -public class TestItem2 extends Items{ +public class TestItem2 extends Item { public static int chance = 2; diff --git a/src/de/teamteamteam/spacescooter/entity/item/TestItem3.java b/src/de/teamteamteam/spacescooter/entity/item/TestItem3.java index 25e46a5..8ff86bd 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/TestItem3.java +++ b/src/de/teamteamteam/spacescooter/entity/item/TestItem3.java @@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity.item; import de.teamteamteam.spacescooter.entity.Player; -public class TestItem3 extends Items{ +public class TestItem3 extends Item { public static int chance = 3; diff --git a/src/de/teamteamteam/spacescooter/entity/item/TestItem4.java b/src/de/teamteamteam/spacescooter/entity/item/TestItem4.java index ed0ab14..7b4b390 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/TestItem4.java +++ b/src/de/teamteamteam/spacescooter/entity/item/TestItem4.java @@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity.item; import de.teamteamteam.spacescooter.entity.Player; -public class TestItem4 extends Items{ +public class TestItem4 extends Item { public static int chance = 4; diff --git a/src/de/teamteamteam/spacescooter/entity/shot/Shot.java b/src/de/teamteamteam/spacescooter/entity/shot/Shot.java index 913846f..256f770 100644 --- a/src/de/teamteamteam/spacescooter/entity/shot/Shot.java +++ b/src/de/teamteamteam/spacescooter/entity/shot/Shot.java @@ -1,9 +1,10 @@ package de.teamteamteam.spacescooter.entity.shot; -import de.teamteamteam.spacescooter.entity.LivingEntity; +import de.teamteamteam.spacescooter.entity.CollidableEntity; import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.enemy.Enemy; import de.teamteamteam.spacescooter.entity.spi.Collidable; +import de.teamteamteam.spacescooter.sound.SoundSystem; import de.teamteamteam.spacescooter.utility.GameConfig; /** @@ -11,7 +12,7 @@ import de.teamteamteam.spacescooter.utility.GameConfig; * It takes care of its movements, contains information about its * look and damage, and ends its life once it is out of the visible screen. */ -public class Shot extends LivingEntity { +public class Shot extends CollidableEntity { /** * Valid value for shootDirection parameter. @@ -97,8 +98,7 @@ public class Shot extends LivingEntity { public void collideWith(Collidable entity) { if(this.direction == LEFT && entity instanceof Enemy) return; if(this.direction == RIGHT && entity instanceof Player) return; - super.collideWith(entity); - this.explode(); + SoundSystem.playSound("sounds/shot_hit_something.wav"); this.remove(); }