Commit c5182e8c authored by Fjen Undso's avatar Fjen Undso
Browse files

gameover: fix funny colors and cleanup

parent ba08d3b2
......@@ -10,12 +10,13 @@ import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
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.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.math.Vector2;
public class GameOverScreen implements Screen {
Game game;
......@@ -28,7 +29,6 @@ public class GameOverScreen implements Screen {
float wWidth;
public GameOverScreen(int p1Score,int p2Score) {
p1 = p1Score;
p2 = p2Score;
......@@ -37,17 +37,18 @@ public class GameOverScreen implements Screen {
game = FrozenNumbersGame.game;
m_Screens = FrozenNumbersGame.m_Screens;
//generating backround
bg = new Sprite(FrozenNumbersGame.assets.get("backgrounds/main-screen.png", Texture.class));
bg.setSize(wWidth, wHeight);
//generating backround
bg = new Sprite(FrozenNumbersGame.assets.get("backgrounds/main-screen.png", Texture.class));
float scaleX = wWidth / bg.getWidth();
float scaleY = wHeight / bg.getHeight();
bg.setScale(scaleX, scaleY);
bg.setCenter(wWidth / 2.0f, wHeight / 2.0f);
bg.setColor(Color.LIGHT_GRAY);
//generating Close button#
close = new Sprite(FrozenNumbersGame.assets.get("sprites/btn_back.png", Texture.class));
close.setOriginCenter();
close.setPosition(wWidth / 2.0f - close.getWidth() / 2, 0.5f * wHeight - close.getHeight() / 2);
close.getBoundingRectangle();
close.setScale(scaleX, scaleY);
close.setCenter(wWidth / 2.0f, wHeight / 2.0f);
}
@Override
......@@ -57,73 +58,53 @@ public class GameOverScreen implements Screen {
@Override
public void render(float delta) {
float scaleX = bg.getWidth() / wWidth;
float scaleY = bg.getHeight() / wHeight;
if (Gdx.input.isTouched()){
if (Gdx.input.justTouched()) {
Vector2 touchPoint = new Vector2();
FrozenNumbersGame.viewport.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY()));
//Clicking Close Button
if(close.getBoundingRectangle().contains(Gdx.input.getX() * scaleX,(wHeight*scaleY-Gdx.input.getY()*scaleY)))
{
game.setScreen(m_Screens.get("MainMenu"));
if(close.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
game.setScreen(m_Screens.get("MainMenu"));
}
}
}
//resize Call
//TODO: Automatic resize call?
resize((int)wWidth,(int)wWidth);
//drawing stuff
Gdx.gl.glClearColor(1, 0, 0, 1);
//drawing stuff
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
FrozenNumbersGame.batch.begin();
bg.draw(FrozenNumbersGame.batch);
FrozenNumbersGame.batch.end();
FrozenNumbersGame.shapeRenderer.begin(ShapeType.Filled);
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
String p1String = "";
String p2String = "";
Batch batch = FrozenNumbersGame.batch;
FrozenNumbersGame.viewport.apply(true);
batch.setProjectionMatrix(FrozenNumbersGame.viewport.getCamera().combined);
batch.begin();
bg.draw(batch);
close.draw(batch);
String p1String = new String();
String p2String = new String();
if(p1 > p2)
{
FrozenNumbersGame.shapeRenderer.setColor(0f,1f,0f,.1f);
FrozenNumbersGame.shapeRenderer.rect(0,(float) (wHeight/2.0),wWidth,(float) (-wHeight/2.0));
FrozenNumbersGame.shapeRenderer.setColor(1f,0f,0f,.1f);
FrozenNumbersGame.shapeRenderer.rect(0,(float) (wHeight/2.0),wWidth,(float) (wHeight/2.0));
p1String = "WIN";
p2String = "LOSE";
}
if(p2 > p1)
{
FrozenNumbersGame.shapeRenderer.setColor(1f,0f,0f,.1f);
FrozenNumbersGame.shapeRenderer.rect(0,(float) (wHeight/2.0),wWidth,(float) (-wHeight/2.0));
FrozenNumbersGame.shapeRenderer.setColor(0f,1f,0f,.1f);
FrozenNumbersGame.shapeRenderer.rect(0,(float) (wHeight/2.0),wWidth,(float) (wHeight/2.0));
p1String = "LOSE";
p2String = "WIN";
}
if(p2 == p1)
{
FrozenNumbersGame.shapeRenderer.setColor(.5f,.5f,0f,.1f);
FrozenNumbersGame.shapeRenderer.rect(0,0,wWidth,wHeight);
p1String = "DRAW";
p2String = "DRAW";
}
FrozenNumbersGame.shapeRenderer.end();
FrozenNumbersGame.batch.begin();
GlyphLayout glyphLayout = new GlyphLayout();
float w = 0;
glyphLayout.setText(FrozenNumbersGame.assets.get("size20.ttf", BitmapFont.class),String.valueOf(p1));
w = glyphLayout.width;
FrozenNumbersGame.assets.get("size20.ttf", BitmapFont.class).draw(FrozenNumbersGame.batch, glyphLayout, (wWidth - w)/2, (float)(wHeight/4.0));
FrozenNumbersGame.assets.get("size20.ttf", BitmapFont.class).draw(batch, glyphLayout, (wWidth - w)/2, (float)(wHeight/4.0));
glyphLayout.setText(FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class),p1String);
w = glyphLayout.width;
FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class).draw(FrozenNumbersGame.batch, glyphLayout, (wWidth - w)/2, (float)(wHeight/4.0 - 50));
FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class).draw(batch, glyphLayout, (wWidth - w)/2, (float)(wHeight/4.0 - 50));
Label p2TextLabel = new Label(p2String, new Label.LabelStyle(FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class), Color.WHITE));
Table container = new Table();
......@@ -131,7 +112,7 @@ public class GameOverScreen implements Screen {
container.add(p2TextLabel);
container.setRotation(180);
container.setPosition((float) (wWidth / 2.0), (float) (wHeight / 2.0 + (wHeight/4.0) + 60));
container.draw(FrozenNumbersGame.batch, 1);
container.draw(batch, 1);
Label p2ScoreLabel = new Label(String.valueOf(p2), new Label.LabelStyle(FrozenNumbersGame.assets.get("size20.ttf", BitmapFont.class), Color.WHITE));
container = new Table();
......@@ -139,18 +120,15 @@ public class GameOverScreen implements Screen {
container.add(p2ScoreLabel);
container.setRotation(180);
container.setPosition((float) (wWidth / 2.0), (float) (wHeight / 2.0 + (wHeight/4.0)));
container.draw(FrozenNumbersGame.batch, 1);
close.draw(FrozenNumbersGame.batch);
FrozenNumbersGame.batch.end();
container.draw(batch, 1);
batch.end();
}
@Override
public void resize(int width, int height) {
wWidth = FrozenNumbersGame.viewport.getWorldWidth();
wHeight = FrozenNumbersGame.viewport.getWorldHeight();
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment