GameLoop and some skeleton classes
This commit is contained in:
@@ -1,49 +1,83 @@
|
||||
package com.darkrp2d;
|
||||
|
||||
import com.badlogic.ashley.core.Engine;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.darkrp2d.input.CommandStream;
|
||||
import com.darkrp2d.input.InputHandler;
|
||||
import com.darkrp2d.input.commands.Command;
|
||||
import com.darkrp2d.input.commands.MenuCommand;
|
||||
import com.darkrp2d.scenes.menu.MenuScreen;
|
||||
|
||||
|
||||
public class DarkRP2D extends Game {
|
||||
|
||||
public BitmapFont font;
|
||||
public SpriteBatch batch;
|
||||
private Engine engine;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
font = new BitmapFont();
|
||||
batch = new SpriteBatch();
|
||||
|
||||
engine = new Engine();
|
||||
//Sets inputs
|
||||
Gdx.input.setInputProcessor(new InputHandler(new MenuCommand(this, new MenuScreen(this))));
|
||||
Gdx.input.setInputProcessor(new InputHandler(this));
|
||||
}
|
||||
|
||||
private double lag = 0.;
|
||||
private static final double MS_PER_UPDATE = 16.66;
|
||||
|
||||
private int ups = 0;
|
||||
private double timer = 0.;
|
||||
|
||||
@Override
|
||||
// GameLoop
|
||||
public void render () {
|
||||
//Update stuff
|
||||
lag += Gdx.graphics.getDeltaTime() * 1e3; //Seconds to milliseconds
|
||||
timer += Gdx.graphics.getDeltaTime();
|
||||
|
||||
//Process Input
|
||||
Command currentCommand = CommandStream.pollCommand();
|
||||
if(currentCommand != null) {
|
||||
currentCommand.execute();
|
||||
}
|
||||
//Render stuff
|
||||
|
||||
//Update Stuff
|
||||
while(lag >= MS_PER_UPDATE) {
|
||||
update();
|
||||
ups++;
|
||||
lag -= MS_PER_UPDATE;
|
||||
}
|
||||
|
||||
if(timer >= 1) {
|
||||
System.out.println(ups);
|
||||
ups = 0;
|
||||
timer = 0.;
|
||||
}
|
||||
|
||||
trueRender();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void trueRender() {
|
||||
Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
//Render current Screen
|
||||
super.render();
|
||||
|
||||
batch.begin();
|
||||
GlyphLayout layout = new GlyphLayout(font, "Hello World");
|
||||
font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2);
|
||||
batch.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
|
||||
@@ -24,4 +24,13 @@ public class IDEAS {
|
||||
* - Ganzes haus voller Marihuana Pflanzen (Leute abhängig (rimworld) oder irgendwelche boosts)
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO ORDER:
|
||||
* Add character from laptop
|
||||
* box2D Character/camera movement
|
||||
* Add World
|
||||
* Add Charakter
|
||||
* Add Cars
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
27
core/src/com/darkrp2d/entities/Character.java
Normal file
27
core/src/com/darkrp2d/entities/Character.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.darkrp2d.entities;
|
||||
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
import com.darkrp2d.entities.components.PositionComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Julian
|
||||
*/
|
||||
public class Character {
|
||||
|
||||
//Singletone
|
||||
private static Entity character;
|
||||
public static Entity create() {
|
||||
if(character == null) {
|
||||
character = new Entity();
|
||||
character.add(new PositionComponent());
|
||||
}
|
||||
return character;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.darkrp2d.entities.components;
|
||||
|
||||
import com.badlogic.ashley.core.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Julian
|
||||
*/
|
||||
public class PositionComponent implements Component {
|
||||
public float x = 0.f;
|
||||
public float y = 0.f;
|
||||
}
|
||||
@@ -7,7 +7,9 @@ package com.darkrp2d.input;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.darkrp2d.DarkRP2D;
|
||||
import com.darkrp2d.input.commands.*;
|
||||
import com.darkrp2d.scenes.menu.MenuScreen;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -18,12 +20,9 @@ public class InputHandler implements InputProcessor {
|
||||
Command testCommand;
|
||||
Command menuCommand;
|
||||
|
||||
|
||||
|
||||
public InputHandler(MenuCommand menuCommand) {
|
||||
public InputHandler(DarkRP2D game) {
|
||||
testCommand = new TestCommand();
|
||||
this.menuCommand = menuCommand;
|
||||
|
||||
this.menuCommand = new MenuCommand(game, new MenuScreen(game));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
14
core/src/com/darkrp2d/scenes/game/Camera.java
Normal file
14
core/src/com/darkrp2d/scenes/game/Camera.java
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.darkrp2d.scenes.game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Julian
|
||||
*/
|
||||
public class Camera {
|
||||
|
||||
}
|
||||
56
core/src/com/darkrp2d/scenes/game/GameScreen.java
Normal file
56
core/src/com/darkrp2d/scenes/game/GameScreen.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.darkrp2d.scenes.game;
|
||||
|
||||
import com.badlogic.gdx.Screen;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Julian
|
||||
*/
|
||||
public class GameScreen implements Screen {
|
||||
|
||||
//Pass server ip....
|
||||
public GameScreen(int ip) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user