added new thread for client connection and added resize method
This commit is contained in:
@@ -19,7 +19,10 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
float yPos = 500;
|
float yPos = 500;
|
||||||
float xUpdate;
|
float xUpdate;
|
||||||
float yUpdate;
|
float yUpdate;
|
||||||
|
float screenWidth;
|
||||||
|
float screenHeight;
|
||||||
private FrameRate frameRate;
|
private FrameRate frameRate;
|
||||||
|
private Client client;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@@ -28,6 +31,8 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
float ratio = (float) Gdx.graphics.getWidth() / Gdx.graphics.getHeight();
|
float ratio = (float) Gdx.graphics.getWidth() / Gdx.graphics.getHeight();
|
||||||
xUpdate = ratio;
|
xUpdate = ratio;
|
||||||
yUpdate = ratio;
|
yUpdate = ratio;
|
||||||
|
screenWidth = Gdx.graphics.getWidth();
|
||||||
|
screenHeight = Gdx.graphics.getHeight();
|
||||||
frameRate = new FrameRate();
|
frameRate = new FrameRate();
|
||||||
|
|
||||||
// play music
|
// play music
|
||||||
@@ -40,14 +45,21 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void connectToServer() {
|
private void connectToServer() {
|
||||||
Client client = new Client("localhost", Server.PORT);
|
client = new Client("localhost", Server.PORT);
|
||||||
client.start();
|
try {
|
||||||
|
client.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("There was an error connecting : " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* render method that is called after the update method
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
update();
|
update();
|
||||||
Gdx.gl.glClearColor(xPos/Gdx.graphics.getWidth(), 0, 0, 1);
|
Gdx.gl.glClearColor(xPos / Gdx.graphics.getWidth(), 0, 0, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
batch.draw(img, xPos, yPos);
|
batch.draw(img, xPos, yPos);
|
||||||
@@ -66,15 +78,28 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
private void updatePos() {
|
private void updatePos() {
|
||||||
yPos += yUpdate;
|
yPos += yUpdate;
|
||||||
xPos += xUpdate;
|
xPos += xUpdate;
|
||||||
if (yPos > Gdx.graphics.getHeight() - img.getHeight() || yPos < 0) {
|
|
||||||
|
if (yPos > screenHeight - img.getHeight() || yPos < 0) {
|
||||||
yUpdate = -yUpdate;
|
yUpdate = -yUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xPos > Gdx.graphics.getWidth() - img.getWidth() || xPos < 0) {
|
if (xPos > screenWidth - img.getWidth() || xPos < 0) {
|
||||||
xUpdate = -xUpdate;
|
xUpdate = -xUpdate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height) {
|
||||||
|
super.resize(width, height);
|
||||||
|
screenHeight = height;
|
||||||
|
screenWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
super.resume();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user