Added parallaxing & audience.

This commit is contained in:
Jeasonfire 2015-05-16 22:28:56 +03:00
parent c98a16dae9
commit 9c3643682d
6 changed files with 51 additions and 18 deletions

View File

@ -11,6 +11,7 @@ public class CPhysics extends Component {
private final Vector2 size = new Vector2(); private final Vector2 size = new Vector2();
private float movespeed = 15f, jumpForce = 35f, gravity = 100f; private float movespeed = 15f, jumpForce = 35f, gravity = 100f;
private CollisionListener collisionListener = null; private CollisionListener collisionListener = null;
private float zParallax = 1;
private boolean movable = true; private boolean movable = true;
private boolean gravityApplied = true; private boolean gravityApplied = true;
@ -167,4 +168,13 @@ public class CPhysics extends Component {
return this.grounded; return this.grounded;
} }
public CPhysics setZParallax(float zParallax) {
this.zParallax = zParallax;
return this;
}
public float getZParallax() {
return this.zParallax;
}
} }

View File

@ -9,18 +9,29 @@ import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
import com.saltosion.gladiator.util.Name; import com.saltosion.gladiator.util.Name;
import com.saltosion.gladiator.util.SpriteLoader; import com.saltosion.gladiator.util.SpriteLoader;
import com.saltosion.gladiator.util.SpriteSequence;
public class TestLevel implements Level { public class TestLevel implements Level {
@Override @Override
public void generate() { public void generate() {
// Generate entities // Audience
AppUtil.entityFactory.createPlayer(new Vector2(0, 5)); Entity audience = new Entity();
AppUtil.entityFactory.createDummy(new Vector2(-6, 5));
// Generate level Sprite audienceSprite0 = SpriteLoader.loadSprite(Name.AUDIENCEIMG, 0, 0, 768, 576);
Sprite audienceSprite1 = SpriteLoader.loadSprite(Name.AUDIENCEIMG, 1, 0, 768, 576);
CRenderedObject audienceRO = new CRenderedObject();
SpriteSequence audienceAnim = new SpriteSequence(1).addSprite(audienceSprite0).addSprite(audienceSprite1);
audienceRO.addSequence("Default-Animation", audienceAnim);
audienceRO.playAnimation("Default-Animation");
audience.add(audienceRO);
CPhysics audiencePO = new CPhysics().setMovable(false).setGravityApplied(false)
.setProcessCollisions(false).setPosition(0, 10).setZParallax(9);
audience.add(audiencePO);
AppUtil.engine.addEntity(audience);
// Ground
Entity ground = new Entity(); Entity ground = new Entity();
Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG); Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG);
CRenderedObject renderedObject = new CRenderedObject(groundSprite); CRenderedObject renderedObject = new CRenderedObject(groundSprite);
ground.add(renderedObject); ground.add(renderedObject);
@ -29,8 +40,11 @@ public class TestLevel implements Level {
groundSprite.getRegionHeight() * Global.SPRITE_SCALE); groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
physics.getPosition().set(new Vector2(0, -4)); physics.getPosition().set(new Vector2(0, -4));
ground.add(physics); ground.add(physics);
AppUtil.engine.addEntity(ground); AppUtil.engine.addEntity(ground);
// Generate entities
AppUtil.entityFactory.createPlayer(new Vector2(0, 5));
AppUtil.entityFactory.createDummy(new Vector2(-6, 5));
} }
} }

View File

