Rename BossBar, tidy up lots of small things.

This commit is contained in:
Jan Philipp Timme 2014-11-28 23:16:56 +01:00
parent 3cf6b233ac
commit 982177c169
16 changed files with 109 additions and 73 deletions

View File

@ -39,15 +39,23 @@ public abstract class Entity implements Updateable, Paintable {
}
/**
* Entity position.
* Entity position x coordinate.
*/
private int x;
/**
* Entity position y coordinate.
*/
private int y;
/**
* Entity width and height.
* Entity width.
*/
private int width;
/**
* Entity height.
*/
private int height;
/**
@ -59,8 +67,6 @@ public abstract class Entity implements Updateable, Paintable {
*/
private BufferedImage img;
private boolean removed = false;
/**
* Constructor.
@ -170,21 +176,11 @@ public abstract class Entity implements Updateable, Paintable {
g.drawImage(this.img, this.x, this.y, null);
}
/**
* Returns Boolean If the Entity got Removed.
* @return removed
*/
public boolean isRemoved() {
return removed;
}
/**
* Removes entity from the game by telling the current Screen
* to remove it from its list.
*/
public void remove() {
this.removed = true;
Screen.currentScreen.removeEntity(this);
}
}

View File

@ -82,13 +82,12 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
/**
* Process incoming damage by calculating remaining health points and shield
* points. Also check for the need of triggering an explosion if dead.
* points. Triggers die() method on death.
*/
public void takeDamage(int damage) {
// Skip everything if already dead.
if (this.isAlive() == false)
return;
// TODO: shield and health logic
if (this.shieldPoints > 0) {
if (this.shieldPoints < damage) {
this.healthPoints = (damage - this.shieldPoints);
@ -103,12 +102,6 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
// Set the correct values for gui indicators
this.healthPoints = 0;
this.shieldPoints = 0;
PlayerSession.addScore(scorePoints);
if(this instanceof Enemy){ // Add 1 credit for the shop
PlayerSession.addCredits(1);
}
if (GameConfig.DEBUG)
System.out.println(this + " ist gestorben. RIP");
this.die();
}
}
@ -124,6 +117,10 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
* different death behaviour.
*/
public void die() {
if (GameConfig.DEBUG) {
System.out.println(this + " ist gestorben. RIP");
}
PlayerSession.addScore(scorePoints);
this.explode();
this.remove();
}

View File

@ -44,6 +44,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
this.setShootDirection(Shot.RIGHT);
this.setShootSpeed(10);
this.setCollisionDamage(10);
this.setScore(0);
this.setHealthPoints(PlayerSession.getShipHealthPoints());
this.setMaximumHealthPoints(PlayerSession.getShipHealthPoints());
this.setShieldPoints(PlayerSession.getShipShieldPoints());
@ -165,6 +166,18 @@ public class Player extends ShootingEntity implements KeyboardListener {
public void keyTyped(KeyEvent e) {}
@Override
public void createRocket() {
super.createRocket();
this.removeRocketAmount();
}
@Override
public void createBeam() {
super.createBeam();
this.removeBeamAmount();
}
/**
* Get the current rocket amount.
*/

View File

@ -3,7 +3,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;
/**
* The ShootingEntity is a LivingEntity that is able to fire Shots.
@ -35,6 +34,10 @@ public abstract class ShootingEntity extends LivingEntity {
*/
private int currentRocketDelay;
/**
* The current tick delay to wait until the next Beam can be fired.
* This value is used to enforce the actual delay defined in shootDelay.
*/
private int currentBeamDelay;
/**
@ -106,7 +109,6 @@ public abstract class ShootingEntity extends LivingEntity {
if(this.canShoot == true) {
if(this.currentRocketDelay == 0) {
this.createRocket();
GameScreen.getPlayer().removeRocketAmount();
this.currentRocketDelay = this.shootDelay*2;
}
}
@ -116,7 +118,6 @@ public abstract class ShootingEntity extends LivingEntity {
if(this.canShoot == true) {
if(this.currentBeamDelay == 0) {
this.createBeam();
GameScreen.getPlayer().removeBeamAmount();
this.currentBeamDelay = this.shootDelay*2;
}
}
@ -209,40 +210,46 @@ public abstract class ShootingEntity extends LivingEntity {
);
}
/**
* Internal method to actually spawn a fired rocket.
*/
public void createRocket() {
new Rocket(
this.getX() + this.shootSpawnX,
this.getY() + this.shootSpawnY,
this.shootDirection,
this.shootSpeed,
(int)(this.shootDamage*1.2),
this.primaryShotImage
);
this.getX() + this.shootSpawnX,
this.getY() + this.shootSpawnY,
this.shootDirection,
this.shootSpeed,
(int) (this.shootDamage*1.2),
this. primaryShotImage
);
}
/**
* Internal method to actually spawn a fired beam.
*/
public void createBeam() {
new Beam(
this.getX() + this.shootSpawnX,
this.getY() + this.shootSpawnY,
this.shootDirection,
this.shootSpeed,
this.shootDamage,
this.primaryShotImage
);
this.getX() + this.shootSpawnX,
this.getY() + this.shootSpawnY,
this.shootDirection,
this.shootSpeed,
this.shootDamage,
this.primaryShotImage
);
}
/**
* Custom Shoot for Custom Action!!!
* Custom Shot for special purposes.
*/
public void createCustomShot(int x, int y, int speed, int dmg, String filename) {
public void createCustomShot(int x_offset, int y_offset, int speed, int dmg, String filename) {
new Shot(
this.getX() + x,
this.getY() + y,
Shot.LEFT,
speed,
dmg,
filename
);
this.getX() + x_offset,
this.getY() + y_offset,
this.shootDirection,
speed,
dmg,
filename
);
}
}

