ColorRunner/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java

60 lines
2.0 KiB
Java
Raw Normal View History

2014-08-10 17:19:40 +02:00
package de.samdev.colorrunner.game.renderer;
2014-08-11 02:32:28 +02:00
import com.badlogic.gdx.Gdx;
2014-08-10 17:19:40 +02:00
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
2014-08-10 20:59:50 +02:00
import com.badlogic.gdx.math.Vector2;
2014-08-11 02:32:28 +02:00
import com.badlogic.gdx.math.Vector3;
2014-08-10 17:19:40 +02:00
import de.samdev.colorrunner.game.world.CRGameWorld;
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
2014-08-10 20:59:50 +02:00
import de.samdev.colorrunner.game.world.entities.MovingEntity;
2014-08-10 17:19:40 +02:00
public class CRGameRenderer extends AbstractGameRenderer {
private CRGameWorld gameworld;
2014-08-10 20:59:50 +02:00
public double avgExecTime = 0;
2014-08-10 17:19:40 +02:00
public CRGameRenderer(CRGameWorld _world, float width, float height) {
super(width, height);
gameworld = _world;
}
@Override
public void doRender() {
2014-08-11 00:24:55 +02:00
updateCameraOffset(gameworld.player.bounds.x);
2014-08-10 20:59:50 +02:00
beginDebug();
2014-08-10 17:19:40 +02:00
renderDebug("FPS: " + (int)gameworld.fps.getFPS());
2014-08-10 20:59:50 +02:00
renderDebug("Entitys: " + gameworld.entities.size());
renderDebug("ExecTime: " + (int)(avgExecTime*100) / 100.0+ " / " + (int)(10000/gameworld.fps.getFPS())/10.0 + "ms (" + (int)((avgExecTime/(1000/gameworld.fps.getFPS()))*1000) / 10.0 + "%)");
endDebug();
2014-08-10 17:19:40 +02:00
2014-08-10 20:59:50 +02:00
spriteBatch.begin();
2014-08-11 02:32:28 +02:00
spriteBatch.enableBlending();
Vector3 cw_coords = cam.unproject(new Vector3(Gdx.graphics.getWidth(), 0, 0));
spriteBatch.draw(CRAssets.TEX_COLORWHEEL, cw_coords.x - 70, cw_coords.y - 70, 64, 64);
spriteBatch.disableBlending();
2014-08-10 17:19:40 +02:00
2014-08-10 20:59:50 +02:00
for (CRGameEntity e : gameworld.entities) {
spriteBatch.draw(e.getTexture(), e.bounds.x, e.bounds.y, e.bounds.width, e.bounds.height);
}
spriteBatch.end();
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.setColor(1, 0, 1, 1);
2014-08-10 17:19:40 +02:00
for (CRGameEntity e : gameworld.entities) {
shapeRenderer.rect(e.bounds.x, e.bounds.y, e.bounds.width, e.bounds.height);
2014-08-10 20:59:50 +02:00
if (e instanceof MovingEntity) {
MovingEntity me = (MovingEntity) e;
shapeRenderer.line(me.bounds.getCenter(new Vector2()), me.bounds.getCenter(new Vector2()).add(me.getVelocity().x / 15f, 0));
shapeRenderer.line(me.bounds.getCenter(new Vector2()), me.bounds.getCenter(new Vector2()).add(0 , me.getVelocity().y / 15f));
}
2014-08-10 17:19:40 +02:00
}
shapeRenderer.end();
}
}