Monster hunger bar added

master
GammelJAN 5 years ago
parent f934f6e568
commit 40dc8a51d8

@ -145,7 +145,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
font.getData().setScale(1);
batch.end();
// DRAW MONSTER
model.getMonster().drawMonster(renderer,polygonSpriteBatch);
model.getMonster().drawMonster(renderer,polygonSpriteBatch, batch, font);
}
}

@ -53,7 +53,11 @@ public class Model {
}
if (monster.getIsDead()) {
toReset = true;
ending = true; // Monster win - Player lost
ending = false; // Monster win - Player lost
}
if(monster.getHp() == monster.getMaxHp()){
toReset = true;
ending = true;
}
// Generation of new projectiles

@ -3,9 +3,11 @@ package com.trs.game.model;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PolygonRegion;
import com.badlogic.gdx.graphics.g2d.PolygonSprite;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
@ -33,14 +35,14 @@ public class Monster {
public Monster(int xPos, int yPos){
this.xPos = xPos;
this.yPos = yPos;
this.maxHp = 3;
this.hp = 3;
this.maxHp = 500;
this.hp = 350;
isDead = false;
generateNewTarget();
}
public void drawMonster(ShapeRenderer renderer, PolygonSpriteBatch polygonSpriteBatch){
public void drawMonster(ShapeRenderer renderer, PolygonSpriteBatch polygonSpriteBatch, SpriteBatch batch, BitmapFont font){
if(renderer.isDrawing()) renderer.end();
renderer.begin(ShapeRenderer.ShapeType.Filled);
//BODY
@ -69,8 +71,25 @@ public class Monster {
renderer.triangle(xPos+28,yPos+10,xPos+31,yPos+15,xPos+34,yPos+10);
renderer.triangle(xPos+34,yPos+10,xPos+37,yPos+15,xPos+40,yPos+10);
// HUNGER BAR
renderer.setColor(Color.BLACK);
renderer.rect(xPos - 26, yPos + 55, 102,22);
renderer.setColor(Color.BROWN);
renderer.rect(xPos - 25, yPos + 56, 100f * (float)hp/(float)maxHp,20);
renderer.setColor(Color.DARK_GRAY);
renderer.rect(xPos - 25 + 100f * (float)hp/(float)maxHp, yPos + 56, 100 - 100f * (float)hp/(float)maxHp,20);
renderer.end();
batch.begin();
font.getData().setScale(0.8f);
font.setColor(Color.WHITE);
font.draw(batch, "Hunger",xPos - 22, yPos + 71);
font.getData().setScale(1f);
font.setColor(Color.BLACK);
batch.end();
}
public void move(ArrayList<Wall> walls, ArrayList<Projectile> projectiles){
@ -91,6 +110,8 @@ public class Monster {
verticesMonster[7] = yPos + HEIGHT;
Polygon monsterPolygon = new Polygon(verticesMonster);
hp--;
for (int i = projectiles.size() - 1; i >= 0; i--) {
Projectile projectile = projectiles.get(i);
if (Intersector.overlapConvexPolygons(monsterPolygon, projectile.getPolygon())) {
@ -98,12 +119,15 @@ public class Monster {
hit();
}
}
if(hp <= 0){
die();
}
}
private void hit(){
hp--;
if(hp <= 0){
die();
hp += 25;
if(hp > maxHp){
hp = maxHp;
}
}

@ -31,7 +31,7 @@ public class EndScreen extends Screen {
music.play();
if(lost)
texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "The monster ate too many doods!", Color.BLACK, 3, 0,0));
texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "The monster ate too many people!", Color.BLACK, 3, 0,0));
else
texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "You successfully starved the Monster!", Color.BLACK, 3, 0,0));

Loading…
Cancel
Save