Permalink
Browse files

Lesson 12: victory notification and bonus logic implemented

  • Loading branch information...
vladimirslav committed Oct 4, 2016
1 parent a439ec0 commit a337f155744c058aacd2ed3367cc1ac309485baf
@@ -108,6 +108,28 @@ public void AssignPlayerPosition(int fx, int fy)
{
player.setFieldX(fx);
player.setFieldY(fy);
for (int i = bonuses.size() - 1; i >= 0; i--)
{
Bonus currentBonus = bonuses.get(i);
if (currentBonus.getFieldX() == fx &&
currentBonus.getFieldY() == fy)
{
if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_HEALTH)
{
player.addLives(1);
}
else if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_ATTACK)
{
enemy.takeDamage(1);
}
currentBonus.release();
bonuses.remove(i);
break;
}
}
}
public EffectEngine getEffectEngine()
@@ -22,6 +22,14 @@
private boolean targetTiles[][];
public void takeDamage(int amount) {
lives -= amount;
if (lives < 0)
{
lives = 0;
}
}
public interface EnemyAttackListener
{
void OnAttack(boolean[][] tiles);
@@ -14,13 +14,15 @@
private int fieldY;
private int lives;
private final int max_lives;
public Player(int fx, int fy, Resources res, int _lives)
{
fieldX = fx;
fieldY = fy;
set(res.player);
lives = _lives;
max_lives = _lives;
}
public int getFieldX()
@@ -63,4 +65,12 @@ public int getLives()
{
return lives;
}
public void addLives(int amount) {
lives += amount;
if (lives > max_lives)
{
lives = max_lives;
}
}
}
@@ -59,7 +59,7 @@ public GameScreen(DodgingHero _game) {
public void update(float delta)
{
gameStage.act(delta);
if (player.getLives() > 0)
if (player.getLives() > 0 && logic.getEnemy().getLives() > 0)
{
logic.update(delta);
}
@@ -100,6 +100,16 @@ private void DrawShadowed(String str, float x, float y, float width, int align,
game.res.gamefont.setColor(Color.WHITE);
}
private void ShowGameResult(String result)
{
DrawShadowed(result,
0,
gameStage.getHeight() / 2,
gameStage.getWidth(),
Align.center,
Color.RED);
}
private void DrawUI()
{
batch.begin();
@@ -119,12 +129,11 @@ private void DrawUI()
if (player.getLives() <= 0)
{
DrawShadowed("DEFEAT!",
0,
gameStage.getHeight() / 2,
gameStage.getWidth(),
Align.center,
Color.RED);
ShowGameResult("DEFEAT!");
}
else if (logic.getEnemy().getLives() <= 0)
{
ShowGameResult("VICTORY!");
}
batch.end();
}
@@ -172,6 +181,7 @@ public void resize(int width, int height)
public void AttempMove(int dx, int dy)
{
if (player.getLives() > 0 &&
logic.getEnemy().getLives() > 0 &&
logic.CanMove(player.getFieldX() + dx, player.getFieldY() + dy))
{
logic.AssignPlayerPosition(player.getFieldX() + dx, player.getFieldY() + dy);

0 comments on commit a337f15

Please sign in to comment.