Added borders to level.
This commit is contained in:
parent
fed3680c18
commit
78d9890437
Binary file not shown.
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 132 KiB |
@ -61,7 +61,6 @@ public class EntityFactory {
|
||||
dummy.add(new CAI().setReactDistance(5).setAIListener(new DummyAI()));
|
||||
|
||||
AppUtil.engine.addEntity(dummy);
|
||||
dummy.getComponent(CCombat.class).inputs.put(Direction.UP, true);
|
||||
}
|
||||
|
||||
private CRenderedObject createPlayerRenderedObject() {
|
||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.saltosion.gladiator.components.CPhysics;
|
||||
import com.saltosion.gladiator.components.CRenderedObject;
|
||||
import com.saltosion.gladiator.systems.RenderingSystem;
|
||||
import com.saltosion.gladiator.util.AppUtil;
|
||||
import com.saltosion.gladiator.util.Global;
|
||||
import com.saltosion.gladiator.util.Name;
|
||||
@ -25,31 +26,53 @@ public class TestLevel implements Level {
|
||||
audienceRO.playAnimation("Default-Animation");
|
||||
audience.add(audienceRO);
|
||||
CPhysics audiencePO = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setProcessCollisions(false).setGhost(true).setPosition(0, 10).setZParallax(9);
|
||||
.setProcessCollisions(false).setGhost(true).setPosition(0, 10).setZParallax(9)
|
||||
.setSize(audienceSprite0.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
audienceSprite0.getRegionHeight() * Global.SPRITE_SCALE);
|
||||
audience.add(audiencePO);
|
||||
AppUtil.engine.addEntity(audience);
|
||||
|
||||
// Wall
|
||||
Entity wall = new Entity();
|
||||
CRenderedObject wallRO = new CRenderedObject(SpriteLoader.loadSprite(Name.WALLIMG));
|
||||
Sprite wallSprite = SpriteLoader.loadSprite(Name.WALLIMG);
|
||||
CRenderedObject wallRO = new CRenderedObject(wallSprite);
|
||||
wall.add(wallRO);
|
||||
CPhysics wallPO = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setProcessCollisions(false).setGhost(true).setPosition(0, 2).setZParallax(1.5f);
|
||||
.setProcessCollisions(false).setGhost(true).setPosition(0, 2).setZParallax(1.5f)
|
||||
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||
wall.add(wallPO);
|
||||
AppUtil.engine.addEntity(wall);
|
||||
|
||||
// Ground
|
||||
Entity ground = new Entity();
|
||||
Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG);
|
||||
CRenderedObject renderedObject = new CRenderedObject(groundSprite);
|
||||
ground.add(renderedObject);
|
||||
CPhysics physics = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false)
|
||||
CRenderedObject groundRO = new CRenderedObject(groundSprite);
|
||||
ground.add(groundRO);
|
||||
CPhysics groundPO = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false)
|
||||
.setSize(groundSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||
physics.getPosition().set(new Vector2(0, -4));
|
||||
ground.add(physics);
|
||||
groundPO.getPosition().set(new Vector2(0, -4));
|
||||
ground.add(groundPO);
|
||||
AppUtil.engine.addEntity(ground);
|
||||
|
||||
// Level borders
|
||||
float xClamp = groundPO.getSize().x / 2f;
|
||||
AppUtil.engine.getSystem(RenderingSystem.class).setXMin(-xClamp).setXMax(xClamp);
|
||||
|
||||
Entity borderLeft = new Entity();
|
||||
CPhysics borderLeftPhysics = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setProcessCollisions(false).setSize(0.1f, 20);
|
||||
borderLeftPhysics.setPosition(-xClamp - borderLeftPhysics.getSize().x, 0);
|
||||
borderLeft.add(borderLeftPhysics);
|
||||
AppUtil.engine.addEntity(borderLeft);
|
||||
Entity borderRight = new Entity();
|
||||
CPhysics borderRightPhysics = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setProcessCollisions(false).setSize(0.1f, 20);
|
||||
borderRightPhysics.setPosition(xClamp + borderRightPhysics.getSize().x, 0);
|
||||
borderRight.add(borderRightPhysics);
|
||||
AppUtil.engine.addEntity(borderRight);
|
||||
|
||||
// Generate entities
|
||||
AppUtil.entityFactory.createPlayer(new Vector2(0, 5));
|
||||
AppUtil.entityFactory.createDummy(new Vector2(-6, 5));
|
||||
|
@ -57,6 +57,8 @@ public class RenderingSystem extends EntitySystem {
|
||||
|
||||
private List<TextObject> drawableText;
|
||||
|
||||
private float xMin = -15, xMax = 15;
|
||||
|
||||
@Override
|
||||
public void addedToEngine(Engine engine) {
|
||||
updateEntities(engine);
|
||||
@ -211,8 +213,8 @@ public class RenderingSystem extends EntitySystem {
|
||||
int spriteHeight = currSprite.getRegionHeight();
|
||||
int spriteWidth = currSprite.getRegionWidth();
|
||||
|
||||
currSprite.setPosition(((physics.getPosition().x - spriteWidth / 2) - playerPhys.getPosition().x / physics.getZParallax() + camera.viewportWidth / 2),
|
||||
(physics.getPosition().y - spriteHeight / 2) - playerPhys.getPosition().y / physics.getZParallax() + camera.viewportHeight / 3);
|
||||
currSprite.setPosition(((physics.getPosition().x - spriteWidth / 2) + getCameraOffset(playerPhys, physics).x),
|
||||
(physics.getPosition().y - spriteHeight / 2) + getCameraOffset(playerPhys, physics).y);
|
||||
currSprite.draw(batch);
|
||||
|
||||
float nextFrame = renderedObject.getCurrentFrame(channel) + deltaTime * currSequence.getPlayspeed();
|
||||
@ -256,10 +258,10 @@ public class RenderingSystem extends EntitySystem {
|
||||
debugRenderer.begin(ShapeType.Line);
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
CPhysics physics = pm.get(entities.get(i));
|
||||
float x0 = physics.getPosition().x - physics.getSize().x / 2 - playerPhys.getPosition().x / physics.getZParallax() + camera.viewportWidth / 2;
|
||||
float x1 = physics.getPosition().x + physics.getSize().x / 2 - playerPhys.getPosition().x / physics.getZParallax() + camera.viewportWidth / 2;
|
||||
float y0 = physics.getPosition().y - physics.getSize().y / 2 - playerPhys.getPosition().y / physics.getZParallax() + camera.viewportHeight / 3;
|
||||
float y1 = physics.getPosition().y + physics.getSize().y / 2 - playerPhys.getPosition().y / physics.getZParallax() + camera.viewportHeight / 3;
|
||||
float x0 = physics.getPosition().x - physics.getSize().x / 2 + getCameraOffset(playerPhys, physics).x;
|
||||
float x1 = physics.getPosition().x + physics.getSize().x / 2 + getCameraOffset(playerPhys, physics).x;
|
||||
float y0 = physics.getPosition().y - physics.getSize().y / 2 + getCameraOffset(playerPhys, physics).y;
|
||||
float y1 = physics.getPosition().y + physics.getSize().y / 2 + getCameraOffset(playerPhys, physics).y;
|
||||
|
||||
debugRenderer.setColor(debugColor);
|
||||
debugRenderer.line(x0, y0, x1, y0);
|
||||
@ -292,10 +294,8 @@ public class RenderingSystem extends EntitySystem {
|
||||
drawableText.add(new TextObject(text, position));
|
||||
}
|
||||
|
||||
public
|
||||
void updateEntities(Engine engine) {
|
||||
entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPhysics.class
|
||||
));
|
||||
public void updateEntities(Engine engine) {
|
||||
entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPhysics.class));
|
||||
}
|
||||
|
||||
public boolean getDebug() {
|
||||
@ -310,6 +310,31 @@ public class RenderingSystem extends EntitySystem {
|
||||
return new Vector2(this.camera.position.x, this.camera.position.y);
|
||||
}
|
||||
|
||||
private Vector2 getCameraOffset(CPhysics playerPhys, CPhysics currPhys) {
|
||||
Vector2 offset = new Vector2(Math.max(xMin + camera.viewportWidth / 2, Math.min(xMax - camera.viewportWidth / 2,
|
||||
-playerPhys.getPosition().x)) / currPhys.getZParallax() + camera.viewportWidth / 2,
|
||||
-playerPhys.getPosition().y / currPhys.getZParallax() + camera.viewportHeight / 3);
|
||||
return offset;
|
||||
}
|
||||
|
||||
public float getXMin() {
|
||||
return xMin;
|
||||
}
|
||||
|
||||
public RenderingSystem setXMin(float xMin) {
|
||||
this.xMin = xMin;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getXMax() {
|
||||
return xMax;
|
||||
}
|
||||
|
||||
public RenderingSystem setXMax(float xMax) {
|
||||
this.xMax = xMax;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
batch.dispose();
|
||||
debugRenderer.dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user