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 torchesmaster
parent
bbd4c068ca
commit
67c2bf37f0
Binary file not shown.
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 6.7 KiB |
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue