From de685366ee14409d52019e6eb4cadbebfb2b70d1 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 2 Dec 2014 11:07:26 +0100 Subject: [PATCH] Add damagable/vulnerable logic. Also, add the other Backgrounds to spawnable Entities and stuff. --- res/levels/test.level | 9 ++++--- .../spacescooter/entity/CollidableEntity.java | 25 ++++++++++++++++- .../spacescooter/entity/Entity.java | 2 +- .../spacescooter/entity/LivingEntity.java | 27 ++++++++++++++++++- .../spacescooter/entity/Obstacle.java | 25 +++++++++++++++++ .../spacescooter/entity/Player.java | 18 ++++++++----- .../spacescooter/entity/enemy/EnemyBoss.java | 1 - .../spacescooter/entity/enemy/EnemyFour.java | 1 - .../spacescooter/entity/enemy/EnemyOne.java | 1 - .../spacescooter/entity/enemy/EnemyThree.java | 1 - .../spacescooter/entity/enemy/EnemyTwo.java | 3 --- .../spacescooter/entity/spi/Collidable.java | 10 +++++++ .../spacescooter/level/Level.java | 8 ++++++ 13 files changed, 110 insertions(+), 21 deletions(-) create mode 100644 src/de/teamteamteam/spacescooter/entity/Obstacle.java diff --git a/res/levels/test.level b/res/levels/test.level index 2bcf5a3..136bdcc 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -1,13 +1,14 @@ + name:Testlevel \o/ backgroundMusic:music/ScooterFriendsTurbo8Bit.wav -background:StarBackground +background:CloudBackground - [0-4] -spawn:EnemyOne,1,1 +spawn:EnemyOne,1,5 [4-10] -spawn:EnemyTwo,2,10 +spawn:EnemyTwo,1,10 [10-25] spawn:EnemyThree,2,4 spawn:EnemyTwo,5,6 [25-30] -spawn:EnemyBoss,1,1 \ No newline at end of file +spawn:EnemyBoss,1,1 diff --git a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java index 917f8f0..9fb7712 100644 --- a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java @@ -16,14 +16,20 @@ public abstract class CollidableEntity extends Entity implements Collidable { * Whether or not this CollidableEntity can collide. */ private boolean canCollide; + + /** + * Whether this CollidableEntity will damage things it collides with. + */ + private boolean damaging; /** - * Default constructor. + * Default constructor. Initializes sane defaults. */ public CollidableEntity(int x, int y) { super(x, y); this.setCollide(true); + this.setDamaging(true); } @@ -60,7 +66,24 @@ public abstract class CollidableEntity extends Entity implements Collidable { * Get the current collision damage of the Entity. */ public int getCollisionDamage() { + if(!this.getDamaging()) return 0; return this.collisionDamage; } + /** + * Set whether the Collidable will damage things it hits. + * This defaults to true on construction and will only be changed manually. + */ + public void setDamaging(boolean damaging) { + this.damaging = damaging; + } + + /** + * Tell whether the Collidable will damage things it hits. + * This defaults to true on construction and will only be changed manually. + */ + public boolean getDamaging(){ + return this.damaging; + } + } diff --git a/src/de/teamteamteam/spacescooter/entity/Entity.java b/src/de/teamteamteam/spacescooter/entity/Entity.java index b1cb35d..0c4a037 100644 --- a/src/de/teamteamteam/spacescooter/entity/Entity.java +++ b/src/de/teamteamteam/spacescooter/entity/Entity.java @@ -27,7 +27,7 @@ public abstract class Entity implements Updateable, Paintable { */ public static enum availableNames { /* Backgrounds */ - StarBackground, + StarBackground, CloudBackground, EarthBackground, /* Enemies */ EnemyOne, EnemyTwo, EnemyThree, EnemyFour, /* Boss Enemies and belongings */ diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 0611b82..333ef33 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -41,12 +41,18 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable */ private int scorePoints; + /** + * Whether the LivingEntity will take damage. + */ + private boolean damagable; + /** - * Default constructor. + * Default constructor. Initializes sane defaults. */ public LivingEntity(int x, int y) { super(x, y); + this.setDamagable(true); } /** @@ -85,6 +91,9 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable * points. Triggers die() method on death. */ public void takeDamage(int damage) { + //Skip taking damage if not vulnerable. + if(!this.getVulnerable()) + return; // Skip everything if already dead. if (this.isAlive() == false) return; @@ -227,5 +236,21 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable public void setScore(int s) { this.scorePoints = s; } + + /** + * Set whether the LivingEntity is damagable. + * This defaults to true on construction and will only be changed manually. + */ + public void setDamagable(boolean damagable) { + this.damagable = damagable; + } + + /** + * Whether or not the LivingEntity is damagable. + * This defaults to true on construction and will only be changed manually. + */ + public boolean getVulnerable() { + return this.damagable; + } } diff --git a/src/de/teamteamteam/spacescooter/entity/Obstacle.java b/src/de/teamteamteam/spacescooter/entity/Obstacle.java new file mode 100644 index 0000000..10527ae --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/Obstacle.java @@ -0,0 +1,25 @@ +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 72d3305..357fff0 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -8,6 +8,7 @@ import de.teamteamteam.spacescooter.brain.GameConfig; 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.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.sound.SoundSystem; @@ -88,9 +89,9 @@ public class Player extends ShootingEntity implements KeyboardListener { //Collision cooldown handling if(this.currentCollisionCooldown > 0) { this.currentCollisionCooldown--; - if(this.currentCollisionCooldown == 0) { - this.setCollide(true); - } + } else { + this.setDamagable(true); + this.setDamaging(true); } int offset = 3; if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.getY() > 51) { @@ -128,15 +129,18 @@ public class Player extends ShootingEntity implements KeyboardListener { } super.paint(g); } - + /** - * Determine what will happen if a Player collides with an Item. + * Implement damage immunity logic after collisions with Enemy or Obstacle Entities. */ @Override public void collideWith(Collidable entity) { super.collideWith(entity); - this.setCollide(false); - this.currentCollisionCooldown = this.collisionCooldown; + if(this.currentCollisionCooldown == 0 && (entity instanceof Enemy || entity instanceof Obstacle)) { + this.currentCollisionCooldown = this.collisionCooldown; + this.setDamagable(false); + this.setDamaging(false); + } } /** diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java index de9a212..be39019 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java @@ -1,6 +1,5 @@ package de.teamteamteam.spacescooter.entity.enemy; -import de.teamteamteam.spacescooter.brain.GameConfig; import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion; import de.teamteamteam.spacescooter.gui.BossHealthBar; import de.teamteamteam.spacescooter.utility.Random; diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java index 4cfd6ff..1a2ddd2 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java @@ -30,7 +30,6 @@ public class EnemyFour extends Enemy{ this.points = points; this.x = x; this.y = y; - this.setCollisionDamage(this.getHealthPoints()); getNextPoint(); } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java index a4da967..978ec24 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java @@ -14,7 +14,6 @@ public class EnemyOne extends Enemy { this.setShootDamage(5); this.setCollisionDamage(5); this.setHealthPoints(5); - this.setCollisionDamage(this.getHealthPoints()); this.setScore(10); } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java index b455d63..435373e 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java @@ -1,6 +1,5 @@ package de.teamteamteam.spacescooter.entity.enemy; -import de.teamteamteam.spacescooter.brain.GameConfig; import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion; import de.teamteamteam.spacescooter.entity.item.Item; diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java index 65c3352..bdef067 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java @@ -1,8 +1,6 @@ package de.teamteamteam.spacescooter.entity.enemy; -import de.teamteamteam.spacescooter.brain.GameConfig; import de.teamteamteam.spacescooter.entity.explosion.ExplosionTwo; -import de.teamteamteam.spacescooter.utility.Random; public class EnemyTwo extends Enemy{ @@ -17,7 +15,6 @@ public class EnemyTwo extends Enemy{ this.setCollisionDamage(5); this.setHealthPoints(5); this.setScore(20); - this.setCollisionDamage(this.getHealthPoints()); } @Override diff --git a/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java b/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java index 1b71ce7..45202d5 100644 --- a/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java +++ b/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java @@ -40,4 +40,14 @@ public interface Collidable { * Set whether the Collidable is currently active. */ public void setCollide(boolean canCollide); + + /** + * Set whether the Collidable will damage things it hits. + */ + public void setDamaging(boolean damaging); + + /** + * Tell whether the Collidable will damage things it hits. + */ + public boolean getDamaging(); } diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index b9241ee..9f14892 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -1,5 +1,7 @@ package de.teamteamteam.spacescooter.level; +import de.teamteamteam.spacescooter.background.CloudBackground; +import de.teamteamteam.spacescooter.background.EarthBackground; import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.brain.GameConfig; import de.teamteamteam.spacescooter.entity.Entity; @@ -117,6 +119,12 @@ public final class Level { case StarBackground: new StarBackground(x, y); break; + case CloudBackground: + new CloudBackground(x, y); + break; + case EarthBackground: + new EarthBackground(x, y); + break; case EnemyOne: new EnemyOne(x, y); break;