Added a bunch of stuff

added bats
added Pressure pads
Fragment shader now gives a slight yellowish tint to simulate torchlight
added flicker to light values
added flicker animation to torches
master
Edward Peterson 9 years ago
parent bbd4c068ca
commit 67c2bf37f0

@ -40,6 +40,10 @@ void main() {
brightest = brightest + dis2Light2 - brightest * dis2Light2;
}
texColor.rgb = texColor.rgb * (sin(pow(brightest, 10) * M_PI / 2));
//apply torchlight tint
texColor.b = texColor.b * 0.7;
texColor.g = texColor.g * 0.9;
//final color
gl_FragColor = texColor * vColor;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-up" width="50" height="50" tilewidth="16" tileheight="16" nextobjectid="232">
<map version="1.0" orientation="orthogonal" renderorder="right-up" width="50" height="50" tilewidth="16" tileheight="16" nextobjectid="268">
<tileset firstgid="1" name="env" tilewidth="16" tileheight="16" tilecount="64" columns="8">
<image source="env.png" width="128" height="128"/>
</tileset>
@ -167,7 +167,6 @@
<object id="60" x="624" y="784" width="176" height="16"/>
<object id="61" x="800" y="352" width="32" height="448"/>
<object id="63" x="608" y="240" width="128" height="152"/>
<object id="65" x="608" y="240" width="48" height="112"/>
<object id="150" x="768" y="240" width="32" height="152"/>
<object id="151" x="736" y="352" width="32" height="40">
<properties>
@ -183,6 +182,48 @@
<object id="160" x="800" y="80" width="16" height="160"/>
</objectgroup>
<objectgroup name="staticLights"/>
<objectgroup name="pathfinding">
<object id="187" x="496" y="400" width="304" height="160"/>
<object id="188" x="624" y="560" width="176" height="224"/>
<object id="190" x="32" y="32" width="240" height="112"/>
<object id="191" x="16" y="48" width="16" height="80"/>
<object id="192" x="272" y="48" width="16" height="80"/>
<object id="193" x="288" y="80" width="16" height="32"/>
<object id="194" x="304" y="32" width="112" height="80"/>
<object id="195" x="352" y="112" width="32" height="48"/>
<object id="196" x="304" y="160" width="112" height="96"/>
<object id="197" x="416" y="192" width="16" height="32"/>
<object id="198" x="432" y="80" width="128" height="160"/>
<object id="199" x="480" y="240" width="32" height="80"/>
<object id="200" x="352" y="304" width="64" height="64"/>
<object id="202" x="576" y="352" width="32" height="48"/>
<object id="203" x="368" y="368" width="32" height="64"/>
<object id="204" x="304" y="432" width="160" height="128"/>
<object id="205" x="432" y="560" width="32" height="48"/>
<object id="206" x="368" y="608" width="224" height="160"/>
<object id="207" x="592" y="688" width="32" height="32"/>
<object id="208" x="336" y="704" width="32" height="32"/>
<object id="209" x="304" y="560" width="32" height="240"/>
<object id="210" x="0" y="768" width="304" height="32"/>
<object id="212" x="0" y="592" width="144" height="96"/>
<object id="213" x="144" y="640" width="16" height="32"/>
<object id="214" x="160" y="592" width="128" height="96"/>
<object id="215" x="288" y="640" width="16" height="32"/>
<object id="216" x="16" y="400" width="240" height="144"/>
<object id="217" x="208" y="544" width="32" height="48"/>
<object id="218" x="64" y="544" width="32" height="48"/>
<object id="219" x="128" y="352" width="32" height="48"/>
<object id="221" x="16" y="192" width="96" height="128"/>
<object id="222" x="112" y="192" width="176" height="80"/>
<object id="223" x="288" y="208" width="16" height="32"/>
<object id="224" x="128" y="144" width="32" height="48"/>
<object id="225" x="720" y="80" width="64" height="16"/>
<object id="226" x="704" y="96" width="96" height="128"/>
<object id="227" x="720" y="224" width="64" height="16"/>
<object id="228" x="736" y="240" width="32" height="160"/>
<object id="229" x="16" y="320" width="336" height="32"/>
<object id="230" x="416" y="320" width="192" height="32"/>
</objectgroup>
<objectgroup name="objectSpawn">
<object id="112" x="272" y="745" width="16" height="16">
<properties>
@ -369,47 +410,160 @@
<property name="type" value="box"/>
</properties>
</object>
</objectgroup>
<objectgroup name="pathfinding">
<object id="187" x="496" y="400" width="304" height="160"/>
<object id="188" x="624" y="560" width="176" height="224"/>
<object id="190" x="32" y="32" width="240" height="112"/>
<object id="191" x="16" y="48" width="16" height="80"/>
<object id="192" x="272" y="48" width="16" height="80"/>
<object id="193" x="288" y="80" width="16" height="32"/>
<object id="194" x="304" y="32" width="112" height="80"/>
<object id="195" x="352" y="112" width="32" height="48"/>
<object id="196" x="304" y="160" width="112" height="96"/>
<object id="197" x="416" y="192" width="16" height="32"/>
<object id="198" x="432" y="80" width="128" height="160"/>
<object id="199" x="480" y="240" width="32" height="80"/>
<object id="200" x="352" y="304" width="64" height="64"/>
<object id="202" x="576" y="352" width="32" height="48"/>
<object id="203" x="368" y="368" width="32" height="64"/>
<object id="204" x="304" y="432" width="160" height="128"/>
<object id="205" x="432" y="560" width="32" height="48"/>
<object id="206" x="368" y="608" width="224" height="160"/>
<object id="207" x="592" y="688" width="32" height="32"/>
<object id="208" x="336" y="704" width="32" height="32"/>
<object id="209" x="304" y="560" width="32" height="240"/>
<object id="210" x="0" y="768" width="304" height="32"/>
<object id="212" x="0" y="592" width="144" height="96"/>
<object id="213" x="144" y="640" width="16" height="32"/>
<object id="214" x="160" y="592" width="128" height="96"/>
<object id="215" x="288" y="640" width="16" height="32"/>
<object id="216" x="16" y="400" width="240" height="144"/>
<object id="217" x="208" y="544" width="32" height="48"/>
<object id="218" x="64" y="544" width="32" height="48"/>
<object id="219" x="128" y="352" width="32" height="48"/>
<object id="221" x="16" y="192" width="96" height="128"/>
<object id="222" x="112" y="192" width="176" height="80"/>
<object id="223" x="288" y="208" width="16" height="32"/>
<object id="224" x="128" y="144" width="32" height="48"/>
<object id="225" x="720" y="80" width="64" height="16"/>
<object id="226" x="704" y="96" width="96" height="128"/>
<object id="227" x="720" y="224" width="64" height="16"/>
<object id="228" x="736" y="240" width="32" height="160"/>
<object id="229" x="16" y="320" width="336" height="32"/>
<object id="230" x="416" y="320" width="192" height="32"/>
<object id="234" x="464" y="672" width="16" height="16">
<properties>
<property name="type" value="pressurePad"/>
</properties>
</object>
<object id="236" x="528" y="704" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="239" x="704" y="640" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="240" x="624" y="480" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="241" x="496" y="464" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="242" x="720" y="448" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="243" x="384" y="480" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="244" x="240" y="640" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="245" x="32" y="640" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="246" x="96" y="608" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="247" x="64" y="464" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="248" x="208" y="416" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="249" x="160" y="496" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="250" x="48" y="224" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="251" x="176" y="224" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="252" x="32" y="304" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="253" x="336" y="192" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="254" x="384" y="224" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="255" x="320" y="48" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="256" x="368" y="80" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="257" x="96" y="80" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="258" x="176" y="112" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="259" x="208" y="64" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="260" x="48" y="80" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="261" x="464" y="96" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="262" x="528" y="112" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="263" x="512" y="144" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="264" x="464" y="176" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="265" x="512" y="208" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="266" x="672" y="704" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
<object id="267" x="736" y="544" width="16" height="16">
<properties>
<property name="type" value="bat"/>
</properties>
</object>
</objectgroup>
</map>

