public class PongGame extends ApplicationAdapter
{
private ShapeRenderer renderer;
private boolean spacePressed;
private boolean leftPressed;
private boolean rightPressed;
private boolean upPressed;
private boolean downPressed;
private boolean aPressed;
private boolean wPressed;
private boolean sPressed;
private boolean dPressed;
@Override
public void create ()
{
renderer = new ShapeRenderer();
spacePressed = false;
leftPressed = false;
rightPressed = false;
upPressed = false;
downPressed = false;
aPressed = false;
wPressed = false;
sPressed = false;
dPressed = false;
}
@Override
public void render()
{
//Update
rightPressed = Gdx.input.isKeyPressed(Input.Keys.RIGHT);
leftPressed = Gdx.input.isKeyPressed(Input.Keys.LEFT);
downPressed = Gdx.input.isKeyPressed(Input.Keys.DOWN);
upPressed = Gdx.input.isKeyPressed(Input.Keys.UP);
spacePressed = Gdx.input.isKeyPressed(Input.Keys.SPACE);
aPressed = Gdx.input.isKeyPressed(Input.Keys.A);
dPressed = Gdx.input.isKeyPressed(Input.Keys.D);
sPressed = Gdx.input.isKeyPressed(Input.Keys.S);
wPressed = Gdx.input.isKeyPressed(Input.Keys.W);
//Clear the screen
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//Render circle in new location.
renderer.begin(ShapeType.Filled);
renderer.setColor(Color.BLUE);
//RENDER
LEFT BUTTON
if (leftPressed || aPressed)
{
renderer.setColor(Color.RED);
}
else
{
renderer.setColor(Color.BLUE);
}
renderer.rect(10,10,200,200); //left
//RENDER
DOWN BUTTON
if (downPressed || sPressed)
{
renderer.setColor(Color.RED);
}
else
{
renderer.setColor(Color.BLUE);
}
renderer.rect(220,10,200,200); //down
//RENDER
RIGHT BUTTON
if (rightPressed || dPressed)
{
renderer.setColor(Color.RED);
}
else
{
renderer.setColor(Color.BLUE);
}
renderer.rect(430,10,200,200); //right
//RENDER
UP BUTTON
if (upPressed || wPressed)
{
renderer.setColor(Color.RED);
}
else
{
renderer.setColor(Color.BLUE);
}
renderer.rect(220,220,200,200); //top
//RENDER
SPACE BUTTON
if (spacePressed)
{
renderer.setColor(Color.RED);
}
else
{
renderer.setColor(Color.BLUE);
}
renderer.rect(10, 430, 620, 40); //space
renderer.end();
}
}
|