GameLoop and some skeleton classes

This commit is contained in:
Gulum
2017-10-16 15:15:32 +02:00
parent 5c16b98c1e
commit 59fcf074f6
14 changed files with 172 additions and 12 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/.nb-gradle/
/core/build/
/desktop/build/

View File

@@ -0,0 +1 @@
#Fri Oct 13 19:03:57 CEST 2017

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,49 +1,83 @@
package com.darkrp2d; package com.darkrp2d;
import com.badlogic.ashley.core.Engine;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.TimeUtils;
import com.darkrp2d.input.CommandStream; import com.darkrp2d.input.CommandStream;
import com.darkrp2d.input.InputHandler; import com.darkrp2d.input.InputHandler;
import com.darkrp2d.input.commands.Command; import com.darkrp2d.input.commands.Command;
import com.darkrp2d.input.commands.MenuCommand;
import com.darkrp2d.scenes.menu.MenuScreen;
public class DarkRP2D extends Game { public class DarkRP2D extends Game {
public BitmapFont font; public BitmapFont font;
public SpriteBatch batch; public SpriteBatch batch;
private Engine engine;
@Override @Override
public void create () { public void create () {
font = new BitmapFont(); font = new BitmapFont();
batch = new SpriteBatch(); batch = new SpriteBatch();
engine = new Engine();
//Sets inputs //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 @Override
// GameLoop
public void render () { public void render () {
//Update stuff lag += Gdx.graphics.getDeltaTime() * 1e3; //Seconds to milliseconds
timer += Gdx.graphics.getDeltaTime();
//Process Input
Command currentCommand = CommandStream.pollCommand(); Command currentCommand = CommandStream.pollCommand();
if(currentCommand != null) { if(currentCommand != null) {
currentCommand.execute(); 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.glClearColor(0.f, 0.f, 0.f, 1.f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//Render current Screen
super.render(); super.render();
batch.begin(); batch.begin();
GlyphLayout layout = new GlyphLayout(font, "Hello World"); 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); font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2);
batch.end(); batch.end();
} }
@Override @Override
public void dispose () { public void dispose () {

View File

@@ -24,4 +24,13 @@ public class IDEAS {
* - Ganzes haus voller Marihuana Pflanzen (Leute abhängig (rimworld) oder irgendwelche boosts) * - 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
*/
} }

View 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;
}
}

View File

@@ -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;
}

View File

@@ -7,7 +7,9 @@ package com.darkrp2d.input;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.InputProcessor;
import com.darkrp2d.DarkRP2D;
import com.darkrp2d.input.commands.*; import com.darkrp2d.input.commands.*;
import com.darkrp2d.scenes.menu.MenuScreen;
/** /**
* *
@@ -18,12 +20,9 @@ public class InputHandler implements InputProcessor {
Command testCommand; Command testCommand;
Command menuCommand; Command menuCommand;
public InputHandler(DarkRP2D game) {
public InputHandler(MenuCommand menuCommand) {
testCommand = new TestCommand(); testCommand = new TestCommand();
this.menuCommand = menuCommand; this.menuCommand = new MenuCommand(game, new MenuScreen(game));
} }
@Override @Override

View 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 {
}

View 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.
}
}