package com.palepail.TestGame.View;
import java.util.Iterator;
import java.util.Random;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.utils.Array;
import com.palepail.TestGame.TestGame;
import com.palepail.TestGame.Enemies.Enemy;
import com.palepail.TestGame.Levels.Level;
import com.palepail.TestGame.Message.Message;
import com.palepail.TestGame.Message.MessageString;
import com.palepail.TestGame.Message.Pause;
import com.palepail.TestGame.Model.Explosion;
import com.palepail.TestGame.Model.Ship;
import com.palepail.TestGame.Model.Bullet.Bullet;
import com.palepail.TestGame.Model.Items.Item;
import com.palepail.TestGame.Screens.MainMenu;
import com.palepail.TestGame.Utilities.Audio;
import com.palepail.TestGame.Utilities.Configuration;
import com.palepail.TestGame.Utilities.InfoBox;
import com.palepail.TestGame.Utilities.InputHandler;
/*the world class houses all of the logic and collisions that happen during gameplay.*/
public class World {
boolean GAMEOVER = false;
boolean VICTORY = false;
boolean START = true;
TestGame game;
Ship ship;
WorldRender wr;
private boolean hold = false;
private boolean bombsScore = false;
private boolean livesScore = false;
private boolean fadeout = false;
private int scoreCounter = 0;
private int scoreQueue = 0;
private int scoreTimer = 0;
private int enemyCounter = 0;
private boolean pause = false;
Random random = new Random();
Rectangle playArea = new Rectangle(1 * Configuration.gameScale, 1 * Configuration.gameScale,
19 * Configuration.gameScale, 22 * Configuration.gameScale);
Rectangle extendedPlayArea = new Rectangle(0, 0, 21 * Configuration.gameScale, 30 * Configuration.gameScale);
Rectangle infoArea = new Rectangle(21 * Configuration.gameScale, 1 * Configuration.gameScale,
10 * Configuration.gameScale, 22 * Configuration.gameScale);
Array<Bullet> enemyBullets = new Array<Bullet>();
Array<Bullet> bullets = new Array<Bullet>();
Iterator<Bullet> bulletIterator;
Bullet bullet;
Array<Item> items = new Array<Item>();
Iterator<Item> itemIterator;
Item item;
Array<Explosion> explosions = new Array<Explosion>();
Array<Explosion> secondaryExplosions = new Array<Explosion>();
Iterator<Explosion> explosionIterator;
Explosion explosion;
Array<Enemy> enemies = new Array<Enemy>();
Iterator<Enemy> enemyIterator;
Enemy enemy;
Array<Enemy> enemyQueue;
Array<Integer> enemyTimes;
Array<Message> messages = new Array<Message>();
Array<Message> infoBoxMessages = new Array<Message>();
Iterator<Message> messageIterator;
Message message;
Array<TextButton> buttons = new Array<TextButton>();
Iterator<TextButton> buttonIterator;
TextButton button;
double delta = 0;
int counter = 0;
Level level;
public World(TestGame game, Level level) {
this.game = game;
ship = new Ship(new Vector2(10 * Configuration.gameScale, 3 * Configuration.gameScale),
.4f * Configuration.gameScale, .4f * Configuration.gameScale, 0, 4f * Configuration.gameScale, 1,
new InfoBox());
ship.setDamage(ship.getBaseDamage());
this.level = level;
ship.getInfoBox().setLevelName(level.getName());
ship.getInfoBox().setScore(level.getName(), 0);
enemyQueue = level.getEnemyQueue();
enemyTimes = level.getEnemyTimes();
enemyQueue.reverse();
enemyTimes.reverse();
addTextBox();
Gdx.input.setInputProcessor(new InputHandler(this));
Audio.setMusic(level.getBgm());
Audio.setVolume();
Audio.playMusic(true);
}
private void addTextBox() {
MessageString levelName = new MessageString(Message.LEVELNAME, level.getName(), Configuration.bonzai32);
levelName.label.setPosition((infoArea.x + infoArea.width / 2) - levelName.getMidPointX(), infoArea.y
+ infoArea.height - (Configuration.bonzai32.getXHeight() * (3f * (Configuration.gameScale / 20))));
infoBoxMessages.add(levelName);
MessageString scoreTag = new MessageString(Message.SCORETAG, ship.getInfoBox().getScoreTag(),
Configuration.bonzai24);
scoreTag.label.setPosition((infoArea.x + infoArea.width / 6), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (6 * (Configuration.gameScale / 20))));
infoBoxMessages.add(scoreTag);
MessageString score = new MessageString(Message.SCORE, Integer.toString(ship.getInfoBox().getScore(
level.getName())), Configuration.bonzai24);
score.label.setPosition((infoArea.x + infoArea.width / 1.5f), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (6 * (Configuration.gameScale / 20))));
infoBoxMessages.add(score);
MessageString livesTag = new MessageString(Message.LIVESTAG, ship.getInfoBox().getLivesTag(),
Configuration.bonzai24);
livesTag.label.setPosition((infoArea.x + infoArea.width / 6), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (8f * (Configuration.gameScale / 20))));
infoBoxMessages.add(livesTag);
MessageString lives = new MessageString(Message.LIVES, Integer.toString(ship.getLives()),
Configuration.bonzai24);
lives.label.setPosition((infoArea.x + infoArea.width / 1.5f), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (8f * (Configuration.gameScale / 20))));
infoBoxMessages.add(lives);
MessageString bombsTag = new MessageString(Message.BOMBTAG, ship.getInfoBox().getBombTag(),
Configuration.bonzai24);
bombsTag.label.setPosition((infoArea.x + infoArea.width / 6), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (10f * (Configuration.gameScale / 20))));
infoBoxMessages.add(bombsTag);
MessageString bombs = new MessageString(Message.BOMBS, Integer.toString(ship.getBombs()),
Configuration.bonzai24);
bombs.label.setPosition((infoArea.x + infoArea.width / 1.5f), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (10f * (Configuration.gameScale / 20))));
infoBoxMessages.add(bombs);
MessageString powerTag = new MessageString(Message.POWERTAG, ship.getInfoBox().getPowerTag(),
Configuration.bonzai24);
powerTag.label.setPosition((infoArea.x + infoArea.width / 6), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (12f * (Configuration.gameScale / 20))));
infoBoxMessages.add(powerTag);
MessageString power = new MessageString(Message.POWER, Float.toString(ship.getDamage()), Configuration.bonzai24);
power.label.setPosition((infoArea.x + infoArea.width / 1.5f), infoArea.y + infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (12f * (Configuration.gameScale / 20))));
infoBoxMessages.add(power);
MessageString BGMName = new MessageString(Message.BGM, "BGM: " + level.getBgmName(), Configuration.bonzai24);
BGMName.label.setPosition(infoArea.x+(infoArea.width/4), infoArea.y
+ infoArea.height
- ((Configuration.bonzai24.getXHeight() * 1.5f) * (16 * (Configuration.gameScale / 20))));
BGMName.label.setWidth(infoArea.width/2);
BGMName.label.setWrap(true);
infoBoxMessages.add(BGMName);
}
public World(TestGame game, Level level, Ship ship) {
this(game, level);
this.ship = ship;
ship.getInfoBox().setLevelName(level.getName());
ship.getInfoBox().setScore(level.getName(), 0);
}
public void update() {
if (!pause) {
updateTimer();
ship.update(this);
addEnemies();
updateBullet();
updateEnemies();
updateItems();
updateExplosions();
updateMessages();
updateScore();
if (!VICTORY) {
updateInfoBox();
}
checkCollision();
removeEntities();
}
}
private void updateScore() {
if (scoreQueue > 0) {
scoreQueue--;
ship.getInfoBox().addScore(level.getName(), 1);
}
}
public void putEnemy(Enemy enemy) {
enemies.add(enemy);
}
public void putItem(Item item) {
items.add(item);
}
public void putExplosion(float x, float y, String variation) {
Explosion explosion = new Explosion(0f, 0, 1 * Configuration.gameScale, 1 * Configuration.gameScale,
new Vector2(x, y), 1, variation);
explosions.add(explosion);
}
public void putSecondaryExplosion(float x, float y, String variation) {
Explosion explosion = new Explosion(0f, random.nextInt(9 * Configuration.gameScale),
1.5f * Configuration.gameScale, .2f * Configuration.gameScale, new Vector2(x, y), .8f, variation);
secondaryExplosions.add(explosion);
}
public void setWorldRenderer(WorldRender wr) {
this.wr = wr;
}
public void addExplosion(Explosion explosion) {
explosions.add(explosion);
}
public void addSecondaryExplosion(Explosion explosion) {
secondaryExplosions.add(explosion);
}
public void addItem(Item item) {
items.add(item);
}
public void addBullet(Bullet bullet) {
bullets.add(bullet);
}
public void addEnemyBullet(Bullet bullet) {
enemyBullets.add(bullet);
}
public Rectangle getPlayArea() {
return playArea;
}
public Rectangle getInfoArea() {
return infoArea;
}
public WorldRender getRenderer() {
return wr;
}
public Array<Bullet> getBullets() {
return bullets;
}
public Array<Bullet> getEnemyBullets() {
return enemyBullets;
}
public Array<Item> getItems() {
return items;
}
public Array<Explosion> getExplosions() {
return explosions;
}
public Array<Explosion> getSecondaryExplosions() {
return secondaryExplosions;
}
public Array<Enemy> getEnemies() {
return enemies;
}
public Ship getShip() {
return ship;
}
/**
* @return the messageArray
*/
public Array<Message> getMessages() {
return messages;
}
/**
* @param messageArray
* the messageArray to set
*/
public void setMessages(Array<Message> messages) {
this.messages = messages;
}
/**
* @return the messageArray
*/
public Array<Message> getInfoBoxMessages() {
return infoBoxMessages;
}
/**
* @param messageArray
* the messageArray to set
*/
public void setInfoBoxMessages(Array<Message> messages) {
this.infoBoxMessages = messages;
}
/**
* @return the buttons
*/
public Array<TextButton> getButtons() {
return buttons;
}
/**
* @param buttons
* the buttons to set
*/
public void setButtons(Array<TextButton> buttons) {
this.buttons = buttons;
}
/**
* returns the game counter.
*
* @return counter
*/
public int getCounter() {
return counter;
}
private void addEnemies() {
if (enemyTimes.size > 0) {
if (enemyTimes.peek() < 0) {
extraConditions(enemyTimes.peek());
} else if (enemyCounter >= enemyTimes.peek()) {
if (enemyQueue.size > 0) {
putEnemy(enemyQueue.pop());
}
enemyTimes.pop();
}
}
}
private void extraConditions(Integer peek) {
if (peek.equals(Level.WAIT_FOR_ENEMIES)) {
if (!hold) {
System.out.println("HOLDING FOR ENEMIES");
hold = true;
}
if (enemies.size <= 0) {
System.out.println("DONE HOLDING FOR ENEMIES");
hold = false;
enemyTimes.pop();
}
} else if (peek.equals(Level.WAIT_FOR_ENEMY_BULLETS)) {
if (!hold) {
System.out.println("HOLDING FOR BULLETS");
hold = true;
}
if (enemyBullets.size <= 0) {
System.out.println("DONE HOLDING FOR BULLETS");
hold = false;
enemyTimes.pop();
}
} else if (peek.equals(Level.VICTORY) && GAMEOVER == false) {
if (!ship.isDead()) {
if (VICTORY == false) {
victoryDoOnce();
} else {
victory();
}
}
}
}
private void victory() {
// on a timer display score
// after a time
messageIterator = infoBoxMessages.iterator();
while (messageIterator.hasNext()) {
message = messageIterator.next();
if (message.getId().equals(Message.SCORE)) {
message.setValue(ship.getInfoBox().getScore(level.getName()));
} else if (message.getId().equals(Message.POWER)) {
message.setValue(Float.toString(ship.getDamage()));
}
if (message.getId().equals(Message.LIVES) && scoreCounter > 150 && scoreQueue == 0) {
message.setValue(ship.getLives() + "x 1000");
// attract all items
if (scoreCounter > 200 && livesScore == false) {
livesScore = true;
attactAll();
// ship.getInfoBox().addScore(level.getName(), 1000 *
// ship.getLives());
addToScoreQueue(1000 * ship.getLives());
}
}
if (message.getId().equals(Message.BOMBS) && scoreCounter > 250 && scoreQueue == 0) {
message.setValue(ship.getBombs() + "x 500");
if (scoreCounter > 300 && bombsScore == false) {
bombsScore = true;
// ship.getInfoBox().addScore(level.getName(), 500 *
// ship.getBombs());
addToScoreQueue(500 * ship.getBombs());
}
}
}
if (scoreCounter > 500 && scoreQueue == 0) {
if (fadeout == false) {
fadeout = true;
wr.triggerFadeOut();
scoreTimer = scoreCounter;
}
if (scoreCounter < scoreTimer + 100) {
float currentVolume = Configuration.musicVolume * Configuration.masterVolume;
Audio.forceMusicVolume(currentVolume - ((currentVolume / 100) * (scoreCounter - scoreTimer)));
}
if (scoreCounter > scoreTimer + 150) {
Audio.stopMusic();
enemyTimes.pop();
startNewLevel(level.getNextLevel());
// pops victory condition
}
}
}
// triggers victory this will include the ending ship animation victory
// message display of final score etc.
private void victoryDoOnce() {
// set ship victory script
// set message
ship.setActive(false);
VICTORY = true;
scoreCounter = 0;
MessageString victory = new MessageString(Message.VICTORY, "Victory", Configuration.bonzai32);
victory.label.setPosition((playArea.x + playArea.width / 2) - victory.getMidPointX(), playArea.y
+ playArea.height * .7f);
messages.add(victory);
ship.setVictoryScript();
removeEnemyBullets();
System.out.println("A WINNER IS YOU");
}
private void attactAll() {
itemIterator = items.iterator();
while (itemIterator.hasNext()) {
item = itemIterator.next();
if (item.isActive()) {
item.setAttracted(true);
}
}
}
private void updateExplosions() {
explosionIterator = explosions.iterator();
while (explosionIterator.hasNext()) {
explosion = explosionIterator.next();
if (explosion.isActive()) {
explosion.update();
} else {
explosionIterator.remove();
}
}
explosionIterator = secondaryExplosions.iterator();
while (explosionIterator.hasNext()) {
explosion = explosionIterator.next();
if (explosion.isActive()) {
explosion.update();
} else {
explosionIterator.remove();
}
}
}
private void removeEntities() {
itemIterator = items.iterator();
while (itemIterator.hasNext()) {
item = itemIterator.next();
if (!item.isActive()) {
itemIterator.remove();
}
}
bulletIterator = enemyBullets.iterator();
while (bulletIterator.hasNext()) {
bullet = bulletIterator.next();
if (!bullet.isActive()) {
bulletIterator.remove();
}
}
bulletIterator = bullets.iterator();
while (bulletIterator.hasNext()) {
bullet = bulletIterator.next();
if (!bullet.isActive()) {
bulletIterator.remove();
}
}
enemyIterator = enemies.iterator();
while (enemyIterator.hasNext()) {
enemy = enemyIterator.next();
if (!enemy.isActive()) {
enemyIterator.remove();
}
}
}
private void updateItems() {
itemIterator = items.iterator();
while (itemIterator.hasNext()) {
item = itemIterator.next();
item.update(ship);
}
}
// =================Collisions
private void checkCollision() {
checkBulletCollision();
checkEnemyBulletCollision();
checkEnemyCollision();
checkItemCollision();
}
private void checkEnemyBulletCollision() {
bulletIterator = enemyBullets.iterator();
while (bulletIterator.hasNext()) {
bullet = bulletIterator.next();
if (bullet.isActive()) {
if (bullet.getBounds().overlaps(ship.getBounds()) && !ship.isDead()) {
damageShip(bullet.getPower());
bullet.setActive(false);
}
if (bullet.getBounds().overlaps(ship.getInfluence())) {
if (!ship.isActive()) {
bullet.setActive(false);
} else if (!bullet.isGrazed()) {
// graze score
bullet.setGrazed(true);
addToScoreQueue(1);
}
}
if (bullet.getBounds().overlaps(ship.getBomb())) {
bullet.setActive(false);
}
if (!bullet.getBounds().overlaps(playArea)) {
bullet.setActive(false);
}
}
}
}
private void checkItemCollision() {
itemIterator = items.iterator();
while (itemIterator.hasNext()) {
item = itemIterator.next();
if (item.isActive() && ship.isActive() || (VICTORY && !ship.isDead())) {
if (item.getBounds().overlaps(ship.getInfluence())) {
item.setAttracted(true);
}
if (item.getBounds().overlaps(ship.getBounds())) {
item.effect(ship);
// Gdx.app.log(TestGame.LOG, "ITEM GET");
item.setActive(false);
}
}
// items can go above the screen due to bounce when dropped
if (!item.getBounds().overlaps(extendedPlayArea)) {
item.setActive(false);
}
}
}
private void checkEnemyCollision() {
enemyIterator = enemies.iterator();
while (enemyIterator.hasNext()) {
enemy = enemyIterator.next();
if (ship.getBounds().overlaps(enemy.getBounds()) && !ship.isDead()) {
damageShip(enemy.getHealth());
}
if (enemy.getBounds().overlaps(ship.getInfluence())) {
if (!ship.isActive() && !enemy.isDeathGrazed() && !GAMEOVER) {
enemy.damage(ship.getDeathDamage());
enemy.setTimeDeathGrazed(enemy.getTime());
enemy.setDeathGrazed(true);
} else if (!enemy.isGrazed()) {
// graze score
enemy.setGrazed(true);
ship.getInfoBox().addScore(level.getName(), 2);
}
}
if (enemy.getBounds().overlaps(ship.getBomb())) {
if (!enemy.isBombed()) {
enemy.setBombed(true);
enemy.setTimeBombed(enemy.getTime());
enemy.damage(ship.getBombDamage());
}
}
if (!enemy.getBounds().overlaps(extendedPlayArea)) {
enemy.setActive(false);
}
}
}
private void checkBulletCollision() {
bulletIterator = bullets.iterator();
while (bulletIterator.hasNext()) {
bullet = bulletIterator.next();
enemyIterator = enemies.iterator();
while (enemyIterator.hasNext()) {
enemy = enemyIterator.next();
if (enemy.isActive() && bullet.isActive()) {
if (enemy.getBounds().overlaps(bullet.getBounds())) {
bullet.setActive(false);
enemy.damage(ship.getDamage());
}
}
}
if (!bullet.getBounds().overlaps(playArea)) {
bullet.setActive(false);
}
}
}
// ============================
/**
* reset level clears the current messages, buttons, enemies, enemy bullets
* and items, resets the game counter to 0 resets the enemy counter to 0
* calls rest on ship, level removes holds and turns off Gameover. also
* resets music
*/
private void resetLevel() {
removeMessages();
removeButtons();
removeEnemies();
removeEnemyBullets();
removeItems();
counter = 0;
enemyCounter = 0;
scoreCounter = 0;
ship.reset(this);
level.reset();
hold = false;
enemyQueue = level.getEnemyQueue();
enemyTimes = level.getEnemyTimes();
enemyQueue.reverse();
enemyTimes.reverse();
GAMEOVER = false;
VICTORY = false;
bombsScore = false;
livesScore = false;
fadeout = false;
Audio.setMusic(level.getBgm());
Audio.setVolume();
Audio.playMusic(true);
Gdx.input.setInputProcessor(new InputHandler(this));
}
private void startNewLevel(Level level) {
removeMessages();
removeTextBox();
removeButtons();
removeEnemies();
removeEnemyBullets();
removeItems();
counter = 0;
enemyCounter = 0;
scoreCounter = 0;
this.level = level;
this.level.reset();
hold = false;
ship.startPosition();
enemyQueue = this.level.getEnemyQueue();
enemyTimes = this.level.getEnemyTimes();
enemyQueue.reverse();
enemyTimes.reverse();
ship.getInfoBox().setLevelName(level.getName());
ship.getInfoBox().setScore(level.getName(), 0);
addTextBox();
GAMEOVER = false;
VICTORY = false;
bombsScore = false;
livesScore = false;
fadeout = false;
Audio.setMusic(level.getBgm());
Audio.setVolume();
Audio.playMusic(true);
wr.triggerFadeIn();
Gdx.input.setInputProcessor(new InputHandler(this));
}
/**
* @return the gAMEOVER
*/
public boolean isGAMEOVER() {
return GAMEOVER;
}
/**
* @param gAMEOVER
* the gAMEOVER to set
*/
public void setGAMEOVER(boolean gAMEOVER) {
GAMEOVER = gAMEOVER;
}
private void removeItems() {
items.clear();
}
private void removeEnemyBullets() {
enemyBullets.clear();
}
private void removeEnemies() {
enemies.clear();
}
private void removeButtons() {
buttons.clear();
}
private void removeMessages() {
messages.clear();
}
private void removeTextBox() {
infoBoxMessages.clear();
}
// =========================
private void damageShip(int damage) {
ship.damage(damage);
}
public void addToScoreQueue(int value) {
scoreQueue += value;
}
public void gameOver() {
GAMEOVER = true;
MessageString gameOver = new MessageString(Message.GAMEOVER, "Game Over", Configuration.bonzai32);
gameOver.label.setPosition((playArea.x + playArea.width / 2) - gameOver.getMidPointX(), playArea.y
+ playArea.height * .7f);
messages.add(gameOver);
MessageString retry = new MessageString(Message.RETRY, "Retry?", Configuration.bonzai24);
retry.label.setPosition((playArea.x + playArea.width / 2) - retry.getMidPointX(), playArea.y + playArea.height
* .6f);
messages.add(retry);
buttons.add(getContinueYesButton());
buttons.add(getContinueNoButton());
Gdx.app.log(TestGame.LOG, "GAME OVER.... YEAH!!!!");
}
private TextButton getContinueNoButton() {
TextButtonStyle style = new TextButtonStyle();
BitmapFont font = Configuration.bonzai24;
style.font = font;
TextButton no = new TextButton("No", style);
no.setWidth(4 * Configuration.gameScale);
no.setHeight(2 * Configuration.gameScale);
no.setScale(Configuration.gameScale / 20);
no.setPosition((playArea.x + (playArea.width / 2)), (playArea.y + playArea.height * .45f));
no.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("down");
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("up");
Audio.stopMusic();
Audio.ok();
game.setScreen(new MainMenu(game));
}
});
return no;
}
private TextButton getContinueYesButton() {
TextButtonStyle style = new TextButtonStyle();
BitmapFont font = Configuration.bonzai24;
style.font = font;
TextButton yes = new TextButton("Yes", style);
yes.setWidth(4 * Configuration.gameScale);
yes.setHeight(2 * Configuration.gameScale);
yes.setPosition((playArea.x + (playArea.width / 2) - (4 * Configuration.gameScale)),
(playArea.y + playArea.height * .45f));
yes.setScale(Configuration.gameScale / 20);
yes.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("down");
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("up");
Audio.stopMusic();
Audio.ok();
resetLevel();
}
});
return yes;
}
// ============Updates
private void updateEnemies() {
enemyIterator = enemies.iterator();
while (enemyIterator.hasNext()) {
enemy = enemyIterator.next();
enemy.update(ship, this);
}
}
private void updateMessages() {
messageIterator = messages.iterator();
while (messageIterator.hasNext()) {
message = messageIterator.next();
message.update();
}
}
private void updateInfoBox() {
messageIterator = infoBoxMessages.iterator();
while (messageIterator.hasNext()) {
message = messageIterator.next();
if (message.getId().equals(Message.SCORE)) {
message.setValue(ship.getInfoBox().getScore(level.getName()));
} else if (message.getId().equals(Message.LIVES)) {
message.setValue(Integer.toString(ship.getLives()));
} else if (message.getId().equals(Message.BOMBS)) {
message.setValue(Integer.toString(ship.getBombs()));
} else if (message.getId().equals(Message.POWER)) {
message.setValue(Float.toString(ship.getDamage()));
}
}
}
private void updateBullet() {
bulletIterator = bullets.iterator();
while (bulletIterator.hasNext()) {
bullet = bulletIterator.next();
bullet.update(ship, this);
}
bulletIterator = enemyBullets.iterator();
while (bulletIterator.hasNext()) {
bullet = bulletIterator.next();
bullet.update(ship, this);
}
}
/**
* game clock, counter is incremented 30 times per second
*
*/
private void updateTimer() {
delta += (Gdx.graphics.getDeltaTime() * Configuration.frameRate);
while (delta >= 1) {
delta--;
scoreCounter++;
counter++;
if (!hold && !GAMEOVER) {
enemyCounter++;
}
}
if (counter > 900000) {
counter = 0;
}
if (scoreCounter > 900000) {
counter = 0;
}
}
public void togglePause() {
if (pause) {
pause = false;
ship.checkControls();
Audio.resumeMusic();
messages.pop();
} else {
pause = true;
Audio.pauseMusic();
Audio.pause();
putPauseMessage();
}
}
private void putPauseMessage() {
MessageString pause = new MessageString(Message.PAUSE, "Paused", Configuration.bonzai32);
pause.label.setPosition((playArea.x + playArea.width / 2) - pause.getMidPointX(), playArea.y + playArea.height
* .7f);
messages.add(pause);
}
public boolean isPaused() {
return pause;
}
/**
* @return the level
*/
public Level getLevel() {
return level;
}
/**
* @param level
* the level to set
*/
public void setLevel(Level level) {
this.level = level;
}
public void dispose() {
}
public void clearBullets() {
enemyBullets.clear();
}
public void setSTART(boolean b) {
START = b;
}
}