Added basic sounds
master
Edward Peterson 9 years ago
parent 4bb305e046
commit 96c774767f

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,15 @@
package com.toasted.chuck;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
public class Audio {
public static Sound getSound(String filename){
return Gdx.audio.newSound(Gdx.files.internal(filename));
}
public static Music getMusic(String filename){
return Gdx.audio.newMusic(Gdx.files.internal(filename));
}
}

@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.maps.MapLayer;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapProperties;
@ -32,6 +33,8 @@ public class Level {
private HashMap<Rectangle, MapObject> collisionLookupTable = new HashMap<Rectangle, MapObject>();
private ArrayList<SecretRoom> secretRooms = new ArrayList<SecretRoom>();
private Sound doorOpening = Audio.getSound("doorOpen.wav");
public Level(String filename, Graphics graphics){
tiledMap = new TmxMapLoader().load("testmap.tmx");
tmRenderer = new OrthogonalTiledMapRenderer(tiledMap, graphics.getBatch());
@ -109,9 +112,13 @@ public class Level {
public void revealSecretRoom(String name){
MapLayer layer = tiledMap.getLayers().get(name);
if(layer != null){
layer.setVisible(true);
doorOpening.play();
} else {
System.err.println("Failed to reveal room: " + name);
}
@ -140,7 +147,7 @@ public class Level {
if(o.getProperties().containsKey("customColor")){
LightEmitter le = (LightEmitter)newEntity;
String[] rgbValues = ((String)o.getProperties().get("customColor")).split(",");
System.out.println("Setting CUSTOM RGB");
// System.out.println("Setting CUSTOM RGB");
le.getLight().setLightColor(Float.parseFloat(rgbValues[0]), Float.parseFloat(rgbValues[1]), Float.parseFloat(rgbValues[2]));
}
}

@ -2,8 +2,11 @@ package com.toasted.chuck.entities;
import java.util.ArrayList;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.toasted.chuck.Audio;
import com.toasted.chuck.EntityController;
import com.toasted.chuck.Graphics;
import com.toasted.chuck.Level;
@ -20,6 +23,10 @@ public abstract class Entity {
protected float stunTimer = 0;
protected float weight = 0; //used for destruction capabilities and pressure plate triggering
protected int health = 3;
protected static Sound hurt = Audio.getSound("hurt.wav");
protected static Sound drop = Audio.getSound("drop.wav");
protected static Sound step = Audio.getSound("step.wav");
public Entity(){
}
@ -102,6 +109,8 @@ public abstract class Entity {
return getY();
}
public void stun(float duration){
if(stunTimer > 0) return;
hurt.play();
this.stunTimer = duration;
}
}

@ -16,9 +16,15 @@ public class EntityBox extends Entity{
weight = 1;
}
public void update(float delta, Level lvl) {
float preFly = flyLength;
flyLength -= delta;
if(flyLength <= 0)
if(preFly > 0 && flyLength <= 0){
drop.play(1f, (1- weight) + .5f, 0);
}
if(flyLength <= 0){
velocity.mulAdd(velocity, -delta * decel);
}
Rectangle r = doCollisions(delta, lvl.getCollisions());
if(r != null){
if(lvl.isCollisionBoxDestructable(r) && weight > .75f){

@ -3,10 +3,12 @@ package com.toasted.chuck.entities;
import java.util.ArrayList;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.audio.Sound;
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.Audio;
import com.toasted.chuck.EntityController;
import com.toasted.chuck.Graphics;
import com.toasted.chuck.Level;
@ -24,6 +26,12 @@ public class EntityPlayer extends Entity implements LightEmitter{
private int lastDirectionalUsed;
private ArrayList<Integer> directionals = new ArrayList<Integer>();//Don't think I'll use this
private boolean[] arrowKeys = new boolean[4]; //UDLR
private float stepTimerFull = .25f;
private float stepTimer = stepTimerFull;
private static Sound pickup = Audio.getSound("pickup.wav");
private static Sound throwing = Audio.getSound("throw.wav");
public EntityPlayer(){
weight = 1;
isChuckable = false;
@ -47,10 +55,9 @@ public class EntityPlayer extends Entity implements LightEmitter{
if(e.collision.overlaps(collision) && e.isChuckable){
holding = e;
holding.shouldDrawSelf = false;
pickup.play();
if(holding instanceof LightEmitter){
LightEmitter le = (LightEmitter)holding;
System.err.println(le.getLight());
}
@ -62,7 +69,7 @@ public class EntityPlayer extends Entity implements LightEmitter{
holding.velocity.add(velocity).mulAdd(getDirectionalVector(), throwSpeed);
holding.flyLength = .5f;
holding.shouldDrawSelf = true;
throwing.play();
holding = null;
}
break;
@ -176,8 +183,14 @@ public class EntityPlayer extends Entity implements LightEmitter{
doControls();
float vectorMag = (float)Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(velocity.y, 2));
if(vectorMag != 0){
stepTimer -= delta;
if(stepTimer <= 0){
stepTimer = stepTimerFull;
step.play(.5f, 1, 0);
}
}
doCollisions(delta, lvl.getCollisions());

@ -1,9 +1,6 @@
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;

Loading…
Cancel
Save