@ -29,7 +29,7 @@ public class ChuckGame extends ApplicationAdapter implements InputProcessor{
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
level.draw(graphics);
// System.out.println("FPS:" + Gdx.graphics.getFramesPerSecond());
System.out.println("FPS:" + Gdx.graphics.getFramesPerSecond());
}

@ -5,7 +5,9 @@ import java.util.ArrayList;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
@ -24,7 +26,7 @@ public class Graphics {
final float orthoScale = orthoX / (float)getWidth();
public float lightValueMultiplier = 1f; // for testing fade out
private static int MAX_LIGHTS = 50;
private static Texture textureMap;
ShaderProgram shader = new ShaderProgram(VERTEX, FRAGMENT);
public Graphics(){
cam = new OrthographicCamera();
@ -77,17 +79,26 @@ public class Graphics {
if(lights.size() > MAX_LIGHTS){ // if there are too many to do
} else {
shader.setUniformi("u_actualLights", lights.size());
shader.setUniformf("u_ambientLight", Light.VAL_AMBIENT);
int loc = shader.getUniformLocation("u_lightCoord[0]");
int locIn = shader.getUniformLocation("u_lightIntensity[0]");
int nullLights = 0;
for(int i = 0;i < lights.size();i++){
if(lights.get(i) == null || !lights.get(i).isEmitting()){
nullLights++;
continue;
}
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).getIntensity() * lightValueMultiplier);
}
shader.setUniformi("u_actualLights", lights.size() - nullLights);
shader.setUniformf("u_ambientLight", Light.VAL_AMBIENT);
}
}
public static TextureRegion getSubTexture(int i){
if(textureMap == null) textureMap = new Texture("env.png");
return new TextureRegion(textureMap, (i % 8) * 16, (i / 8) * 16, 16, 16);
}
}

