From e8400f4f346ecbf7750cf6aaf212f6b80c412dc3 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 2 Dec 2014 13:04:51 +0100 Subject: [PATCH] Add the other two Stones to the game. --- res/levels/test.level | 10 ++--- .../spacescooter/entity/Entity.java | 2 +- .../entity/obstacle/MovingObstacle.java | 41 +++++++++++++++++++ .../entity/obstacle/Obstacle.java | 10 +++++ .../entity/obstacle/StoneOne.java | 16 +------- .../entity/obstacle/StoneThree.java | 14 +++++++ .../entity/obstacle/StoneTwo.java | 14 +++++++ .../spacescooter/level/Level.java | 8 ++++ 8 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 src/de/teamteamteam/spacescooter/entity/obstacle/MovingObstacle.java create mode 100644 src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java create mode 100644 src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java diff --git a/res/levels/test.level b/res/levels/test.level index cfc2f15..a62365b 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -7,15 +7,15 @@ spawn:EnemyBoss,1,1,50 [1-2] spawn:StoneOne,2,1,0 spawn:StoneOne,2,1,10 -spawn:StoneOne,2,1,20 +spawn:StoneTwo,2,1,20 spawn:StoneOne,2,1,30 -spawn:StoneOne,2,1,40 +spawn:StoneTwo,2,1,40 spawn:EnemyOne,2,1,50 spawn:StoneOne,2,1,60 -spawn:StoneOne,2,1,70 +spawn:StoneThree,2,1,70 spawn:StoneOne,2,1,80 -spawn:StoneOne,2,1,90 -spawn:StoneOne,2,1,100 +spawn:StoneThree,2,1,90 +spawn:StoneThree,2,1,100 [2-4] spawn:EnemyOne,1,5,20 spawn:StoneOne,4,5,50 diff --git a/src/de/teamteamteam/spacescooter/entity/Entity.java b/src/de/teamteamteam/spacescooter/entity/Entity.java index 5b053f8..75f2fa0 100644 --- a/src/de/teamteamteam/spacescooter/entity/Entity.java +++ b/src/de/teamteamteam/spacescooter/entity/Entity.java @@ -35,7 +35,7 @@ public abstract class Entity implements Updateable, Paintable { /* Explosions */ ExplosionOne, ExplosionTwo, MultiExplosion, /* Stones */ - StoneOne, + StoneOne, StoneTwo, StoneThree, /* Items */ ItemCredit, ItemHeal, ItemIncreaseDamage, ItemNuke, ItemOneUp, ItemRocket, ItemShield, } diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/MovingObstacle.java b/src/de/teamteamteam/spacescooter/entity/obstacle/MovingObstacle.java new file mode 100644 index 0000000..6864d06 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/MovingObstacle.java @@ -0,0 +1,41 @@ +package de.teamteamteam.spacescooter.entity.obstacle; + +public abstract class MovingObstacle extends Obstacle { + + /** + * Delta the Obstacle moves at on X-Axis. + * Defaults to -1. + */ + private int xDelta; + + /** + * Delta the Obstacle moves at on Y-Axis. + * Defaults to 0. + */ + private int yDelta; + + + /** + * Default constructor. + */ + public MovingObstacle(int x, int y) { + super(x, y); + this.setMoveDeltas(-1, 0); + } + + /** + * Make the Obstacle move at its defined X- and Y-Delta. + */ + public void update() { + this.transpose(this.xDelta, this.yDelta); + } + + /** + * Set the deltas used to move this Obstacle. + */ + public void setMoveDeltas(int xDelta, int yDelta) { + this.xDelta = xDelta; + this.yDelta = yDelta; + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java b/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java index 0ce0457..ee1db86 100644 --- a/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/Obstacle.java @@ -1,6 +1,7 @@ package de.teamteamteam.spacescooter.entity.obstacle; import de.teamteamteam.spacescooter.entity.CollidableEntity; +import de.teamteamteam.spacescooter.entity.spi.Collidable; /** * Obstacles are static or floating things that do damage on collision. @@ -10,5 +11,14 @@ public abstract class Obstacle extends CollidableEntity { public Obstacle(int x, int y) { super(x, y); } + + /** + * Obstacles do not care about collisions. Mostly. + * Override this if you think different. + */ + @Override + public void collideWith(Collidable entity) { + + } } diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java index 44cddd5..034be47 100644 --- a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java @@ -1,12 +1,9 @@ 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. + * The first stone/meteor like object in the game! */ -public class StoneOne extends Obstacle { +public class StoneOne extends MovingObstacle { public StoneOne(int x, int y) { super(x, y); @@ -14,13 +11,4 @@ public class StoneOne extends Obstacle { this.setCollisionDamage(9001); } - public void update() { - this.transpose(-1, 0); - } - - @Override - public void collideWith(Collidable entity) { - - } - } diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java new file mode 100644 index 0000000..f1b92b4 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java @@ -0,0 +1,14 @@ +package de.teamteamteam.spacescooter.entity.obstacle; + +/** + * Yet another stony obstacle. + */ +public class StoneThree extends MovingObstacle { + + public StoneThree(int x, int y) { + super(x, y); + this.setImage("images/stones/stone03.png"); + this.setCollisionDamage(9001); + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java new file mode 100644 index 0000000..8392b9d --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java @@ -0,0 +1,14 @@ +package de.teamteamteam.spacescooter.entity.obstacle; + +/** + * Yet another stony obstacle. + */ +public class StoneTwo extends MovingObstacle { + + public StoneTwo(int x, int y) { + super(x, y); + this.setImage("images/stones/stone02.png"); + this.setCollisionDamage(9001); + } + +} diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index cb70067..0509123 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -11,6 +11,8 @@ 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.entity.obstacle.StoneThree; +import de.teamteamteam.spacescooter.entity.obstacle.StoneTwo; import de.teamteamteam.spacescooter.screen.GameScreen; import de.teamteamteam.spacescooter.sound.SoundSystem; import de.teamteamteam.spacescooter.utility.Loader; @@ -189,6 +191,12 @@ public final class Level { case StoneOne: new StoneOne(x, y); break; + case StoneTwo: + new StoneTwo(x, y); + break; + case StoneThree: + new StoneThree(x, y); + break; default: System.err.println("I don't know how to spawn this: " + entity); break;