Skip to content

Commit

Permalink
Added game over message.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGussio committed Jun 10, 2017
1 parent 1eda8fb commit 2e9a93e
Showing 1 changed file with 86 additions and 41 deletions.
127 changes: 86 additions & 41 deletions core/src/ga/gussio/ld38/earthinvaders/screen/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class GameScreen extends Screen implements InputListener {
private BitmapFont scoreFont;
private Particle[] background;

private Button leftButton, rightButton;
private Button leftButton, rightButton, exit, retry;
private Player player;

private long spawnTimer;
Expand Down Expand Up @@ -80,6 +81,9 @@ public GameScreen() {
leftButton = new Button(10, 60, 180, "buttons/control_button.png");
rightButton = new Button(150, 60, "buttons/control_button.png");

exit = new Button(1230, 450, "buttons/exit.png");
retry = new Button(500, 450, "buttons/retry.png");

//generating randomized background
Random r = new Random();
background = new Particle[r.nextInt(55-45)+45];
Expand Down Expand Up @@ -130,42 +134,74 @@ public void render(SpriteBatch sb, ShapeRenderer sr) {
for(Entity e : entities){
e.renderSB(sb);
}

leftButton.renderSB(sb);
rightButton.renderSB(sb);

scoreFont.draw(sb, "Score: "+score, 360, Game.HEIGHT-10);
sb.end();
System.out.println("Test");

if(health <= 0){
GlyphLayout layout = new GlyphLayout(scoreFont, "Game Over! Score: "+score);
float fontX = Game.WIDTH/4 + (Game.WIDTH/2 - layout.width) / 2;
sr.begin();
sr.set(ShapeRenderer.ShapeType.Filled);
sr.setColor(Color.GRAY);
sr.rect(Game.WIDTH/4, Game.HEIGHT*4/10, Game.WIDTH/2, Game.HEIGHT*4/10);
sr.end();

sb.begin();
retry.renderSB(sb);
exit.renderSB(sb);
scoreFont.draw(sb, "Game Over! Score: "+score, fontX, Game.HEIGHT*7/10);
sb.end();
}
}

@Override
public void tick() {
if(leftButton.clicked)
player.setDirection(-1);
else if(rightButton.clicked)
player.setDirection(1);
else
player.setDirection(0);
for(Entity e : entities){
e.tick();
}
if(dmgAnimation > 0){
health--;
dmgAnimation--;
}
if(health > 0) {
if (leftButton.clicked)
player.setDirection(-1);
else if (rightButton.clicked)
player.setDirection(1);
else
player.setDirection(0);
for (Entity e : entities) {
e.tick();
}
if (dmgAnimation > 0) {
health--;
dmgAnimation--;
}

if(System.currentTimeMillis() > spawnTimer){
entities.add(new Meteorite(meteoriteSprites, warningSprites));
long dtime = System.currentTimeMillis()-startTime;
if(dtime > 10000){
startTime = System.currentTimeMillis();
if (System.currentTimeMillis() > spawnTimer) {
entities.add(new Meteorite(meteoriteSprites, warningSprites));
long dtime = System.currentTimeMillis() - startTime;
if (dtime > 10000) {
startTime = System.currentTimeMillis();
}
spawnTimer = System.currentTimeMillis() + spawnFactor;
}
spawnTimer = System.currentTimeMillis()+spawnFactor;
}

scoreTimer++;
if(scoreTimer > 60){
score++;
scoreTimer = 0;
scoreTimer++;
if (scoreTimer > 60) {
score++;
scoreTimer = 0;
}
}else{
retry.tick();
exit.tick();

if(retry.clicked){
retry.clicked = false;
Game.setCurrentScreen(new GameScreen());
}

if(exit.clicked){
exit.clicked = false;
Game.setCurrentScreen(new MenuScreen());
}
}
}

Expand Down Expand Up @@ -199,6 +235,9 @@ else if(right)
pointers.put(pointer, 2);
else
pointers.put(pointer, 0);

retry.click(new Vector2(coords.x, coords.y));
exit.click(new Vector2(coords.x, coords.y));
}

@Override
Expand All @@ -217,29 +256,35 @@ public void touchUp(int screenX, int screenY, int pointer, int button) {
}
pointers.remove(pointer);
}
retry.release(new Vector2(coords.x, coords.y));
exit.release(new Vector2(coords.x, coords.y));
}

@Override
public void touchDragged(int screenX, int screenY, int pointer) {
Vector3 coords = camera.unproject(new Vector3(screenX, screenY, 0));
boolean left = leftButton.drag(new Vector2(coords.x, coords.y));
boolean right = rightButton.drag(new Vector2(coords.x, coords.y));
int currentValue = pointers.get(pointer);
pointers.remove(pointer);
if(left) {
pointers.put(pointer, 1);
leftButton.clicked = true;
rightButton.clicked = false;
}else if(right){
pointers.put(pointer, 2);
leftButton.clicked = false;
rightButton.clicked = true;
}else{
pointers.put(pointer, 0);
if(currentValue == 1)
leftButton.clicked = false;
else if(currentValue == 2)
if(pointers.containsKey(pointer)) {
int currentValue = pointers.get(pointer);
if (left) {
pointers.put(pointer, 1);
leftButton.clicked = true;
rightButton.clicked = false;
} else if (right) {
pointers.put(pointer, 2);
leftButton.clicked = false;
rightButton.clicked = true;
} else {
pointers.put(pointer, 0);
if (currentValue == 1)
leftButton.clicked = false;
else if (currentValue == 2)
rightButton.clicked = false;
}
pointers.remove(pointer);
}
retry.drag(new Vector2(coords.x, coords.y));
exit.drag(new Vector2(coords.x, coords.y));
}
}

0 comments on commit 2e9a93e

Please sign in to comment.