evil-inside/src/ei/engine/sound/Sound.java

113 lines
2 KiB
Java
Raw Normal View History

package ei.engine.sound;
import java.awt.Rectangle;
import ei.engine.math.Vector3f;
import ei.engine.scene.Entity;
2007-04-08 15:57:10 +00:00
import ei.engine.texture.Texture;
/**
* A sound that can be played through OpenAL
*
* @author Ziver Koc
*/
public class Sound extends Entity{
private static int soundId = 1;
/** The buffer containing the sound */
private int buffer;
private int sourceId;
private int id;
private Vector3f velocity;
2007-03-16 19:16:00 +00:00
/**
* Create a new sound
*
* @param name The name of the sound
* @param ref the path to the sound file
*/
public Sound(String name, String ref) {
super(name);
id = soundId;
soundId++;
velocity = new Vector3f();
this.buffer = SoundLoader.getInstnace().loadSound(ref);
}
/**
* Returns the unique id of the object
*
* @return The id of the object
*/
public int getSoundId(){
return id;
}
/**
* Returns the source this object uses
*
* @return The id of the source
*/
public int getSourceId(){
return sourceId;
}
/**
* Returns the buffer of this object
*
* @return The buffer
*/
public int getBuffer(){
return buffer;
}
/**
* Play this sound as a sound effect
*
*/
2007-03-15 23:29:55 +00:00
public void play() {
sourceId = SoundManager.getInstnace().playSound(this, false);
2007-03-16 19:16:00 +00:00
update();
2007-03-15 23:29:55 +00:00
}
/**
* Loop this sound
*
2007-03-15 23:29:55 +00:00
*/
public void loop() {
SoundManager.getInstnace().playSound(this, true);
2007-03-16 19:16:00 +00:00
update();
}
/**
* Updates the sound
*/
public void update() {
//AL10.alSource(source.get(0), AL10.AL_POSITION, sourcePos);
SoundManager.getInstnace().setSoundLocation(this,
getLocation().getX(),
getLocation().getY(),
getLocation().getZ());
2007-03-16 19:16:00 +00:00
}
public Vector3f getVelocity(){
return velocity;
}
/**
* Returns the bound of this class
*/
public Rectangle getBound() {
return new Rectangle(
(int)getLocation().getX(),
(int)getLocation().getY(),
10, 10);
}
2007-04-08 15:57:10 +00:00
@Override
public Texture getTexture() {
return null;
}
}