Moved a bunch of files around

Set scope on unscoped variables
master
Edward Peterson 9 years ago
parent 24e619452d
commit 9e6b58ec19

@ -17,6 +17,10 @@ import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.toasted.chuck.entities.Entity;
import com.toasted.chuck.entities.EntityBox;
import com.toasted.chuck.entities.EntityPlayer;
import com.toasted.chuck.entities.EntityTorch;
public class ChuckGame extends ApplicationAdapter implements InputProcessor{
Graphics graphics;
@ -27,7 +31,6 @@ public class ChuckGame extends ApplicationAdapter implements InputProcessor{
OrthogonalTiledMapRenderer tmRenderer;
ArrayList<Rectangle> collisions = new ArrayList<Rectangle>();
ArrayList<Light> lights = new ArrayList<Light>();
boolean testLightFade = false;
@Override
@ -41,7 +44,7 @@ public class ChuckGame extends ApplicationAdapter implements InputProcessor{
zSorter = new Comparator<Entity>(){
public int compare(Entity arg0, Entity arg1) {
return (int) Math.signum(arg1.position.y - arg0.position.y);
return (int) Math.signum(arg1.getY() - arg0.getY());
}
@ -88,8 +91,8 @@ public class ChuckGame extends ApplicationAdapter implements InputProcessor{
}
Collections.sort(entities, zSorter);
graphics.cam.position.x = player.position.x + 8;
graphics.cam.position.y = player.position.y + 8;
graphics.cam.position.x = player.getCenterX();
graphics.cam.position.y = player.getCenterY();
graphics.cam.update();
@ -109,7 +112,6 @@ public class ChuckGame extends ApplicationAdapter implements InputProcessor{
graphics.startSprite();
for(Entity e: entities){
if(e.shouldDrawSelf)
e.draw(graphics);
}
graphics.endSprite();
@ -128,13 +130,13 @@ public class ChuckGame extends ApplicationAdapter implements InputProcessor{
@Override
public boolean keyDown(int keycode) {
player.controller.acceptEvent(keycode, true, player, entities, collisions);
player.getController().acceptEvent(keycode, true, player, entities, collisions);
return false;
}
@Override
public boolean keyUp(int keycode) {
player.controller.acceptEvent(keycode, false, player, entities, collisions);
player.getController().acceptEvent(keycode, false, player, entities, collisions);
switch(keycode){
case Keys.F:
testLightFade = true;

@ -3,6 +3,7 @@ package com.toasted.chuck;
import java.util.ArrayList;
import com.badlogic.gdx.math.Rectangle;
import com.toasted.chuck.entities.Entity;
public interface EntityController {
public void acceptEvent(int keycode, boolean newState, Entity owner, ArrayList<Entity> entities, ArrayList<Rectangle> collisions);

@ -23,6 +23,7 @@ public class Graphics {
final int orthoY = 9 * 28;
final float orthoScale = orthoX / (float)getWidth();
public float lightValueMultiplier = 1f; // for testing fade out
private static int MAX_LIGHTS = 50;
ShaderProgram shader = new ShaderProgram(VERTEX, FRAGMENT);
public Graphics(){
@ -73,19 +74,19 @@ public class Graphics {
}
public void passLightsToShader(ArrayList<Light> lights){
if(lights.size() > 50){ // if there are too many to do
if(lights.size() > MAX_LIGHTS){ // if there are too many to do
} else {
shader.setUniformi("u_actualLights", lights.size());
shader.setUniformf("u_ambientLight", 0f);
int loc = shader.getUniformLocation("u_lightCoord[" + 0 + "]");
shader.setUniformf("u_ambientLight", Light.VAL_AMBIENT);
int loc = shader.getUniformLocation("u_lightCoord[0]");
int locIn = shader.getUniformLocation("u_lightIntensity[0]");
for(int i = 0;i < lights.size();i++){
Vector3 v3 = cam.project(new Vector3(lights.get(i).position.x, lights.get(i).position.y, 0));
Vector3 v3 = cam.project(new Vector3(lights.get(i).getX(), lights.get(i).getY(), 0));
Vector2 v = new Vector2(v3.x, v3.y);
shader.setUniformf(loc + i, v);
shader.setUniformf(locIn + i, lights.get(i).intensity * lightValueMultiplier);
shader.setUniformf(locIn + i, lights.get(i).getIntensity() * lightValueMultiplier);
}
}
}

@ -5,9 +5,10 @@ import com.badlogic.gdx.math.Vector2;
public class Light {
public final static float VAL_TORCH = .4f;
public final static float VAL_PLAYER = .9f;
public final static float VAL_AMBIENT = 0f;
private static Vector2 tmp = new Vector2();
Vector2 position;
float intensity = 1;
private Vector2 position;
private float intensity = 1;
public Light(float x, float y, float intensity){
position = new Vector2(x, y);
this.intensity = intensity;
@ -15,5 +16,17 @@ public class Light {
public Vector2 getScreenPos(float cx, float cy){
return tmp.set(position).sub(cx, cy);
}
public float getX(){
return position.x;
}
public float getY(){
return position.y;
}
public Vector2 getPosition(){
return position;
}
public float getIntensity(){
return intensity;
}
}

@ -1,18 +1,20 @@
package com.toasted.chuck;
package com.toasted.chuck.entities;
import java.util.ArrayList;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.toasted.chuck.EntityController;
import com.toasted.chuck.Graphics;
public abstract class Entity {
public Vector2 position = new Vector2();
public Vector2 velocity = new Vector2();
public EntityController controller;
public Rectangle collision;
float flyLength;
public boolean isChuckable = true;
boolean shouldDrawSelf = true;
protected Vector2 position = new Vector2();
protected Vector2 velocity = new Vector2();
protected EntityController controller;
protected Rectangle collision;
protected float flyLength;
protected boolean isChuckable = true;
protected boolean shouldDrawSelf = true;
public Entity(){
}
@ -58,7 +60,25 @@ public abstract class Entity {
collision.y = position.y;
}
public abstract void draw(Graphics g);
public Vector2 getCenterPoint(){
return new Vector2(getCenterX(), getCenterY());
}
public float getCenterX(){
return position.x + collision.width / 2;
}
public float getCenterY(){
return position.y + collision.height / 2;
}
public void draw(Graphics g, float dx, float dy){
draw(g);
}
public float getX(){
return position.x;
}
public float getY(){
return position.y;
}
public EntityController getController(){
return controller;
}
}

@ -1,10 +1,11 @@
package com.toasted.chuck;
package com.toasted.chuck.entities;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import com.toasted.chuck.Graphics;
public class EntityBox extends Entity{
float decel = 25;
@ -27,10 +28,12 @@ public class EntityBox extends Entity{
public void draw(Graphics g) {
// g.getShapes().setColor(Color.BLUE);
// g.getShapes().rect(position.x, position.y + (float)Math.sin((1 - Math.max(flyLength, 0) / .5f) * Math.PI) * 8, 16, 16);
if(shouldDrawSelf)
draw(g, 0, 0);
}
public void draw(Graphics g, float dx, float dy){
if(flyLength >= 0){
g.getBatch().draw(shadow, position.x, position.y-1);
}

@ -1,4 +1,4 @@
package com.toasted.chuck;
package com.toasted.chuck.entities;
import java.util.ArrayList;
@ -8,17 +8,20 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.toasted.chuck.EntityController;
import com.toasted.chuck.Graphics;
import com.toasted.chuck.Light;
import com.toasted.chuck.LightEmitter;
public class EntityPlayer extends Entity implements LightEmitter{
Light illuminator;
Texture playerArt = new Texture("player.png");
TextureRegion[] sprites = new TextureRegion[8];
float moveSpeed = 100;
float throwSpeed = 100;
Entity holding;
Vector2 lastVelocity;
int lastDirectionalUsed;
int lastXDirectional, lastYDirectional;
protected Light illuminator;
protected Texture playerArt = new Texture("player.png");
protected TextureRegion[] sprites = new TextureRegion[8];
private float moveSpeed = 100;
private float throwSpeed = 100;
private Entity holding;
private Vector2 lastVelocity;
private int lastDirectionalUsed;
private ArrayList<Integer> directionals = new ArrayList<Integer>();//Don't think I'll use this
private boolean[] arrowKeys = new boolean[4]; //UDLR
public EntityPlayer(){
@ -175,8 +178,8 @@ public class EntityPlayer extends Entity implements LightEmitter{
holding.position.y = position.y;
}
illuminator.position.x = position.x + collision.width / 2;
illuminator.position.y = position.y + collision.height / 2;
illuminator.getPosition().x = position.x + collision.width / 2;
illuminator.getPosition().y = position.y + collision.height / 2;
}

@ -1,10 +1,13 @@
package com.toasted.chuck;
package com.toasted.chuck.entities;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.toasted.chuck.Graphics;
import com.toasted.chuck.Light;
import com.toasted.chuck.LightEmitter;
public class EntityTorch extends EntityBox implements LightEmitter{
private Light emitter;
@ -22,7 +25,7 @@ public class EntityTorch extends EntityBox implements LightEmitter{
@Override
public void update(float delta, ArrayList<Entity> entities, ArrayList<Rectangle> collisions) {
super.update(delta, entities, collisions);
emitter.position.set(position).add(collision.width / 2, 3 * collision.height / 4);
emitter.getPosition().set(position).add(collision.width / 2, 3 * collision.height / 4);
}
Loading…
Cancel
Save