@ -15,8 +15,10 @@ 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.EntityBat;
import com.toasted.chuck.entities.EntityBox;
import com.toasted.chuck.entities.EntityPlayer;
import com.toasted.chuck.entities.EntityPressurePad;
import com.toasted.chuck.entities.EntityTorch;
public class Level {
@ -36,7 +38,7 @@ public class Level {
zSorter = new Comparator<Entity>(){
public int compare(Entity arg0, Entity arg1) {
return (int) Math.signum(arg1.getY() - arg0.getY());
return (int) Math.signum(arg1.getZSortValue() - arg0.getZSortValue());
}
@ -132,12 +134,19 @@ public class Level {
Vector2 t = new Vector2();
t = r.getCenter(t);
Entity newEntity = null;
if(o.getProperties().get("type").equals("torch")){
String type = (String) o.getProperties().get("type");
if(type.equals("torch")){
newEntity = new EntityTorch(t.x - r.getWidth() / 2, t.y - r.getHeight() / 2);
}
if(o.getProperties().get("type").equals("box")){
if(type.equals("box")){
newEntity = new EntityBox(t.x - r.getWidth() / 2, t.y - r.getHeight() / 2);
}
if(type.equals("pressurePad")){
newEntity = new EntityPressurePad(t.x - r.getWidth() / 2, t.y - r.getHeight() / 2);
}
if(type.equals("bat")){
newEntity = new EntityBat(r.x, r.y);
}
if(listToAdd == null){
spawnEntity(newEntity);
} else {

@ -9,6 +9,7 @@ public class Light {
private static Vector2 tmp = new Vector2();
private Vector2 position;
private float intensity = 1;
private boolean isEmitting = true;
public Light(float x, float y, float intensity){
position = new Vector2(x, y);
this.intensity = intensity;
@ -28,5 +29,13 @@ public class Light {
public float getIntensity(){
return intensity;
}
public void setIntensity(float value){
intensity = value;
}
public boolean isEmitting(){
return isEmitting;
}
public void setEmitting(boolean state){
isEmitting = state;
}
}

@ -16,12 +16,22 @@ public abstract class Entity {
protected float flyLength;
protected boolean isChuckable = true;
protected boolean shouldDrawSelf = true;
protected boolean isHostile = false;
protected float stunTimer = 0;
protected float weight = 0; //used for destruction capabilities and pressure plate triggering
public Entity(){
}
public Entity(float x, float y){
position = new Vector2(x, y);
collision = new Rectangle(x, y, 16, 16);
}
public abstract void update(float delta, Level lvl);
protected Rectangle doCollisions(float delta, ArrayList<Rectangle> collisions){
if(stunTimer > 0) {
stunTimer -= delta;
return null;
}
Rectangle collidedWith = null;
position.x += velocity.x * delta;
@ -87,4 +97,10 @@ public abstract class Entity {
public EntityController getController(){
return controller;
}
public float getZSortValue(){
return getY();
}
public void stun(float duration){
this.stunTimer = duration;
}
}

@ -0,0 +1,48 @@
package com.toasted.chuck.entities;
import java.util.Random;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.toasted.chuck.Graphics;
import com.toasted.chuck.Level;
public class EntityBat extends Entity{
private static final float MOVE_SPEED = 40f;
private TextureRegion[] animation = new TextureRegion[]{Graphics.getSubTexture(20), Graphics.getSubTexture(21)};
private float timeToPickNextDirection = 0f;
private float animationSpeed = .05f;
private float animationTimer = animationSpeed;
private int animationFrame = 0;
private Random rand = new Random();
public EntityBat(float x, float y){
super(x, y);
isChuckable = false;
isHostile = true;
}
public void update(float delta, Level lvl) {
Rectangle collide = doCollisions(delta, lvl.getCollisions());
//wandering ai
timeToPickNextDirection -= delta;
if(timeToPickNextDirection <= 0 || collide != null){
float nextDirection = rand.nextFloat();
timeToPickNextDirection = rand.nextFloat() * 1.5f;
velocity.x = (float)Math.cos(nextDirection * Math.PI * 2f) * MOVE_SPEED;
velocity.y = (float)Math.sin(nextDirection * Math.PI * 2f) * MOVE_SPEED;
}
animationTimer -= delta;
if(animationTimer <= 0){
animationTimer = animationSpeed;
animationFrame++;
}
}
public void draw(Graphics g) {
g.getBatch().draw(animation[animationFrame % 2], getX(), getY());
}
}

@ -12,10 +12,7 @@ public class EntityBox extends Entity{
Texture shadow = new Texture("shadow.png");
public EntityBox(float x, float y){
super();
position.x = x;
position.y = y;
collision = new Rectangle(x, y, 16, 16);
super(x, y);
weight = 1;
}
public void update(float delta, Level lvl) {
@ -31,6 +28,16 @@ public class EntityBox extends Entity{
lvl.revealSecretRoom(layerOpened);
}
}
if(flyLength > 0){
//can hit enemies while in air
for(Entity e: lvl.getEntities()){
if(e.isHostile && e.collision.overlaps(collision)){
velocity.x = 0;
velocity.y = 0;
e.stun(4f);
}
}
}
}
public void draw(Graphics g) {

@ -0,0 +1,62 @@
package com.toasted.chuck.entities;
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.Graphics;
import com.toasted.chuck.Level;
import com.toasted.chuck.Light;
import com.toasted.chuck.LightEmitter;
public class EntityPressurePad extends Entity implements LightEmitter{
private final float TRIGGER_WEIGHT = .75f;
private TextureRegion art = Graphics.getSubTexture(16);
private TextureRegion pressed = Graphics.getSubTexture(24);
private Light indicator;
private boolean depressed = false;
public EntityPressurePad(float x, float y){
super(x, y);
indicator = new Light(x + collision.width / 2, y + collision.height / 2, 2f);
indicator.setEmitting(false);
isChuckable = false;
}
@Override
public void update(float delta, Level lvl) {
boolean foundTrigger = false;
for(Entity e: lvl.getEntities()){
if(e.weight > TRIGGER_WEIGHT && e.flyLength <= 0){
if(e.collision.overlaps(collision)){
foundTrigger = true;
break;
}
}
}
if(foundTrigger) {
// indicator.setEmitting(true);
depressed = true;
} else {
depressed = false;
// indicator.setEmitting(false);
}
}
@Override
public void draw(Graphics g) {
g.getBatch().draw(depressed ? pressed : art, position.x, position.y);
}
public float getZSortValue(){
return super.getZSortValue() + 1000000;
}
@Override
public Light getLight() {
return indicator;
}
}

@ -1,5 +1,7 @@
package com.toasted.chuck.entities;
import java.util.Random;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.toasted.chuck.Graphics;
@ -9,7 +11,20 @@ import com.toasted.chuck.LightEmitter;
public class EntityTorch extends EntityBox implements LightEmitter{
private Light emitter;
private TextureRegion torch = new TextureRegion(new Texture("env.png"),0, 23, 16, 16);
private TextureRegion torch = new TextureRegion(new Texture("env.png"),0, 16, 16, 16);
private Random rand = new Random();
private static TextureRegion[] torchFrames = new TextureRegion[]{
Graphics.getSubTexture(8),
Graphics.getSubTexture(25),
Graphics.getSubTexture(26),
Graphics.getSubTexture(27),
Graphics.getSubTexture(28),
};
private int currentFrame = 0;
private float flickerSpeed = .1f;
private float frameTimer = flickerSpeed;
private static final float FLICKER = .07f;
public EntityTorch(float x, float y) {
super(x, y);
emitter = new Light(x + collision.width / 2, y + collision.height / 2, .3f);
@ -24,6 +39,20 @@ public class EntityTorch extends EntityBox implements LightEmitter{
@Override
public void update(float delta, Level lvl) {
super.update(delta, lvl);
//try flickering light
emitter.setIntensity((rand.nextFloat() * FLICKER + (1f-FLICKER)) * .3f);
frameTimer -= delta;
if(frameTimer <= 0){
frameTimer = flickerSpeed;
int newFrame;
do {
newFrame = rand.nextInt(5);
} while(newFrame == currentFrame);
currentFrame = newFrame;
}
//follow the torch
emitter.getPosition().set(position).add(collision.width / 2, 3 * collision.height / 4);
}
@ -34,8 +63,11 @@ public class EntityTorch extends EntityBox implements LightEmitter{
}
float flyPerc = (Math.max(flyLength, 0) / .5f);
if(flyPerc > 0)
g.getBatch().draw(torch, position.x +dx, position.y + (float)Math.abs(Math.cos((1 - flyPerc) * (Math.PI * 3f / 4f) - (Math.PI / 4f))) * 15 + dy);
else g.getBatch().draw(torch, position.x + dx, position.y + dy);
g.getBatch().draw(getFrame(), position.x +dx, position.y + (float)Math.abs(Math.cos((1 - flyPerc) * (Math.PI * 3f / 4f) - (Math.PI / 4f))) * 15 + dy);
else g.getBatch().draw(getFrame(), position.x + dx, position.y + dy);
}
private TextureRegion getFrame(){
return torchFrames[currentFrame];
}
}

Loading…
Cancel
Save