From e4ebc31a1b8c81234e9aba9b9ae50a2a3cb02356 Mon Sep 17 00:00:00 2001 From: Sosch Date: Tue, 25 Nov 2014 13:39:23 +0100 Subject: [PATCH] Add Beam (Button: x) --- res/images/shots/beam.png | Bin 0 -> 472 bytes .../spacescooter/entity/Player.java | 24 +++++++++++++++++- .../spacescooter/entity/ShootingEntity.java | 23 +++++++++++++++++ .../spacescooter/entity/enemy/Enemy.java | 6 ++++- .../spacescooter/entity/enemy/EnemyThree.java | 4 --- .../spacescooter/entity/enemy/EnemyTwo.java | 4 --- .../spacescooter/entity/shot/Beam.java | 19 ++++++++++++++ 7 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 res/images/shots/beam.png create mode 100644 src/de/teamteamteam/spacescooter/entity/shot/Beam.java diff --git a/res/images/shots/beam.png b/res/images/shots/beam.png new file mode 100644 index 0000000000000000000000000000000000000000..0d7834005a09a64b007700aaff9f2925f2b464ca GIT binary patch literal 472 zcmeAS@N?(olHy`uVBq!ia0y~yU{(OK12~v~WZsRoWFW;@9OUlAuEaktaqI0hLtX|34i>`$`=7frb0%v)T=rUofnmNI&=Jk7 z3<(<;7 0){ + this.shootBeam(); + } + } } } @@ -209,6 +219,10 @@ public class Player extends ShootingEntity implements KeyboardListener { return rocketAmount; } + public int getBeamAmount(){ + return beamAmount; + } + /** * Add one rocket. */ @@ -216,6 +230,10 @@ public class Player extends ShootingEntity implements KeyboardListener { rocketAmount++; } + public void addBeamAmount(){ + beamAmount++; + } + /** * Remove one rocket. */ @@ -223,4 +241,8 @@ public class Player extends ShootingEntity implements KeyboardListener { rocketAmount--; } + public void removeBeamAmount(){ + beamAmount--; + } + } diff --git a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java index 710e733..7d6dfea 100644 --- a/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/ShootingEntity.java @@ -1,5 +1,6 @@ package de.teamteamteam.spacescooter.entity; +import de.teamteamteam.spacescooter.entity.shot.Beam; import de.teamteamteam.spacescooter.entity.shot.Rocket; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.screen.GameScreen; @@ -34,6 +35,8 @@ public abstract class ShootingEntity extends LivingEntity { */ private int currentRocketDelay; + private int currentBeamDelay; + /** * The X delta to pass to the Shot, so it spawns at the * right position relative to the ShootingEntity. @@ -83,6 +86,7 @@ public abstract class ShootingEntity extends LivingEntity { public void update() { if(this.currentShootDelay > 0) this.currentShootDelay--; if(this.currentRocketDelay > 0) this.currentRocketDelay--; + if(this.currentBeamDelay > 0) this.currentBeamDelay--; } /** @@ -108,6 +112,15 @@ public abstract class ShootingEntity extends LivingEntity { } } + public void shootBeam() { + if(this.canShoot == true) { + if(this.currentBeamDelay == 0) { + this.createBeam(); + GameScreen.getPlayer().removeBeamAmount(); + this.currentBeamDelay = this.shootDelay; + } + } + } /** * Enable or disable the ShootingEntitys fire ability. */ @@ -220,5 +233,15 @@ public abstract class ShootingEntity extends LivingEntity { filename ); } + public void createBeam() { + new Beam( + this.getX() + this.shootSpawnX, + this.getY() + this.shootSpawnY, + this.shootDirection, + this.shootSpeed, + this.shootDamage, + this.primaryShotImage + ); + } } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java index a13e7b2..b710091 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java @@ -37,8 +37,12 @@ public abstract class Enemy extends ShootingEntity { */ public void update() { super.update(); - if(willShoot == true) + if(willShoot == true){ this.shoot(); + } + if(this.getX() < 0-getWidth()){ + this.remove(); + } } @Override diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java index 4a538d4..ca387c6 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java @@ -49,10 +49,6 @@ public class EnemyThree extends Enemy{ public void update() { super.update(); this.setPosition(this.getX()-1, this.getY()); - if(this.getX() < 0-getWidth()){ - this.remove(); - new EnemyThree(0, 0); - } Player player = GameScreen.getPlayer(); if(this.getY() < player.getY()){ this.newY += ySpeed; diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java index 5882cac..a2adec3 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java @@ -24,10 +24,6 @@ public class EnemyTwo extends Enemy{ public void update() { super.update(); this.setPosition(this.getX()-1, this.getY()); - if(this.getX() < 0-getWidth()){ - this.remove(); - new EnemyTwo(0, 0); - } if(!this.isAlive()){ new EnemyTwo(0, 0); } diff --git a/src/de/teamteamteam/spacescooter/entity/shot/Beam.java b/src/de/teamteamteam/spacescooter/entity/shot/Beam.java new file mode 100644 index 0000000..226bd1e --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/shot/Beam.java @@ -0,0 +1,19 @@ +package de.teamteamteam.spacescooter.entity.shot; + +public class Beam extends Shot{ + + int i =0; + + public Beam(int x, int y, int shootDirection, int shootSpeed, int damageValue, String filename) { + super(x, y-35, shootDirection, shootSpeed, damageValue, filename); + this.setImage("images/shots/beam.png"); + } + + @Override + public void update() { + i++; + if(i>100){ + this.remove(); + } + } +}