2015-04-08 15:59:01 +02:00
|
|
|
package com.saltosion.gladiator;
|
|
|
|
|
2015-04-08 18:19:14 +02:00
|
|
|
import com.badlogic.ashley.core.Engine;
|
2015-04-08 19:15:14 +02:00
|
|
|
import com.badlogic.ashley.core.Entity;
|
|
|
|
import com.badlogic.ashley.core.EntityListener;
|
|
|
|
import com.badlogic.ashley.core.Family;
|
2015-04-08 15:59:01 +02:00
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
|
|
|
import com.badlogic.gdx.Gdx;
|
2015-04-08 18:19:14 +02:00
|
|
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
2015-04-08 19:50:13 +02:00
|
|
|
import com.saltosion.gladiator.components.CPosition;
|
2015-04-08 19:15:14 +02:00
|
|
|
import com.saltosion.gladiator.components.CRenderedObject;
|
|
|
|
import com.saltosion.gladiator.systems.RenderingSystem;
|
2015-04-08 18:19:14 +02:00
|
|
|
import com.saltosion.gladiator.util.GlobalStrings;
|
|
|
|
import com.saltosion.gladiator.util.SpriteLoader;
|
2015-04-08 15:59:01 +02:00
|
|
|
|
|
|
|
public class GladiatorBrawler extends ApplicationAdapter {
|
2015-04-08 18:19:14 +02:00
|
|
|
|
|
|
|
private Engine engine;
|
2015-04-08 15:59:01 +02:00
|
|
|
|
2015-04-08 19:15:14 +02:00
|
|
|
private Entity player;
|
|
|
|
|
2015-04-08 15:59:01 +02:00
|
|
|
@Override
|
|
|
|
public void create () {
|
2015-04-08 19:15:14 +02:00
|
|
|
// Initialize the Engine
|
|
|
|
|
2015-04-08 18:19:14 +02:00
|
|
|
engine = new Engine();
|
|
|
|
|
2015-04-08 19:15:14 +02:00
|
|
|
engine.addSystem(new RenderingSystem());
|
|
|
|
|
2015-04-08 19:50:13 +02:00
|
|
|
engine.addEntityListener(Family.getFor(CRenderedObject.class, CPosition.class),
|
2015-04-08 19:15:14 +02:00
|
|
|
new EntityListener() {
|
|
|
|
@Override
|
|
|
|
public void entityRemoved(Entity entity) {
|
|
|
|
RenderingSystem rs = engine.getSystem(RenderingSystem.class);
|
|
|
|
rs.updateEntities(engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void entityAdded(Entity entity) {
|
|
|
|
RenderingSystem rs = engine.getSystem(RenderingSystem.class);
|
|
|
|
rs.updateEntities(engine);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Initialize player
|
|
|
|
|
|
|
|
initializePlayer();
|
|
|
|
|
2015-04-08 15:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render () {
|
2015-04-08 19:15:14 +02:00
|
|
|
engine.update(Gdx.graphics.getDeltaTime());
|
|
|
|
}
|
|
|
|
|
2015-04-08 23:12:07 +02:00
|
|
|
@Override
|
|
|
|
public void resize(int width, int height) {
|
|
|
|
super.resize(width, height);
|
|
|
|
RenderingSystem rs = engine.getSystem(RenderingSystem.class);
|
|
|
|
float aspectratio = ((float)width)/((float)height);
|
|
|
|
rs.setViewport((int)(rs.VPHEIGHT_CONST*aspectratio), rs.VPHEIGHT_CONST);
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:15:14 +02:00
|
|
|
public void initializePlayer() {
|
|
|
|
player = new Entity();
|
|
|
|
|
|
|
|
CRenderedObject renderedObject = new CRenderedObject();
|
2015-04-08 19:50:13 +02:00
|
|
|
Sprite player1 = SpriteLoader.loadSprite(GlobalStrings.PLAYERIMG, 0, 0, 64, 64);
|
|
|
|
Sprite player2 = SpriteLoader.loadSprite(GlobalStrings.PLAYERIMG, 1, 0, 64, 64);
|
|
|
|
SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2);
|
|
|
|
renderedObject.addSequence("Idle", sequence);
|
|
|
|
renderedObject.setCurrentSequence("Idle");
|
2015-04-08 19:15:14 +02:00
|
|
|
player.add(renderedObject);
|
2015-04-08 19:50:13 +02:00
|
|
|
player.add(new CPosition());
|
|
|
|
player.getComponent(CPosition.class).x = 50;
|
|
|
|
player.getComponent(CPosition.class).y = 50;
|
2015-04-08 19:15:14 +02:00
|
|
|
|
|
|
|
engine.addEntity(player);
|
2015-04-08 15:59:01 +02:00
|
|
|
}
|
|
|
|
}
|