@ -9,7 +9,6 @@ import com.badlogic.ashley.utils.ImmutableArray;
import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Log;
public class PhysicsSystem extends EntitySystem { public class PhysicsSystem extends EntitySystem {
@ -99,8 +98,8 @@ public class PhysicsSystem extends EntitySystem {
} }
boolean collidedAlready = false; boolean collidedAlready = false;
float precisionX = COLLISION_PRECISION * (cp0.getSize().x > cp1.getSize().x ? cp0.getSize().x : cp1.getSize().x); float precisionX = COLLISION_PRECISION * (float) Math.sqrt(cp0.getSize().x > cp1.getSize().x ? cp0.getSize().x : cp1.getSize().x);
float precisionY = COLLISION_PRECISION * (cp0.getSize().y > cp1.getSize().y ? cp0.getSize().y : cp1.getSize().y); float precisionY = COLLISION_PRECISION * (float) Math.sqrt(cp0.getSize().y > cp1.getSize().y ? cp0.getSize().y : cp1.getSize().y);
if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.getSize().x + cp1.getSize().x) / precisionX) { if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.getSize().x + cp1.getSize().x) / precisionX) {
// cp0's left side is colliding with cp1's right side // cp0's left side is colliding with cp1's right side

View File

@ -26,7 +26,6 @@ import com.saltosion.gladiator.gui.nodes.TextNode;
import com.saltosion.gladiator.gui.properties.TextProperty; import com.saltosion.gladiator.gui.properties.TextProperty;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
import com.saltosion.gladiator.util.Log;
import com.saltosion.gladiator.util.SpriteLoader; import com.saltosion.gladiator.util.SpriteLoader;
import com.saltosion.gladiator.util.SpriteSequence; import com.saltosion.gladiator.util.SpriteSequence;
import java.util.ArrayList; import java.util.ArrayList;
@ -87,8 +86,8 @@ public class RenderingSystem extends EntitySystem {
public void update(float deltaTime) { public void update(float deltaTime) {
if (AppUtil.player != null) { if (AppUtil.player != null) {
CPhysics phys = pm.get(AppUtil.player); CPhysics phys = pm.get(AppUtil.player);
camera.position.set(phys.getPosition().x, phys.getPosition().y, 0); //camera.position.set(phys.getPosition().x, phys.getPosition().y, 0);
fontCamera.position.set(camera.position.x * Global.FONT_SCALE, camera.position.y * Global.FONT_SCALE, 0); //fontCamera.position.set(camera.position.x * Global.FONT_SCALE, camera.position.y * Global.FONT_SCALE, 0);
} }
camera.update(); camera.update();
fontCamera.update(); fontCamera.update();
@ -194,6 +193,10 @@ public class RenderingSystem extends EntitySystem {
} }
private void renderEntities(float deltaTime) { private void renderEntities(float deltaTime) {
if (AppUtil.player == null) {
return;
}
CPhysics playerPhys = pm.get(AppUtil.player);
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
batch.begin(); batch.begin();
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
@ -208,8 +211,8 @@ public class RenderingSystem extends EntitySystem {
int spriteHeight = currSprite.getRegionHeight(); int spriteHeight = currSprite.getRegionHeight();
int spriteWidth = currSprite.getRegionWidth(); int spriteWidth = currSprite.getRegionWidth();
currSprite.setPosition(physics.getPosition().x - spriteWidth / 2, currSprite.setPosition(((physics.getPosition().x - spriteWidth / 2) - playerPhys.getPosition().x / physics.getZParallax() + camera.viewportWidth / 2),
physics.getPosition().y - spriteHeight / 2); (physics.getPosition().y - spriteHeight / 2) - playerPhys.getPosition().y / physics.getZParallax() + camera.viewportHeight / 3);
currSprite.draw(batch); currSprite.draw(batch);
float nextFrame = renderedObject.getCurrentFrame(channel) + deltaTime * currSequence.getPlayspeed(); float nextFrame = renderedObject.getCurrentFrame(channel) + deltaTime * currSequence.getPlayspeed();
@ -245,14 +248,18 @@ public class RenderingSystem extends EntitySystem {
private void renderDebug(Camera camera) { private void renderDebug(Camera camera) {
if (debug) { if (debug) {
if (AppUtil.player == null) {
return;
}
CPhysics playerPhys = pm.get(AppUtil.player);
debugRenderer.setProjectionMatrix(camera.combined); debugRenderer.setProjectionMatrix(camera.combined);
debugRenderer.begin(ShapeType.Line); debugRenderer.begin(ShapeType.Line);
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
CPhysics physics = pm.get(entities.get(i)); CPhysics physics = pm.get(entities.get(i));
float x0 = physics.getPosition().x - physics.getSize().x / 2; 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; 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; 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; float y1 = physics.getPosition().y + physics.getSize().y / 2 - playerPhys.getPosition().y / physics.getZParallax() + camera.viewportHeight / 3;
debugRenderer.setColor(debugColor); debugRenderer.setColor(debugColor);
debugRenderer.line(x0, y0, x1, y0); debugRenderer.line(x0, y0, x1, y0);

View File

@ -10,6 +10,7 @@ public class Name {
public static final String GROUNDIMG = "GROUNDIMG"; public static final String GROUNDIMG = "GROUNDIMG";
public static final String WALLIMG = "WALLIMG"; public static final String WALLIMG = "WALLIMG";
public static final String SWINGHITBOXIMG = "SWINGHITBOXIMG"; public static final String SWINGHITBOXIMG = "SWINGHITBOXIMG";
public static final String AUDIENCEIMG = "AUDIENCEIMG";
public static final String BUTTON_HUGE = "BUTTON_HUGE"; public static final String BUTTON_HUGE = "BUTTON_HUGE";
public static final String BUTTON_HUGE_HOVER = "BUTTON_HUGE_HOVER"; public static final String BUTTON_HUGE_HOVER = "BUTTON_HUGE_HOVER";

View File

@ -17,6 +17,8 @@ public class SpriteLoader {
loadTexture(Name.GROUNDIMG, "sprites/ground.png"); loadTexture(Name.GROUNDIMG, "sprites/ground.png");
loadTexture(Name.WALLIMG, "sprites/wall.png"); loadTexture(Name.WALLIMG, "sprites/wall.png");
loadTexture(Name.SWINGHITBOXIMG, "sprites/swinghitbox.png"); loadTexture(Name.SWINGHITBOXIMG, "sprites/swinghitbox.png");
loadTexture(Name.AUDIENCEIMG, "sprites/Audience.png");
loadTexture(Name.BUTTON_HUGE, "sprites/buttons/Button_Huge.png"); loadTexture(Name.BUTTON_HUGE, "sprites/buttons/Button_Huge.png");
loadTexture(Name.BUTTON_HUGE_HOVER, "sprites/buttons/Button_Huge_Hover.png"); loadTexture(Name.BUTTON_HUGE_HOVER, "sprites/buttons/Button_Huge_Hover.png");
loadTexture(Name.BUTTON_BIG, "sprites/buttons/Button_Big.png"); loadTexture(Name.BUTTON_BIG, "sprites/buttons/Button_Big.png");