From bc68de5b9918d6eb146eb91d188154fa9be670b3 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 2 Dec 2014 11:50:46 +0100 Subject: [PATCH] Add first obstacle as proof of concept. --- res/levels/test.level | 1 + .../spacescooter/entity/Entity.java | 2 ++ .../spacescooter/entity/LivingEntity.java | 5 ++++ .../spacescooter/entity/Obstacle.java | 25 ------------------ .../spacescooter/entity/Player.java | 1 + .../entity/obstacle/Obstacle.java | 14 ++++++++++ .../entity/obstacle/StoneOne.java | 26 +++++++++++++++++++ .../spacescooter/level/Level.java | 4 +++ 8 files changed, 53 insertions(+), 25 deletions(-) delete mode 100644 src/de/teamteamteam/spacescooter/entity/Obstacle.java create mode 100644 src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java create mode 100644 src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java diff --git a/res/levels/test.level b/res/levels/test.level index 136bdcc..f0e66df 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -5,6 +5,7 @@ background:CloudBackground - [0-4] spawn:EnemyOne,1,5 +spawn:StoneOne,4,5 [4-10] spawn:EnemyTwo,1,10 [10-25] diff --git a/src/de/teamteamteam/spacescooter/entity/Entity.java b/src/de/teamteamteam/spacescooter/entity/Entity.java index 0c4a037..5b053f8 100644 --- a/src/de/teamteamteam/spacescooter/entity/Entity.java +++ b/src/de/teamteamteam/spacescooter/entity/Entity.java @@ -34,6 +34,8 @@ public abstract class Entity implements Updateable, Paintable { EnemyBoss, EnemyBossMinion, /* Explosions */ ExplosionOne, ExplosionTwo, MultiExplosion, + /* Stones */ + StoneOne, /* Items */ ItemCredit, ItemHeal, ItemIncreaseDamage, ItemNuke, ItemOneUp, ItemRocket, ItemShield, } diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 333ef33..9def9ea 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -3,6 +3,7 @@ package de.teamteamteam.spacescooter.entity; import de.teamteamteam.spacescooter.brain.GameConfig; import de.teamteamteam.spacescooter.brain.PlayerSession; import de.teamteamteam.spacescooter.entity.enemy.Enemy; +import de.teamteamteam.spacescooter.entity.obstacle.Obstacle; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.entity.spi.Hittable; @@ -69,6 +70,10 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable return; this.takeDamage(s.getDamageValue()); } + if (entity instanceof Obstacle) { + Obstacle o = (Obstacle) entity; + this.takeDamage(o.getCollisionDamage()); + } if (entity instanceof Player && (!(this instanceof Player))) { Player player = (Player) entity; this.takeDamage(player.getCollisionDamage()); diff --git a/src/de/teamteamteam/spacescooter/entity/Obstacle.java b/src/de/teamteamteam/spacescooter/entity/Obstacle.java deleted file mode 100644 index 10527ae..0000000 --- a/src/de/teamteamteam/spacescooter/entity/Obstacle.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.teamteamteam.spacescooter.entity; - -import de.teamteamteam.spacescooter.entity.spi.Collidable; - -/** - * Obstacles are static or floating things that do damage on collision. - */ -public abstract class Obstacle extends CollidableEntity { - - public Obstacle(int x, int y) { - super(x, y); - } - - public void update() { - // TODO Auto-generated method stub - - } - - @Override - public void collideWith(Collidable entity) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 357fff0..8cb2e20 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -9,6 +9,7 @@ import de.teamteamteam.spacescooter.brain.PlayerSession; import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.KeyboardListener; import de.teamteamteam.spacescooter.entity.enemy.Enemy; +import de.teamteamteam.spacescooter.entity.obstacle.Obstacle; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.sound.SoundSystem; diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java b/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java new file mode 100644 index 0000000..0ce0457 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java @@ -0,0 +1,14 @@ +package de.teamteamteam.spacescooter.entity.obstacle; + +import de.teamteamteam.spacescooter.entity.CollidableEntity; + +/** + * Obstacles are static or floating things that do damage on collision. + */ +public abstract class Obstacle extends CollidableEntity { + + public Obstacle(int x, int y) { + super(x, y); + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java new file mode 100644 index 0000000..44cddd5 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java @@ -0,0 +1,26 @@ +package de.teamteamteam.spacescooter.entity.obstacle; + +import de.teamteamteam.spacescooter.entity.spi.Collidable; + +/** + * First proof of concept obstacle. + * A simple stone that moves to the left. + */ +public class StoneOne extends Obstacle { + + public StoneOne(int x, int y) { + super(x, y); + this.setImage("images/stones/stone01.png"); + this.setCollisionDamage(9001); + } + + public void update() { + this.transpose(-1, 0); + } + + @Override + public void collideWith(Collidable entity) { + + } + +} diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index 9f14892..7ebcb7c 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -10,6 +10,7 @@ import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss; import de.teamteamteam.spacescooter.entity.enemy.EnemyOne; import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo; +import de.teamteamteam.spacescooter.entity.obstacle.StoneOne; import de.teamteamteam.spacescooter.screen.GameScreen; import de.teamteamteam.spacescooter.sound.SoundSystem; import de.teamteamteam.spacescooter.utility.Loader; @@ -140,6 +141,9 @@ public final class Level { case EnemyBoss: new EnemyBoss(x, y); break; + case StoneOne: + new StoneOne(x, y); + break; default: System.err.println("I don't know how to spawn this: " + entity); break;