From 0253cc1a28bf12482cff2f6e1ef64ac8d023f4a7 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 11 May 2020 11:55:49 +0200 Subject: [PATCH] added an update method to handle calculation --- core/src/netwerkprog/game/MainGame.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/netwerkprog/game/MainGame.java b/core/src/netwerkprog/game/MainGame.java index e66162d..bbe8398 100644 --- a/core/src/netwerkprog/game/MainGame.java +++ b/core/src/netwerkprog/game/MainGame.java @@ -9,6 +9,8 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import netwerkprog.game.client.Client; +import netwerkprog.game.server.Server; public class MainGame extends ApplicationAdapter { SpriteBatch batch; @@ -33,20 +35,34 @@ public class MainGame extends ApplicationAdapter { music.setVolume(.1f); music.play(); music.setLooping(true); + + connectToServer(); + } + + private void connectToServer() { + Client client = new Client("localhost", Server.PORT); + client.start(); } @Override public void render() { + update(); Gdx.gl.glClearColor(xPos/Gdx.graphics.getWidth(), 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); - updatePos(); batch.draw(img, xPos, yPos); batch.end(); - frameRate.update(); frameRate.render(); } + /** + * update method that does all calculation before something is being drawn + */ + public void update() { + frameRate.update(); + updatePos(); + } + private void updatePos() { yPos += yUpdate; xPos += xUpdate;