Added util package for all mutual classes between server and client.

Added FrameRate and GameApplicationConfiguration to util package.
Added super class for controllers.
Added controllers package for server and client packages.
Added gamecontroller for server.
Added character, object and score controllers for server and create them on gamecontroller creation.
Added sessioncontroller for server and client.
Added graphicsController for client.
Removed unused imports.
This commit is contained in:
MickWerf
2020-05-11 14:32:22 +02:00
parent 2596b913fc
commit f56af5e3dd
12 changed files with 61 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
package netwerkprog.game.util;
public abstract class Controller {
}

View File

@@ -0,0 +1,62 @@
package netwerkprog.game.util;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils;
/**
* A nicer class for showing framerate that doesn't spam the console
* like Logger.log()
*
* @author William Hartman
*/
public class FrameRate implements Disposable{
long lastTimeCounted;
private float sinceChange;
private float frameRate;
private BitmapFont font;
private SpriteBatch batch;
private OrthographicCamera cam;
public FrameRate() {
lastTimeCounted = TimeUtils.millis();
sinceChange = 0;
frameRate = Gdx.graphics.getFramesPerSecond();
font = new BitmapFont();
batch = new SpriteBatch();
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
public void resize(int screenWidth, int screenHeight) {
cam = new OrthographicCamera(screenWidth, screenHeight);
cam.translate(screenWidth / 2, screenHeight / 2);
cam.update();
batch.setProjectionMatrix(cam.combined);
}
public void update() {
long delta = TimeUtils.timeSinceMillis(lastTimeCounted);
lastTimeCounted = TimeUtils.millis();
sinceChange += delta;
if(sinceChange >= 1000) {
sinceChange = 0;
frameRate = Gdx.graphics.getFramesPerSecond();
}
}
public void render() {
batch.begin();
font.draw(batch, (int)frameRate + " fps", 3, Gdx.graphics.getHeight() - 3);
batch.end();
}
public void dispose() {
font.dispose();
batch.dispose();
}
}

View File

@@ -0,0 +1,73 @@
package netwerkprog.game.util;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
/**
* custom application config class for the game
*/
public class GameApplicationConfiguration extends LwjglApplicationConfiguration {
/**
* makes a new configuration with the given parameters
* @param width the width (in pixels)
* @param height the height (in pixels)
* @param fullscreen whether the app should run in fullscreen
*/
public GameApplicationConfiguration(int width, int height, boolean fullscreen) {
super();
super.width = width;
super.height = height;
super.fullscreen = fullscreen;
}
/**
* makes a new configuration with the given parameters.
* No fullscreen
* @param width the width (in pixels)
* @param height the height (in pixels)
*/
public GameApplicationConfiguration(int width, int height) {
this(width,height,false);
}
/**
* makes a new configuration with standard full hd width and height
*/
public GameApplicationConfiguration() {
this(1920,1080,false);
}
/**
* Makes a new configuration with the given parameters
* @param title the title of the window
* @param width the width in pixels
* @param height the height in pixels
* @param fullscreen if the window should be fullscreen
*/
public GameApplicationConfiguration(String title, int width, int height, boolean fullscreen) {
super();
super.width = width;
super.height = height;
super.title = title;
super.fullscreen = fullscreen;
}
/**
* Makes a new configuration with the given parameters.
* fullscreen is off
* @param title the window title
* @param width the width in pixels
* @param height the height in pixels
*/
public GameApplicationConfiguration(String title, int width, int height) {
this(title,width,height,false);
}
/**
* Makes a new configuration with the given title
* the window will be 1920 x 1080 and fullscreen will be off
* @param title the window title
*/
public GameApplicationConfiguration(String title) {
this(title, 1920,1080);
}
}