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

Created a world, added the ball to the world, body constraints missing

parent bbe972b4
No related branches found
No related tags found
No related merge requests found
...@@ -18,18 +18,14 @@ import java.util.Date; ...@@ -18,18 +18,14 @@ import java.util.Date;
public class GameIntro extends GameScreen public class GameIntro extends GameScreen
{ {
BitmapFont bf = new BitmapFont(); BitmapFont bf = new BitmapFont();
long creationDate;
Texture intro; Texture intro;
String s; String s;
@Override @Override
public void buildStage() { public void buildStage()
/*Label l = new Label("Intro screen", FontManager.getInstance().getLabelStyle(Color.BLACK)); {
l.setPosition(50, 50);
addActor(l);*/
creationDate = System.currentTimeMillis();
bf.setColor(Color.RED); bf.setColor(Color.RED);
intro = new Texture(Gdx.files.internal("images/Intro.jpg")); intro = new Texture(Gdx.files.internal("images/Intro.jpg"));
...@@ -42,7 +38,7 @@ public class GameIntro extends GameScreen ...@@ -42,7 +38,7 @@ public class GameIntro extends GameScreen
batch.draw(intro, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.draw(intro, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
if(System.currentTimeMillis() - creationDate > 2000) if(System.currentTimeMillis() - creationDate > 3000)
{ {
// Intro screen is over // Intro screen is over
GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_MENU); GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_MENU);
......
...@@ -24,6 +24,11 @@ public class GameMenu extends GameScreen ...@@ -24,6 +24,11 @@ public class GameMenu extends GameScreen
batch.draw(menu, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.draw(menu, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
if(totalElapsedSeconds() > 3)
{
GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_PLAY);
}
super.render(delta); super.render(delta);
} }
} }
...@@ -3,6 +3,18 @@ package com.mygdx.game.GameScreens; ...@@ -3,6 +3,18 @@ package com.mygdx.game.GameScreens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Shape2D;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2D;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.Shape;
import com.badlogic.gdx.physics.box2d.World;
/** /**
* Gameplay screen, allowing the user to play against an IA or another player on a shared screen * Gameplay screen, allowing the user to play against an IA or another player on a shared screen
...@@ -10,14 +22,62 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; ...@@ -10,14 +22,62 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
*/ */
public class GamePlay extends GameScreen public class GamePlay extends GameScreen
{ {
Texture game_field, pad_left, pad_right, goal_left, goal_right, player_left, player_right, ball;
World world;
Body b_ball;
Box2DDebugRenderer b2dd;
@Override @Override
public void buildStage() { public void buildStage()
{
game_field = new Texture(Gdx.files.internal("images/Terrain.png"));
pad_left = new Texture(Gdx.files.internal("images/Pad.png"));
pad_right = new Texture(Gdx.files.internal("images/Pad.png"));
goal_left = new Texture(Gdx.files.internal("images/But.bmp"));
goal_right = new Texture(Gdx.files.internal("images/But.bmp"));
player_left = new Texture(Gdx.files.internal("images/JoueurGauche.png"));
player_right = new Texture(Gdx.files.internal("images/JoueurDroite.png"));
ball = new Texture(Gdx.files.internal("images/Ballon.png"));
world = new World(new Vector2(0, 0), true);
BodyDef bd_ball = new BodyDef();
bd_ball.type = BodyDef.BodyType.DynamicBody;
bd_ball.position.set(width()/2, height()/2);
b_ball = world.createBody(bd_ball);
FixtureDef fd_ball = new FixtureDef();
fd_ball.shape = new CircleShape();
fd_ball.shape.setRadius((1/85f) * width());
Fixture f = b_ball.createFixture(fd_ball);
b2dd = new Box2DDebugRenderer();
} }
@Override @Override
public void render(float delta) { public void render(float delta) {
beforeRender(); beforeRender();
batch.draw(game_field, width()*0.1f, 0, width()*0.8f, height());
batch.draw(ball, b_ball.getPosition().x, b_ball.getPosition().y, (1/85f)*width(), (1/85f)*width());
//b2dd.render(world, getCamera().combined);
world.step(delta, 1, 1);
super.render(delta); super.render(delta);
} }
private float width()
{
return Gdx.graphics.getWidth();
}
private float height()
{
return Gdx.graphics.getHeight();
}
} }
...@@ -15,9 +15,11 @@ public abstract class GameScreen extends Stage implements Screen ...@@ -15,9 +15,11 @@ public abstract class GameScreen extends Stage implements Screen
{ {
SpriteBatch batch = new SpriteBatch(); SpriteBatch batch = new SpriteBatch();
long creationDate;
protected GameScreen() { protected GameScreen() {
super( new StretchViewport(320.0f, 240.0f, new OrthographicCamera()) ); super( new StretchViewport(102.4f, 76.8f, new OrthographicCamera()) );
creationDate = System.currentTimeMillis();
} }
/** /**
...@@ -55,4 +57,9 @@ public abstract class GameScreen extends Stage implements Screen ...@@ -55,4 +57,9 @@ public abstract class GameScreen extends Stage implements Screen
@Override public void hide() {} @Override public void hide() {}
@Override public void pause() {} @Override public void pause() {}
@Override public void resume() {} @Override public void resume() {}
public long totalElapsedSeconds()
{
return (System.currentTimeMillis() - creationDate) / 1000;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment