diff --git a/core/src/com/mygdx/game/GameScreens/GamePlay.java b/core/src/com/mygdx/game/GameScreens/GamePlay.java index 311bf378905f810d4f690bc2ef347d21a3c10e7c..83c46e80cd282be69141cc06908ec85a81a75403 100644 --- a/core/src/com/mygdx/game/GameScreens/GamePlay.java +++ b/core/src/com/mygdx/game/GameScreens/GamePlay.java @@ -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); + } } diff --git a/core/src/com/mygdx/game/GameScreens/GameScreen.java b/core/src/com/mygdx/game/GameScreens/GameScreen.java index d85fe99cf147fc9fcf4a1900397fcad3e9e9e43b..4778e693597f68a2976f71500a8675f76ee29c4d 100644 --- a/core/src/com/mygdx/game/GameScreens/GameScreen.java +++ b/core/src/com/mygdx/game/GameScreens/GameScreen.java @@ -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(); } diff --git a/core/src/com/mygdx/game/GameScreens/GameScreenEnum.java b/core/src/com/mygdx/game/GameScreens/GameScreenEnum.java index beda66c36be035b1239df2d066be7483da5d7de6..8dcbc13b07f21fa38475bdcc5657262dea5b6226 100644 --- a/core/src/com/mygdx/game/GameScreens/GameScreenEnum.java +++ b/core/src/com/mygdx/game/GameScreens/GameScreenEnum.java @@ -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); } }; /** diff --git a/core/src/com/mygdx/game/TableFootball.java b/core/src/com/mygdx/game/TableFootball.java index 9e823dfb6e5ee72cf0698d44632cd51bc2dd8e44..fb931a3bd3e61a2d93546577b892eeaa518e0d7c 100644 --- a/core/src/com/mygdx/game/TableFootball.java +++ b/core/src/com/mygdx/game/TableFootball.java @@ -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 diff --git a/core/src/com/mygdx/game/bodies/Joystick.java b/core/src/com/mygdx/game/bodies/Joystick.java index 4a9f4cad7d5f6bf96ea486f9a8ac5cad19abac2b..10c50281dfd01122108e7e46fe23f03621d937fe 100644 --- a/core/src/com/mygdx/game/bodies/Joystick.java +++ b/core/src/com/mygdx/game/bodies/Joystick.java @@ -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 diff --git a/core/src/com/mygdx/game/singletons/FontManager.java b/core/src/com/mygdx/game/singletons/FontManager.java deleted file mode 100644 index 5dd091df99a8fd5f1c411120f2a060c824d0e428..0000000000000000000000000000000000000000 --- a/core/src/com/mygdx/game/singletons/FontManager.java +++ /dev/null @@ -1,52 +0,0 @@ -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; - } -}