ppp
This commit is contained in:
parent
1ded694712
commit
810b52d57c
9 changed files with 411 additions and 0 deletions
BIN
VBO/lib/slick.jar
Normal file
BIN
VBO/lib/slick.jar
Normal file
Binary file not shown.
BIN
VBO/res/sounds/test.wav
Normal file
BIN
VBO/res/sounds/test.wav
Normal file
Binary file not shown.
142
VBO/src/mrdev023/audio/Audio.java
Normal file
142
VBO/src/mrdev023/audio/Audio.java
Normal file
|
@ -0,0 +1,142 @@
|
|||
package mrdev023.audio;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import org.lwjgl.util.*;
|
||||
import static org.lwjgl.openal.AL10.*;
|
||||
|
||||
public class Audio {
|
||||
|
||||
private String fileName;
|
||||
private WaveData soundData;
|
||||
private int buffer,source;
|
||||
|
||||
public static final int INITIAL_STATE = 4113,PAUSED_STATE = 4115,STOPPED_STATE = 4116,PLAYING_STATE = 4114;
|
||||
|
||||
public Audio(String fileName) throws FileNotFoundException{
|
||||
this.fileName = fileName;
|
||||
setSound();
|
||||
}
|
||||
|
||||
private void setSound() throws FileNotFoundException{
|
||||
soundData = WaveData.create(new BufferedInputStream(new FileInputStream("res" + File.separatorChar +
|
||||
"sounds" + File.separatorChar + fileName)));
|
||||
buffer = alGenBuffers();
|
||||
alBufferData(buffer, soundData.format, soundData.data, soundData.samplerate);
|
||||
soundData.dispose();
|
||||
source = alGenSources();
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
|
||||
}
|
||||
|
||||
public void playSound(){
|
||||
alSourcePlay(source);
|
||||
}
|
||||
|
||||
public int getStateSound(){
|
||||
return alGetSourcei(source, AL_SOURCE_STATE);
|
||||
}
|
||||
|
||||
public boolean isStopped(){
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == STOPPED_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isPaused(){
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PAUSED_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isPlaying(){
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PLAYING_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isInitial(){
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == INITIAL_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public void stopSound(){
|
||||
alSourceStop(source);
|
||||
}
|
||||
|
||||
public void pauseSound(){
|
||||
alSourcePause(source);
|
||||
}
|
||||
|
||||
public void rewindSound(){
|
||||
alSourceRewind(source);
|
||||
}
|
||||
|
||||
public void setGain(float gain){
|
||||
if(gain > 1.0f)gain = 1.0f;
|
||||
if(gain < 0.0f)gain = 0.0f;
|
||||
alSourcef(source, AL_GAIN, gain);
|
||||
}
|
||||
|
||||
public void setPitch(float pitch){
|
||||
if(pitch < 0.0f)pitch = 0.0f;
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
}
|
||||
|
||||
|
||||
public float getGain(){
|
||||
return alGetSourcef(source, AL_GAIN);
|
||||
}
|
||||
|
||||
public float getPitch(){
|
||||
return alGetSourcef(source, AL_PITCH);
|
||||
}
|
||||
|
||||
public void setLooping(boolean looping){
|
||||
if(looping){
|
||||
alSourcef(source, AL_LOOPING, AL_TRUE);
|
||||
}else{
|
||||
alSourcef(source, AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroySound(){
|
||||
alDeleteSources(source);
|
||||
alDeleteBuffers(buffer);
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) throws FileNotFoundException {
|
||||
this.fileName = fileName;
|
||||
setSound();
|
||||
}
|
||||
|
||||
public WaveData getSoundData() {
|
||||
return soundData;
|
||||
}
|
||||
|
||||
public void setSoundData(WaveData soundData) {
|
||||
this.soundData = soundData;
|
||||
}
|
||||
|
||||
public int getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public void setBuffer(int buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
public int getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(int source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
40
VBO/src/mrdev023/audio/AudioManager.java
Normal file
40
VBO/src/mrdev023/audio/AudioManager.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package mrdev023.audio;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.openal.*;
|
||||
|
||||
public class AudioManager {
|
||||
|
||||
public static ArrayList<Audio> music = new ArrayList<Audio>();
|
||||
public static ArrayList<Audio> sound = new ArrayList<Audio>();
|
||||
|
||||
public static void create() throws LWJGLException{
|
||||
AL.create();
|
||||
}
|
||||
|
||||
public static void addMusic(String name){
|
||||
try {
|
||||
music.add(new Audio(name));
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addSound(String name){
|
||||
try {
|
||||
sound.add(new Audio(name));
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void destroy(){
|
||||
AL.destroy();
|
||||
}
|
||||
|
||||
}
|
44
VBO/src/mrdev023/rendering/gui/ButtonGUI.java
Normal file
44
VBO/src/mrdev023/rendering/gui/ButtonGUI.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package mrdev023.rendering.gui;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import org.newdawn.slick.*;
|
||||
|
||||
|
||||
public class ButtonGUI extends GUI{
|
||||
|
||||
public ButtonGUI(String value,float x,float y,float width,float height){
|
||||
super(value,x, y, width, height,(int)(height/2));
|
||||
}
|
||||
|
||||
public void render()
|
||||
{
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
if(mouseIsCollide()){
|
||||
font.drawString((int)(x + (width/2 - font.getWidth(value)/2)),(int)(y + font.getHeight()/2 - height/16),value,Color.green);
|
||||
}else{
|
||||
font.drawString((int)(x + (width/2 - font.getWidth(value)/2)),(int)(y + font.getHeight()/2 - height/16),value,Color.red);
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
if(mouseIsCollide())glColor4f(0,1,0,1);
|
||||
else glColor4f(1,0,0,1);
|
||||
glLineWidth(height/(height/2));
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(x,y);
|
||||
glVertex2f(x + width,y);
|
||||
glVertex2f(x + width,y + height);
|
||||
glVertex2f(x,y + height);
|
||||
glEnd();
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
}
|
110
VBO/src/mrdev023/rendering/gui/GUI.java
Normal file
110
VBO/src/mrdev023/rendering/gui/GUI.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package mrdev023.rendering.gui;
|
||||
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.gui.action.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import org.newdawn.slick.*;
|
||||
import org.newdawn.slick.font.effects.*;
|
||||
|
||||
public abstract class GUI {
|
||||
|
||||
protected float x,y,width,height;
|
||||
protected Color4f color;
|
||||
protected String value;
|
||||
|
||||
public static final int NULL = 0,CLICKED = 1;
|
||||
|
||||
public Action action;
|
||||
|
||||
protected TrueTypeFont font = null;
|
||||
|
||||
public GUI(String value,float x,float y,float width,float height,int size){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.color = new Color4f(1f,1f,1f,1f);
|
||||
this.value = value;
|
||||
font = new TrueTypeFont (new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, size),false);
|
||||
this.action = new Action() {
|
||||
public void manageAction(int action) {}
|
||||
public void hover(Vector2f position) {}
|
||||
};
|
||||
}
|
||||
|
||||
public abstract void render();
|
||||
public abstract void update();
|
||||
|
||||
|
||||
public void updateAction(){
|
||||
while(Mouse.next()){
|
||||
if(Mouse.getEventButtonState()){
|
||||
if(Mouse.getEventButton() == 0 && mouseIsCollide()){
|
||||
action.manageAction(CLICKED);
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
if(mouseIsCollide())action.hover(new Vector2f(Mouse.getX(),(Display.getDisplayMode().getHeight() - Mouse.getY())));
|
||||
}
|
||||
|
||||
public void setAction(Action a){
|
||||
this.action = a;
|
||||
}
|
||||
|
||||
public boolean mouseIsCollide(){
|
||||
if(Mouse.getX() > x && Mouse.getX() < (x+width)
|
||||
&& (Display.getDisplayMode().getHeight() - Mouse.getY()) > y && (Display.getDisplayMode().getHeight() - Mouse.getY()) < (y+height))return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Color4f getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color4f color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
|
||||
}
|
27
VBO/src/mrdev023/rendering/gui/LabelGUI.java
Normal file
27
VBO/src/mrdev023/rendering/gui/LabelGUI.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package mrdev023.rendering.gui;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import org.newdawn.slick.*;
|
||||
|
||||
public class LabelGUI extends GUI{
|
||||
|
||||
public LabelGUI(String value,float x, float y, float width, float height) {
|
||||
super(value,x, y, width, height,(int)(height/2));
|
||||
}
|
||||
|
||||
public void render() {
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
font.drawString((int)(x + (width/2 - font.getWidth(value)/2)),(int)(y + font.getHeight()/2 - height/16),value,Color.red);
|
||||
glDisable(GL_BLEND);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
}
|
39
VBO/src/mrdev023/rendering/gui/Text.java
Normal file
39
VBO/src/mrdev023/rendering/gui/Text.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package mrdev023.rendering.gui;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import mrdev023.math.*;
|
||||
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
public class Text {
|
||||
|
||||
public static int getWidth(String a){
|
||||
return a.length() * 10;
|
||||
}
|
||||
|
||||
public static int getHeight(){
|
||||
return 8;
|
||||
}
|
||||
|
||||
public static void drawString(String s, int x, int y,int size,Color4f color) {
|
||||
int startX = x;
|
||||
int a = 10;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glColor4f(color.getR(), color.getG(), color.getB(), color.getA());
|
||||
GL11.glPointSize(size);
|
||||
GL11.glBegin(GL11.GL_POINTS);
|
||||
char[] c = s.toCharArray();
|
||||
for(char c1 : c){
|
||||
switch(c1){
|
||||
case 'a':
|
||||
GL11.glVertex2f(x, y);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
9
VBO/src/mrdev023/rendering/gui/action/Action.java
Normal file
9
VBO/src/mrdev023/rendering/gui/action/Action.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package mrdev023.rendering.gui.action;
|
||||
|
||||
import mrdev023.math.*;
|
||||
|
||||
public abstract class Action {
|
||||
|
||||
public abstract void manageAction(int action);
|
||||
public abstract void hover(Vector2f position);
|
||||
}
|
Reference in a new issue