View File

@ -1,5 +1,6 @@
package de.teamteamteam.spacescooter.entity.enemy;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.entity.ShootingEntity;
import de.teamteamteam.spacescooter.entity.shot.Shot;
import de.teamteamteam.spacescooter.sound.SoundSystem;
@ -45,6 +46,14 @@ public abstract class Enemy extends ShootingEntity {
}
}
/**
* Every enemy that dies awards the Player one credit and points.
*/
@Override
public void die() {
PlayerSession.addCredits(1);
}
@Override
public void createShot() {
super.createShot();

View File

@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity.enemy;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion;
import de.teamteamteam.spacescooter.gui.BossBar;
import de.teamteamteam.spacescooter.gui.BossHealthBar;
import de.teamteamteam.spacescooter.utility.Random;
public class EnemyBoss extends Enemy{
@ -22,7 +22,7 @@ public class EnemyBoss extends Enemy{
this.setScore(5000);
this.willShoot = true;
this.setPosition(GameConfig.windowWidth, Random.nextInt(GameConfig.windowHeight - this.getHeight() - 50) +50);
new BossBar(10, 44, this);
new BossHealthBar(10, 44, this);
}
/**

View File

@ -6,6 +6,11 @@ import de.teamteamteam.spacescooter.entity.spi.Collidable;
import de.teamteamteam.spacescooter.sound.SoundSystem;
import de.teamteamteam.spacescooter.utility.Random;
/**
* Abstract representation of an item.
* Contains logic to spawn a random item at a location and passes
* the collision with a player up to the itemCollected() method.
*/
public abstract class Item extends CollidableEntity {
/**
@ -21,7 +26,7 @@ public abstract class Item extends CollidableEntity {
public void collideWith(Collidable entity) {
if(entity instanceof Player) {
SoundSystem.playSound("sounds/powerup_pickup.wav");
itemCollected((Player) entity);
this.itemCollected((Player) entity);
this.remove();
}
}
@ -74,7 +79,7 @@ public abstract class Item extends CollidableEntity {
break;
}
}
//Actually spawn the item now
//Actually spawn the random item now
switch (choice) {
case 0:
new ItemNuke(x, y);

View File

@ -6,7 +6,7 @@ public class ItemIncreaseDamage extends Item {
public ItemIncreaseDamage(int x, int y) {
super(x, y);
//TODO: Chane Image
//TODO: Change Image
this.setImage("images/items/item.png");
}

View File

@ -9,7 +9,6 @@ import de.teamteamteam.spacescooter.screen.Screen;
public class ItemNuke extends Item {
private ConcurrentIterator<Entity> entityIterator;
public ItemNuke(int x, int y) {
@ -17,11 +16,13 @@ public class ItemNuke extends Item {
this.setImage("images/items/itemNuke.png");
}
/**
* Gives every enemy 20 damage. Most enemies do not survive this.
*/
@Override
public void itemCollected(Player player) {
System.out.println("Gotta Nuke 'em All!");
this.entityIterator = Screen.currentScreen.createEntityIterator();
entityIterator.reset();
this.entityIterator.reset();
while (entityIterator.hasNext()) {
Entity entity = entityIterator.next();
if(entity instanceof Enemy) {

View File

@ -9,8 +9,13 @@ public class ItemOneUp extends Item {
this.setImage("images/items/itemOneUp.png");
}
/**
* Since we do not actually have a concept of "lives" yet, the
* player gets full health restored.
*/
@Override
public void itemCollected(Player player) {
System.out.println("1 UP");
player.setHealthPoints(player.getMaximumHealthPoints());
}
}

View File

@ -9,6 +9,10 @@ public class ItemShield extends Item {
this.setImage("images/items/itemShield.png");
}
/**
* Adds 5 shield points to the player in case he upgraded
* his ship to have a shield.
*/
@Override
public void itemCollected(Player player) {
player.addShieldPoints(5);

View File

@ -2,24 +2,24 @@ package de.teamteamteam.spacescooter.entity.shot;
import de.teamteamteam.spacescooter.entity.spi.Collidable;
public class Beam extends Shot{
public class Beam extends Shot {
int i =0;
private int i;
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");
this.i = 0;
}
@Override
public void update() {
i++;
if(i>10){
this.i++;
if(this.i>10){
this.remove();
}
}
@Override
public void collideWith(Collidable entity) {
}
public void collideWith(Collidable entity) {}
}

View File

@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity.shot;
import de.teamteamteam.spacescooter.entity.spi.Collidable;
public class Rocket extends Shot{
public class Rocket extends Shot {
public Rocket(int x, int y, int shootDirection, int shootSpeed, int damageValue, String filename) {
super(x, y, shootDirection, shootSpeed, damageValue, filename);
@ -10,7 +10,7 @@ public class Rocket extends Shot{
}
/**
* If the rocket collide with an enemy, the rocket create a big damage range
* If the rocket collide with an enemy, the rocket create a big damage range.
*/
@Override
public void collideWith(Collidable entity) {

View File

@ -7,18 +7,18 @@ import java.awt.Graphics2D;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
public class BossBar extends Entity {
public class BossHealthBar extends Entity {
private int width = 150;
private int height = 14;
private int health = 0;
private int fullhealth = 0;
private int healthwidth = 0;
private static Enemy boss;
private Enemy boss;
public BossBar(int x, int y, Enemy ent) {
public BossHealthBar(int x, int y, Enemy boss) {
super(x, y);
BossBar.boss = ent;
this.boss = boss;
this.fullhealth = boss.getHealthPoints();
}
@ -39,10 +39,10 @@ public class BossBar extends Entity {
}
public void update() {
if (boss.isAlive() == false || boss.isRemoved() == true) {
if (this.boss != null && this.boss.isAlive() == false) {
this.boss = null; //Dereference the boss, so it actually can be removed.
this.remove();
}
}
}

View File

@ -125,7 +125,7 @@ public final class Level {
new EnemyBoss(x, y);
break;
default:
System.err.println("Fuck you, i don't know what you mean with this: " + entity);
System.err.println("I don't know how to spawn this: " + entity);
break;
}
}

View File

@ -73,7 +73,6 @@ public class LevelConfig {
/**
* Add a given interval to the list in case it is not a duplicate.
* TODO: Catch overlapping intervals and more!
*/
public void addIntervalToList(int intervalStart, int intervalEnd) {
if(intervalStart >= intervalEnd) {