Skip to content
Snippets Groups Projects
Commit 14a5c236 authored by ALGLAVE Ivan's avatar ALGLAVE Ivan
Browse files

Fixed text positions and size in the GamePlay screen (scores and time)

parent 1fb4f390
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,16 @@ public class GamePlay extends GameScreen
long duration;
int remaining;
boolean isAI;
float text_left_x, text_right_x, text_time_x, text_y, text_w;
public GamePlay(boolean is2ndPlayerAI)
{
super();
isAI = is2ndPlayerAI;
}
@Override
public void buildStage()
{
......@@ -69,7 +79,7 @@ public class GamePlay extends GameScreen
field = new Field(world);
fieldBounds = new FieldBounds(world);
ball = new Ball(world, new Vector2(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f));
pleft = new Player(world, Player.TYPE.LEFT);
pleft = isAI ? new Player(world, Player.TYPE.AI) : new Player(world, Player.TYPE.LEFT);
pright = new Player(world, Player.TYPE.RIGHT);
jleft = new Joystick(world, Joystick.SIDE.LEFT);
jright = new Joystick(world, Joystick.SIDE.RIGHT);
......@@ -79,7 +89,7 @@ public class GamePlay extends GameScreen
FreeTypeFontGenerator fGen = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Comic_Sans_MS_Bold.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter fp = new FreeTypeFontGenerator.FreeTypeFontParameter();
fp.size = 1024/60;
fp.size = (int)(width()/1024f * 60f);
fp.color = new Color(1f, 1f, 0f, 0.75f);
fp.borderColor = Color.BLACK;
fp.borderWidth = 3f;
......@@ -87,6 +97,12 @@ public class GamePlay extends GameScreen
font = fGen.generateFont(fp);
fGen.dispose();
text_left_x = width()*0.25f - width()*0.10f;
text_time_x = width()*0.5f - width()*0.10f;
text_right_x = width()*0.75f - width()*0.10f;
text_y = height()*0.97f;
text_w = width()*0.20f;
scoreLeft = 0;
scoreRight = 0;
duration = 180;
......@@ -163,7 +179,7 @@ public class GamePlay extends GameScreen
remaining = (int)(duration - (System.currentTimeMillis() - creationDate) / 1000);
displayTexts(batch);
b2dd.render(world, debugMatrix);
//b2dd.render(world, debugMatrix);
world.step(delta, 1, 1);
......@@ -182,9 +198,10 @@ public class GamePlay extends GameScreen
private void displayTexts(SpriteBatch batch)
{
font.draw(batch, "" + scoreLeft, width()*0.25f, height()*0.985f);
font.draw(batch, "" + scoreRight, width()*0.75f, height()*0.985f);
font.draw(batch, "" + remaining, width()/2f, height()*0.985f);
font.draw(batch, "" + scoreLeft, text_left_x, text_y, text_w, 1, true);
font.draw(batch, "" + scoreRight, text_right_x, text_y, text_w, 1, true);
font.draw(batch, "" + remaining, text_time_x, text_y, text_w, 1, true);
}
private void score(Player player)
......@@ -198,4 +215,9 @@ public class GamePlay extends GameScreen
{
return Gdx.input.isKeyPressed(key);
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
}
......@@ -30,8 +30,8 @@ public abstract class GameScreen extends Stage implements Screen
protected void beforeRender()
{
// Clear screen
//Gdx.gl.glClearColor(0, 0, 0, 1);
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
}
......
......@@ -25,13 +25,20 @@ public enum GameScreenEnum
},
/**
* Play screen
* Play screen with 2 players
*/
GAME_PLAY {
public GameScreen getScreen(Object... args)
{
return new GamePlay();
return new GamePlay(false);
}
},
/**
* Play screen with AI
*/
GAME_PLAY_AI {
public GameScreen getScreen(Object... args) { return new GamePlay(true); }
};
/**
......
......@@ -17,7 +17,7 @@ public class TableFootball extends Game {
public void create ()
{
GameScreenManager.getInstance().initialize(this); // Initialize the GameScreenManager instance with the current Game
GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_PLAY); // Set the base screen as the intro screen
GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_PLAY_AI); // Set the base screen as the intro screen
}
@Override
......
......@@ -7,10 +7,12 @@ import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.graphics.Color;
public class Joystick
{
private TextureBody tb;
private SIDE side;
public Joystick(World world, SIDE side)
{
......@@ -29,6 +31,8 @@ public class Joystick
fdef.restitution = 0f;
fdef.friction = 0f;
this.side = side;
bdef.active = false;
tb = new TextureBody(Gdx.files.internal( "images/Pad.png"), world, bdef, fdef, Gdx.graphics.getWidth()*0.1f, Gdx.graphics.getWidth()*0.1f);
......@@ -36,7 +40,17 @@ public class Joystick
public void draw(SpriteBatch batch)
{
Color or = batch.getColor();
if(side == SIDE.LEFT)
{
batch.setColor(Color.YELLOW);
}
else
{
batch.setColor(Color.CYAN);
}
tb.draw(batch);
batch.setColor(or);
}
public enum SIDE
......
package com.mygdx.game.singletons;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
public class FontManager
{
private static FontManager fm = new FontManager();
private AssetManager am;
private FontManager()
{
am = new AssetManager();
}
public static FontManager getInstance()
{
return fm;
}
public BitmapFont generateFont()
{
/*FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("HFF Ice Bergman.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 30;
parameter.borderWidth = 1;
parameter.color = Color.BLUE;
parameter.shadowOffsetX = 3;
parameter.shadowOffsetY = 3;
parameter.shadowColor = new Color(0, 0.5f, 0, 0.75f);
BitmapFont font = generator.generateFont(parameter); // font size 24 pixels
generator.dispose();
return font;*/
return null;
}
public Label.LabelStyle getLabelStyle(Color fontColor)
{
/*Label.LabelStyle l = new Label.LabelStyle();
l.font = generateFont();
l.fontColor = fontColor;
return l;*/
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment