Add gradle project
This commit is contained in:
parent
cf97742219
commit
b7bd35c153
69 changed files with 225 additions and 18 deletions
148
src/main/java/globalgamejam/Main.java
Normal file
148
src/main/java/globalgamejam/Main.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
package globalgamejam;
|
||||
|
||||
//http://www.tomdalling.com/blog/modern-opengl/08-even-more-lighting-directional-lights-spotlights-multiple-lights/
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_RESIZABLE;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_SAMPLES;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE;
|
||||
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
|
||||
import static org.lwjgl.glfw.GLFW.glfwDefaultWindowHints;
|
||||
import static org.lwjgl.glfw.GLFW.glfwDestroyWindow;
|
||||
import static org.lwjgl.glfw.GLFW.glfwGetPrimaryMonitor;
|
||||
import static org.lwjgl.glfw.GLFW.glfwGetVideoMode;
|
||||
import static org.lwjgl.glfw.GLFW.glfwInit;
|
||||
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
|
||||
import static org.lwjgl.glfw.GLFW.glfwPollEvents;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSetWindowTitle;
|
||||
import static org.lwjgl.glfw.GLFW.glfwShowWindow;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
|
||||
import static org.lwjgl.glfw.GLFW.glfwTerminate;
|
||||
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
|
||||
import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
|
||||
import static org.lwjgl.opengl.GL11.GL_VERSION;
|
||||
import static org.lwjgl.opengl.GL11.glGetString;
|
||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import globalgamejam.audio.Audio;
|
||||
import globalgamejam.game.Game;
|
||||
import globalgamejam.game.MainMenuGame;
|
||||
import globalgamejam.input.Input;
|
||||
import globalgamejam.render.Camera;
|
||||
import globalgamejam.render.DisplayManager;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
//Valeur de la fenetre
|
||||
public static final int WIDTH = 800,HEIGHT = 600;
|
||||
public static final String TITLE = "Beach Fighter (OpenGL)";
|
||||
|
||||
//Variable pour la gestion de la fenetre
|
||||
public static long windowID = 0;
|
||||
public static GLFWErrorCallback errorCallback;
|
||||
|
||||
//variable du moteur du jeu
|
||||
public static float delta = 0;
|
||||
public static Game game;
|
||||
public static long previous = System.currentTimeMillis(),previousInfo = System.currentTimeMillis(),previousTicks = System.currentTimeMillis();
|
||||
public static int FPS = 0,TICKS = 0;
|
||||
|
||||
public static boolean isDestroy = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// System.setProperty("org.lwjgl.librarypath", new File("libs").getAbsolutePath());
|
||||
//Creation de la fenetre
|
||||
//------------------------------------------------------------------------------------
|
||||
errorCallback = new GLFWErrorCallback() {
|
||||
public void invoke(int error, long description) {
|
||||
System.err.println("ID : " + error + " | Description :" + description);
|
||||
}
|
||||
};
|
||||
// glfwSetErrorCallback(errorCallback);
|
||||
|
||||
if(!glfwInit())throw new Exception("GLFW not init");
|
||||
glfwDefaultWindowHints();
|
||||
glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);//Activation du MSAA x4
|
||||
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
windowID = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL);
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
glfwSetWindowPos(windowID,(vidmode.width()-WIDTH)/2,(vidmode.height()-HEIGHT)/2);
|
||||
glfwShowWindow(windowID);
|
||||
glfwMakeContextCurrent(windowID);
|
||||
GL.createCapabilities();
|
||||
System.out.println("OpenGL Version :" + glGetString(GL_VERSION));
|
||||
System.out.println("GLSL Shader Version :" + glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
//Creation du device audio
|
||||
//------------------------------------------------------------------------------------
|
||||
Audio.create();
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
//initialisation
|
||||
//------------------------------------------------------------------------------------
|
||||
//glEnable(GL_MULTISAMPLE);//Activation du MSAA
|
||||
Input.init();
|
||||
game = new MainMenuGame();
|
||||
|
||||
Camera.transform();
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
while(!glfwWindowShouldClose(windowID) && !isDestroy){
|
||||
|
||||
if(System.currentTimeMillis() - previousTicks >= 1000/120){//Update TICKS
|
||||
glfwPollEvents();
|
||||
Input.update();
|
||||
game.update();
|
||||
previousTicks = System.currentTimeMillis();
|
||||
delta = (float)(System.currentTimeMillis() - previous)/1000.0f;
|
||||
previous = System.currentTimeMillis();
|
||||
TICKS++;
|
||||
}else{//Update FPS
|
||||
DisplayManager.clear();
|
||||
DisplayManager.preRender2D();
|
||||
DisplayManager.render2D();
|
||||
DisplayManager.preRenderGUI();
|
||||
DisplayManager.renderGUI();
|
||||
glfwSwapBuffers(windowID);
|
||||
FPS++;
|
||||
}
|
||||
|
||||
if(System.currentTimeMillis() - previousInfo >= 1000){
|
||||
glfwSetWindowTitle(windowID, TITLE + " | FPS:" + FPS + " TICKS:" + TICKS);
|
||||
FPS = 0;
|
||||
TICKS = 0;
|
||||
previousInfo = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void destroy(){
|
||||
game.destroy();
|
||||
Audio.destroy();
|
||||
glfwDestroyWindow(windowID);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
public static void changeGame(Game g){
|
||||
game.destroy();
|
||||
game = g;
|
||||
}
|
||||
|
||||
}
|
326
src/main/java/globalgamejam/audio/Audio.java
Normal file
326
src/main/java/globalgamejam/audio/Audio.java
Normal file
|
@ -0,0 +1,326 @@
|
|||
package globalgamejam.audio;
|
||||
|
||||
import static org.lwjgl.openal.AL.createCapabilities;
|
||||
import static org.lwjgl.openal.AL10.*;
|
||||
import static org.lwjgl.openal.ALC10.*;
|
||||
import static org.lwjgl.stb.STBVorbis.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.openal.*;
|
||||
|
||||
|
||||
import org.lwjgl.stb.STBVorbisInfo;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Audio {
|
||||
|
||||
//Variables global
|
||||
//------------------------------------------------------
|
||||
public static long device;
|
||||
public static ALCCapabilities caps;
|
||||
public static long context;
|
||||
public static final int INITIAL_STATE = 4113,PAUSED_STATE = 4115,STOPPED_STATE = 4116,PLAYING_STATE = 4114;
|
||||
//------------------------------------------------------
|
||||
|
||||
//Variable de l'objet audio ou du son a lire
|
||||
//------------------------------------------------------
|
||||
private int buffer,source;
|
||||
private String fileName;
|
||||
private String format;
|
||||
//------------------------------------------------------
|
||||
|
||||
//Fonction global
|
||||
//------------------------------------------------------
|
||||
public static void create(){
|
||||
device = alcOpenDevice((ByteBuffer)null);
|
||||
ALCCapabilities deviceCaps = ALC.createCapabilities(device);
|
||||
|
||||
context = alcCreateContext(device, (IntBuffer)null);
|
||||
alcMakeContextCurrent(context);
|
||||
createCapabilities(deviceCaps);
|
||||
}
|
||||
|
||||
public static void destroy(){
|
||||
alcDestroyContext(context);
|
||||
alcCloseDevice(device);
|
||||
ALC.destroy();
|
||||
}
|
||||
//------------------------------------------------------
|
||||
|
||||
//Fonction de l'objet audio ou du son a lire
|
||||
//------------------------------------------------------
|
||||
|
||||
public Audio(String fileName) throws Exception{
|
||||
this.fileName = fileName;
|
||||
setSound();
|
||||
}
|
||||
|
||||
private void setSound() throws Exception{
|
||||
if(fileName.endsWith(".ogg")){
|
||||
loadOGGFormat();
|
||||
format = "OGG";
|
||||
}else if(fileName.endsWith(".wav")){
|
||||
loadWavFormat();
|
||||
format = "WAV";
|
||||
}else{
|
||||
throw new Exception("Format not supported !");
|
||||
}
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
int size = alGetBufferi(buffer,AL_SIZE);
|
||||
int bits = alGetBufferi(buffer, AL_BITS);
|
||||
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
||||
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
||||
System.out.println(fileName + " loaded !" + " | TIME : " + (size/channels/(bits/8)/freq) + "s | BITS : " + bits + " | CHANNELS : " + channels + " | FREQUENCE : " + freq + " FORMAT : " + format);
|
||||
}
|
||||
|
||||
public void loadWavFormat() throws Exception{
|
||||
AudioInputStream ais = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(fileName)));
|
||||
AudioFormat audioformat = ais.getFormat();
|
||||
|
||||
// get channels
|
||||
int channels = 0;
|
||||
if (audioformat.getChannels() == 1) {
|
||||
if (audioformat.getSampleSizeInBits() == 8) {
|
||||
channels = AL10.AL_FORMAT_MONO8;
|
||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||
channels = AL10.AL_FORMAT_MONO16;
|
||||
} else {
|
||||
assert false : "Illegal sample size";
|
||||
}
|
||||
} else if (audioformat.getChannels() == 2) {
|
||||
if (audioformat.getSampleSizeInBits() == 8) {
|
||||
channels = AL10.AL_FORMAT_STEREO8;
|
||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||
channels = AL10.AL_FORMAT_STEREO16;
|
||||
} else {
|
||||
assert false : "Illegal sample size";
|
||||
}
|
||||
} else {
|
||||
assert false : "Only mono or stereo is supported";
|
||||
}
|
||||
|
||||
int available = ais.available();
|
||||
if(available <= 0) {
|
||||
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
||||
}
|
||||
byte[] buf = new byte[ais.available()];
|
||||
int read = 0, total = 0;
|
||||
while ((read = ais.read(buf, total, buf.length - total)) != -1
|
||||
&& total < buf.length) {
|
||||
total += read;
|
||||
}
|
||||
byte[] audio_bytes = buf;
|
||||
boolean two_bytes_data = audioformat.getSampleSizeInBits() == 16;
|
||||
ByteOrder order = audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
||||
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
|
||||
dest.order(ByteOrder.nativeOrder());
|
||||
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
|
||||
src.order(order);
|
||||
if (two_bytes_data) {
|
||||
ShortBuffer dest_short = dest.asShortBuffer();
|
||||
ShortBuffer src_short = src.asShortBuffer();
|
||||
while (src_short.hasRemaining())
|
||||
dest_short.put(src_short.get());
|
||||
} else {
|
||||
while (src.hasRemaining())
|
||||
dest.put(src.get());
|
||||
}
|
||||
dest.rewind();
|
||||
|
||||
this.buffer = alGenBuffers();
|
||||
this.source = alGenSources();
|
||||
alBufferData(this.buffer, channels, dest, (int)audioformat.getSampleRate());
|
||||
dest.clear();
|
||||
}
|
||||
|
||||
public void loadOGGFormat(){
|
||||
STBVorbisInfo info = STBVorbisInfo.malloc();
|
||||
ByteBuffer buff = BufferUtils.createByteBuffer(0);
|
||||
//lecture du fichier
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
try {
|
||||
File file = new File(fileName);
|
||||
if ( file.isFile() ) {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
FileChannel fc = fis.getChannel();
|
||||
buff = BufferUtils.createByteBuffer((int)fc.size() + 1);
|
||||
|
||||
while ( fc.read(buff) != -1 ) ;
|
||||
|
||||
fis.close();
|
||||
fc.close();
|
||||
} else {
|
||||
System.err.println("File not found !");
|
||||
return;
|
||||
}
|
||||
|
||||
buff.flip();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
IntBuffer error = BufferUtils.createIntBuffer(1);
|
||||
long decoder = stb_vorbis_open_memory(buff, error, null);
|
||||
if ( decoder == NULL )
|
||||
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
||||
|
||||
stb_vorbis_get_info(decoder, info);
|
||||
|
||||
int channels = info.channels();
|
||||
|
||||
stb_vorbis_seek_start(decoder);
|
||||
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
|
||||
|
||||
ShortBuffer pcm = BufferUtils.createShortBuffer(lengthSamples * channels);
|
||||
|
||||
stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm);
|
||||
stb_vorbis_close(decoder);
|
||||
|
||||
buffer = alGenBuffers();
|
||||
|
||||
source = alGenSources();
|
||||
|
||||
if(channels == 1)alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());
|
||||
else alBufferData(buffer, AL_FORMAT_STEREO16, pcm, info.sample_rate());
|
||||
}
|
||||
|
||||
public void playSound(){
|
||||
if(source == 0 || buffer == 0) return;
|
||||
alSourcePlay(source);
|
||||
}
|
||||
|
||||
public int getPosition(){
|
||||
return alGetSourcei(source, AL_POSITION);
|
||||
}
|
||||
|
||||
public int getDurationInSeconds(){
|
||||
if(source == 0 || buffer == 0) return 0;
|
||||
int size = alGetBufferi(buffer,AL_SIZE);
|
||||
int bits = alGetBufferi(buffer, AL_BITS);
|
||||
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
||||
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
||||
return size/channels/(bits/8)/freq;
|
||||
}
|
||||
|
||||
public int getStateSound(){
|
||||
if(source == 0 || buffer == 0) return 0;
|
||||
return alGetSourcei(source, AL_SOURCE_STATE);
|
||||
}
|
||||
|
||||
public boolean isStopped(){
|
||||
if(source == 0 || buffer == 0) return false;
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == STOPPED_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isPaused(){
|
||||
if(source == 0 || buffer == 0) return false;
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PAUSED_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isPlaying(){
|
||||
if(source == 0 || buffer == 0) return false;
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PLAYING_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isInitial(){
|
||||
if(source == 0 || buffer == 0) return false;
|
||||
if(alGetSourcei(source, AL_SOURCE_STATE) == INITIAL_STATE)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public void stopSound(){
|
||||
if(source == 0 || buffer == 0) return;
|
||||
alSourceStop(source);
|
||||
}
|
||||
|
||||
public void pauseSound(){
|
||||
if(source == 0 || buffer == 0) return;
|
||||
alSourcePause(source);
|
||||
}
|
||||
|
||||
public void rewindSound(){
|
||||
if(source == 0 || buffer == 0) return;
|
||||
alSourceRewind(source);
|
||||
}
|
||||
|
||||
public void setGain(float gain){
|
||||
if(source == 0 || buffer == 0) return;
|
||||
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(source == 0 || buffer == 0) return;
|
||||
if(pitch < 0.0f)pitch = 0.0f;
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
}
|
||||
|
||||
|
||||
public float getGain(){
|
||||
if(source == 0 || buffer == 0) return 0;
|
||||
return alGetSourcef(source, AL_GAIN);
|
||||
}
|
||||
|
||||
public float getPitch(){
|
||||
if(source == 0 || buffer == 0) return 0;
|
||||
return alGetSourcef(source, AL_PITCH);
|
||||
}
|
||||
|
||||
public void setLooping(boolean looping){
|
||||
if(source == 0 || buffer == 0) return;
|
||||
if(looping){
|
||||
alSourcef(source, AL_LOOPING, AL_TRUE);
|
||||
}else{
|
||||
alSourcef(source, AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroySound(){
|
||||
alDeleteSources(source);
|
||||
alDeleteBuffers(buffer);
|
||||
source = 0;
|
||||
buffer = 0;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) throws Exception {
|
||||
this.fileName = fileName;
|
||||
destroySound();
|
||||
setSound();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
//------------------------------------------------------
|
||||
|
||||
}
|
26
src/main/java/globalgamejam/game/Coffre.java
Normal file
26
src/main/java/globalgamejam/game/Coffre.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.tiles.CoffreTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
public class Coffre extends PhysicalEntity {
|
||||
|
||||
private final Tile tile;
|
||||
|
||||
public Coffre(String texturePath, float x, float y){
|
||||
super(x, y, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
this.tile = new CoffreTile(texturePath, x, y);
|
||||
|
||||
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
|
||||
}
|
||||
|
||||
public Tile getTile(){
|
||||
return this.tile;
|
||||
}
|
||||
|
||||
public void makeEffect(int numPlayerHitCoffre){
|
||||
|
||||
}
|
||||
}
|
31
src/main/java/globalgamejam/game/EObjetType.java
Normal file
31
src/main/java/globalgamejam/game/EObjetType.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
public enum EObjetType {
|
||||
|
||||
POISSON("res/textures/dechets1.png",-2, 0.5f),POMME("res/textures/dechets.png",-3, 0.75f),
|
||||
ETOILE_DE_MER("res/textures/bonus1.png",2, 0.75f),COQUILLAGE("res/textures/bonus2.png",3, 0.75f),
|
||||
COQUILLAGE2("res/textures/bonus3.png",4, 0.85f),BANANE("res/textures/banane.png",-5, 0.9f),
|
||||
BALLON("res/textures/ballon.png", 1, 0.5f);
|
||||
|
||||
private int points;
|
||||
private String filename;
|
||||
private float despawnRate;
|
||||
|
||||
EObjetType(String filename, int points, float despawnRate){
|
||||
this.points = points;
|
||||
this.filename = filename;
|
||||
this.despawnRate = despawnRate;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public float getDespawnRate(){
|
||||
return this.despawnRate;
|
||||
}
|
||||
}
|
13
src/main/java/globalgamejam/game/EffectEnum.java
Normal file
13
src/main/java/globalgamejam/game/EffectEnum.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
public enum EffectEnum {
|
||||
|
||||
INVERSE_SCREEN,
|
||||
SCORE_FREEZE,
|
||||
MUSIC_MULTIPLICATOR_J1,
|
||||
MUSIC_MULTIPLICATOR_J2,
|
||||
INVERSE_COMMAND_J1,
|
||||
INVERSE_COMMAND_J2,
|
||||
HEAVY_J1,
|
||||
HEAVY_J2
|
||||
}
|
24
src/main/java/globalgamejam/game/Game.java
Normal file
24
src/main/java/globalgamejam/game/Game.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import globalgamejam.render.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public abstract class Game {
|
||||
|
||||
public Game(){
|
||||
Camera.init();
|
||||
init();
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
public abstract void update();
|
||||
public abstract void render2D();
|
||||
public abstract void renderGUI();
|
||||
public abstract void destroy();
|
||||
|
||||
|
||||
}
|
66
src/main/java/globalgamejam/game/HighScore.java
Normal file
66
src/main/java/globalgamejam/game/HighScore.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class HighScore implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 182903812903812908L;
|
||||
|
||||
private int[] topScore;
|
||||
private int length;
|
||||
|
||||
public HighScore(){
|
||||
this.topScore = new int[10];
|
||||
this.length = 10;
|
||||
}
|
||||
|
||||
public void put(int data){
|
||||
ArrayList<Integer> scores = new ArrayList<Integer>();
|
||||
boolean alreadyExist = false;
|
||||
for(int i : topScore){
|
||||
scores.add(i);
|
||||
if(i == data){
|
||||
alreadyExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!alreadyExist){
|
||||
scores.add(data);
|
||||
scores.sort(new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
});
|
||||
|
||||
for(int i = 0;i < this.topScore.length;i++){
|
||||
this.topScore[i] = scores.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int[] getTopScores(){
|
||||
return this.topScore;
|
||||
}
|
||||
|
||||
public int getTopScore(){
|
||||
return this.topScore[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
for(int i = 0;i < this.topScore.length;i++){
|
||||
sb.append(this.topScore[i]);
|
||||
if(i != this.topScore.length - 1)sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
102
src/main/java/globalgamejam/game/MainGame.java
Normal file
102
src/main/java/globalgamejam/game/MainGame.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.audio.Audio;
|
||||
import globalgamejam.gui.GUILabel;
|
||||
import globalgamejam.input.IO;
|
||||
import globalgamejam.interfaces.MainInterfaces;
|
||||
import globalgamejam.world.MainWorld;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class MainGame extends Game{
|
||||
|
||||
public Audio audioBackground;
|
||||
public Audio audioMacarena;
|
||||
public Audio audioBennyHill;
|
||||
public Audio audioEffect;
|
||||
|
||||
public static final int SCORE_INIT = 500;
|
||||
public static final float START_TIMER = 300;
|
||||
public static float time_in_sec = 0;
|
||||
private MainWorld world;
|
||||
private MainInterfaces interfaces;
|
||||
public float[] scores;
|
||||
public final int HELP_KEY = GLFW.GLFW_KEY_H;
|
||||
public HighScore highScore;
|
||||
public boolean isEnd = false;
|
||||
private GUILabel loading;
|
||||
@Override
|
||||
public void init() {
|
||||
loading = new GUILabel("Loading",10,10,Color.WHITE,"Arial",16);
|
||||
loading.render();
|
||||
|
||||
// load audio
|
||||
try{
|
||||
audioMacarena = new Audio("res/audio/macarena_court.ogg");
|
||||
audioMacarena.setGain(0.4f);
|
||||
|
||||
audioBennyHill = new Audio("res/audio/background.ogg");
|
||||
audioBennyHill.setGain(0.4f);
|
||||
} catch(Exception e){}
|
||||
|
||||
this.scores = new float[2];
|
||||
this.scores[0] = SCORE_INIT;
|
||||
this.scores[1] = SCORE_INIT;
|
||||
time_in_sec = START_TIMER;
|
||||
try{
|
||||
this.highScore = IO.loadHighScore("res/highscore");
|
||||
}catch(Exception e){
|
||||
this.highScore = new HighScore();
|
||||
}
|
||||
world = new MainWorld(this);
|
||||
interfaces = new MainInterfaces(this);
|
||||
loading.destroy();
|
||||
}
|
||||
|
||||
public void saveHighScore(){
|
||||
IO.writeHighScore("res/highscore", this.highScore);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
this.scores[0] = SCORE_INIT;
|
||||
this.scores[1] = SCORE_INIT;
|
||||
time_in_sec = START_TIMER;
|
||||
world.destroy();
|
||||
isEnd = false;
|
||||
world = new MainWorld(this);
|
||||
world.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
interfaces.update();
|
||||
world.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render2D() {
|
||||
world.render();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderGUI() {
|
||||
interfaces.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
interfaces.destroy();
|
||||
world.destroy();
|
||||
}
|
||||
|
||||
|
||||
}
|
99
src/main/java/globalgamejam/game/MainMenuGame.java
Normal file
99
src/main/java/globalgamejam/game/MainMenuGame.java
Normal file
|
@ -0,0 +1,99 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.gui.ActionGUI;
|
||||
import globalgamejam.gui.GUILabel;
|
||||
|
||||
public class MainMenuGame extends Game{
|
||||
|
||||
private GUILabel menuLabel;
|
||||
private GUILabel jouerLabel;
|
||||
private GUILabel quitterLabel;
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
menuLabel = new GUILabel("MENU", 0, 10, Color.WHITE, "Arial", 32);
|
||||
menuLabel.setPosition(Main.WIDTH/2 - menuLabel.getWitdh()/2, 10);
|
||||
jouerLabel = new GUILabel("JOUER (A)", 0, 60, Color.WHITE, "Arial", 24);
|
||||
jouerLabel.setPosition(Main.WIDTH/2 - jouerLabel.getWitdh()/2, 70);
|
||||
jouerLabel.setAction(new ActionGUI(){
|
||||
@Override
|
||||
public void enter(float mouseX,float mouseY){
|
||||
jouerLabel.setColor(new Color(1, 1, 1, 0.5f));
|
||||
}
|
||||
@Override
|
||||
public void leave(float mouseX,float mouseY){
|
||||
jouerLabel.setColor(Color.WHITE);
|
||||
}
|
||||
@Override
|
||||
public void clicked(float mouseX, float mouseY, int buttonKey, int buttonState) {
|
||||
Main.changeGame(new MainGame());
|
||||
}
|
||||
@Override
|
||||
public void joystickButtonState(int idJoy,int id,int state){
|
||||
if(idJoy == GLFW.GLFW_JOYSTICK_1){
|
||||
if(state == 1 && id == 0){
|
||||
Main.changeGame(new MainGame());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
quitterLabel = new GUILabel("QUITTER (B)", 0, 80, Color.WHITE, "Arial", 24);
|
||||
quitterLabel.setPosition(Main.WIDTH/2 - quitterLabel.getWitdh()/2, 100);
|
||||
quitterLabel.setAction(new ActionGUI(){
|
||||
@Override
|
||||
public void enter(float mouseX,float mouseY){
|
||||
quitterLabel.setColor(new Color(1, 1, 1, 0.5f));
|
||||
}
|
||||
@Override
|
||||
public void leave(float mouseX,float mouseY){
|
||||
quitterLabel.setColor(Color.WHITE);
|
||||
}
|
||||
@Override
|
||||
public void clicked(float mouseX, float mouseY, int buttonKey, int buttonState) {
|
||||
Main.isDestroy = true;
|
||||
}
|
||||
@Override
|
||||
public void joystickButtonState(int idJoy,int id,int state){
|
||||
if(idJoy == GLFW.GLFW_JOYSTICK_1){
|
||||
if(state == 1 && id == 1){
|
||||
Main.isDestroy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
menuLabel.update();
|
||||
jouerLabel.update();
|
||||
quitterLabel.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render2D() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderGUI() {
|
||||
menuLabel.render();
|
||||
jouerLabel.render();
|
||||
quitterLabel.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
menuLabel.destroy();
|
||||
jouerLabel.destroy();
|
||||
quitterLabel.destroy();
|
||||
}
|
||||
|
||||
}
|
27
src/main/java/globalgamejam/game/Mur.java
Normal file
27
src/main/java/globalgamejam/game/Mur.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.tiles.MurTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
public class Mur extends PhysicalEntity {
|
||||
|
||||
private final Tile tile;
|
||||
|
||||
public Mur(float x, float y, String texturePath){
|
||||
super(x, y, 0, 0, 5, 0, 0, 0);
|
||||
|
||||
this.tile = new MurTile(x, y, texturePath);
|
||||
|
||||
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
|
||||
}
|
||||
|
||||
public Tile getTile(){
|
||||
return this.tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSpeed(){
|
||||
return this.getSpeedFactor();
|
||||
}
|
||||
}
|
68
src/main/java/globalgamejam/game/Objet.java
Normal file
68
src/main/java/globalgamejam/game/Objet.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.tiles.ObjetTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
public class Objet extends PhysicalEntity {
|
||||
|
||||
private static final int TIME_IN_SEC = 5;
|
||||
|
||||
private EObjetType type;
|
||||
private float inactiveDelay = 0;
|
||||
private float despawnRate;
|
||||
private final Tile tile;
|
||||
|
||||
public Objet(String texturePath, float x, float y, float speed, float xVelocity, float yVelocity, float frictionFactor){
|
||||
super(x, y, 0, 0, speed, xVelocity, yVelocity, frictionFactor);
|
||||
|
||||
this.tile = new ObjetTile(texturePath, x, y);
|
||||
|
||||
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
|
||||
}
|
||||
|
||||
public Tile getTile(){
|
||||
return this.tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveTile(){
|
||||
this.tile.setPosition(new Vector2f(this.x, this.y));
|
||||
this.tile.applyTransform();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "x : " + this.x + ", y : " + this.y;
|
||||
}
|
||||
|
||||
public EObjetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(EObjetType type) {
|
||||
this.type = type;
|
||||
this.despawnRate = this.type.getDespawnRate();
|
||||
}
|
||||
|
||||
public float getInactiveDelay() {
|
||||
return inactiveDelay;
|
||||
}
|
||||
|
||||
public boolean underWave(float yWave){
|
||||
return yWave >= this.y + this.getSizeRadius();
|
||||
}
|
||||
|
||||
public boolean shouldDespawn(){
|
||||
if(this.despawnRate >= Math.random()){
|
||||
return true;
|
||||
}
|
||||
this.despawnRate *= 1.05f;
|
||||
return false;
|
||||
}
|
||||
}
|
117
src/main/java/globalgamejam/game/Player.java
Normal file
117
src/main/java/globalgamejam/game/Player.java
Normal file
|
@ -0,0 +1,117 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.render.Texture;
|
||||
import globalgamejam.tiles.PlayerTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jean-Baptiste
|
||||
*
|
||||
*/
|
||||
public class Player extends PhysicalEntity {
|
||||
|
||||
private final Tile tile;
|
||||
private float angle;
|
||||
|
||||
private float speed = 15;
|
||||
|
||||
private final PhysicalEntity brosse;
|
||||
private final float longueurBalai;
|
||||
|
||||
public Player(String path, float x, float y){
|
||||
super(x, y, 100, 0, 3, 0, 0, 10);
|
||||
this.tile = new PlayerTile(path, x, y);
|
||||
|
||||
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().width);
|
||||
|
||||
this.longueurBalai = 82;
|
||||
|
||||
this.brosse = new PhysicalEntity(x, y + this.longueurBalai, 18f, 12f, 15, 0, 0, 0){
|
||||
@Override
|
||||
public float getSpeed(){
|
||||
return getSpeedFactor();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Tile getTile(){
|
||||
return this.tile;
|
||||
}
|
||||
|
||||
public void move(float x, float y){
|
||||
float oldX = this.x;
|
||||
float deltaX = 0;
|
||||
float oldY = this.y;
|
||||
float deltaY = 0;
|
||||
this.addPosition(x, y);
|
||||
|
||||
if(this.x - this.tile.getTexture().width / 2 < 30){
|
||||
this.x = this.tile.getTexture().width / 2 + 30;
|
||||
}
|
||||
else if(this.x + this.tile.getTexture().width / 2 > Main.WIDTH - 30){
|
||||
this.x = Main.WIDTH - this.tile.getTexture().width / 2 - 30;
|
||||
}
|
||||
|
||||
if(this.y - this.tile.getTexture().height / 2 < 34){
|
||||
this.y = this.tile.getTexture().height / 2 + 34;
|
||||
}
|
||||
else if(this.y + this.tile.getTexture().height / 2 > Main.HEIGHT + 18){
|
||||
this.y = Main.HEIGHT - this.tile.getTexture().height / 2 + 18;
|
||||
}
|
||||
|
||||
this.tile.setPosition(new Vector2f(this.x, this.y));
|
||||
this.tile.applyTransform();
|
||||
|
||||
deltaX = this.x - oldX;
|
||||
deltaY = this.y - oldY;
|
||||
this.brosse.addPosition(deltaX, deltaY);
|
||||
}
|
||||
|
||||
public void rotate(float angleRotation){
|
||||
this.angle += angleRotation;
|
||||
this.angle %= 360;
|
||||
if(this.angle < 0){
|
||||
this.angle += 360;
|
||||
}
|
||||
|
||||
this.tile.setRotation(this.angle);
|
||||
this.tile.applyTransform();
|
||||
|
||||
float angleRad = (float)(this.angle * (Math.PI / 180));
|
||||
|
||||
float xBrosse = this.x + this.longueurBalai * -(float)Math.sin(angleRad);
|
||||
float yBrosse = this.y + this.longueurBalai * (float)Math.cos(angleRad);
|
||||
|
||||
this.brosse.setPosition(xBrosse, yBrosse);
|
||||
}
|
||||
|
||||
public boolean brosseCollideWith(PhysicalEntity entity){
|
||||
return this.brosse.collideWithSquareHitBox(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the velocity
|
||||
*/
|
||||
public float getSpeed() {
|
||||
return this.speed;
|
||||
}
|
||||
|
||||
public PhysicalEntity getBrosse(){
|
||||
return this.brosse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.brosse.toString();
|
||||
}
|
||||
|
||||
public float getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
}
|
29
src/main/java/globalgamejam/gui/ActionGUI.java
Normal file
29
src/main/java/globalgamejam/gui/ActionGUI.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package globalgamejam.gui;
|
||||
|
||||
/**
|
||||
* Created by trexr on 20/01/2017.
|
||||
*/
|
||||
public class ActionGUI implements IActionGUI{
|
||||
|
||||
|
||||
@Override
|
||||
public void enter(float mouseX, float mouseY) {}
|
||||
|
||||
@Override
|
||||
public void leave(float mouseX, float mouseY) {}
|
||||
|
||||
@Override
|
||||
public void move(float mouseX, float mouseY) {}
|
||||
|
||||
@Override
|
||||
public void hover(float mouseX, float mouseY) {}
|
||||
|
||||
@Override
|
||||
public void clicked(float mouseX, float mouseY, int buttonKey, int buttonState) {}
|
||||
|
||||
@Override
|
||||
public void joystickButtonState(int idJoy,int id,int state){}
|
||||
|
||||
@Override
|
||||
public void joystickAxisState(int idJoy,int id,float value){}
|
||||
}
|
88
src/main/java/globalgamejam/gui/GUI.java
Normal file
88
src/main/java/globalgamejam/gui/GUI.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package globalgamejam.gui;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import globalgamejam.input.Input;
|
||||
|
||||
/**
|
||||
* Created by trexr on 20/01/2017.
|
||||
*/
|
||||
public abstract class GUI {
|
||||
private int mouseInGUI = 0;//0 = En dehors, 1 = entrer, 2 = deplacer
|
||||
|
||||
protected int x, y;
|
||||
protected int width,height;
|
||||
|
||||
protected IActionGUI action;
|
||||
|
||||
public GUI(int x,int y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.action = new ActionGUI();
|
||||
}
|
||||
|
||||
public void setAction(IActionGUI action){
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
float mouseX = Input.getMousePosition().x;
|
||||
float mouseY = Input.getMousePosition().y;
|
||||
float dMouseX = Input.getDMouse().x;
|
||||
float dMouseY = Input.getDMouse().y;
|
||||
if(mouseX >= this.x && mouseX <= this.x + this.width && mouseY >= this.y && mouseY <= this.y + this.height){
|
||||
for(int i = 0;i < Input.NBRE_BUTTON;i++){
|
||||
if(Input.isButton(i)){
|
||||
action.clicked(mouseX,mouseY,i,Input.getButtonState(i));
|
||||
}
|
||||
}
|
||||
if(mouseInGUI == 0){
|
||||
mouseInGUI = 1;
|
||||
action.enter(mouseX,mouseY);
|
||||
}else if(mouseInGUI == 1 || mouseInGUI == 2){
|
||||
mouseInGUI = 2;
|
||||
action.hover(mouseX,mouseY);
|
||||
if(dMouseX != 0 || dMouseY != 0)action.move(mouseX,mouseY);
|
||||
}
|
||||
}else{
|
||||
if(mouseInGUI == 1 || mouseInGUI == 2){
|
||||
mouseInGUI = 0;
|
||||
action.leave(mouseX,mouseY);
|
||||
}
|
||||
}
|
||||
for(int id : Input.getJoysticks()){
|
||||
try{
|
||||
FloatBuffer axis = Input.getJoysticksAxis(id);
|
||||
for(int i = 0;i < axis.capacity();i++){
|
||||
action.joystickAxisState(id, i, axis.get(i));
|
||||
}
|
||||
ByteBuffer buttons = Input.getJoysticksButton(id);
|
||||
for(int i = 0;i < buttons.capacity();i++){
|
||||
action.joystickButtonState(id, i, buttons.get(i));
|
||||
}
|
||||
}catch(Exception e){}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void render();
|
||||
public abstract void destroy();
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
}
|
228
src/main/java/globalgamejam/gui/GUILabel.java
Normal file
228
src/main/java/globalgamejam/gui/GUILabel.java
Normal file
|
@ -0,0 +1,228 @@
|
|||
package globalgamejam.gui;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Matrix4f;
|
||||
import globalgamejam.render.Camera;
|
||||
import globalgamejam.render.DisplayManager;
|
||||
import globalgamejam.render.Shaders;
|
||||
import globalgamejam.render.Texture;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
/**
|
||||
* usefull to print 2D text in openGL LWJGL application
|
||||
* @author Jean-Baptiste Pommeret (Fiesta)
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GUILabel extends GUI {
|
||||
|
||||
private Texture texture;
|
||||
private String text;
|
||||
private Color color;
|
||||
private int size;
|
||||
private String font;
|
||||
private int vbo,numberOfVertices;
|
||||
|
||||
/**
|
||||
* Full constructor of a Label
|
||||
* @param text (String) : the text to print
|
||||
* @param xC (float) : the x coordonnate of the frame where start printing the Label (upper left corner)
|
||||
* @param yC (float) : the y coordonnate of the frame where start printing the Label (upper left corner)
|
||||
* @param color (java.awt.Color) : the Color you wish for the text
|
||||
* @param font (String) : the font (i.e. "Arial" or "Times new roman")
|
||||
* @param size (int) : the font size
|
||||
*/
|
||||
public GUILabel(String text, int xC, int yC, Color color, String font, int size){
|
||||
super(xC,yC);
|
||||
this.font = font;
|
||||
this.color = color;
|
||||
this.text = text;
|
||||
this.size = size;
|
||||
if(this.texture != null)this.texture.destroy();
|
||||
this.texture = Texture.loadFont(text,color,font,size);
|
||||
super.width = this.texture.width;
|
||||
super.height = this.texture.height;
|
||||
this.vbo = GL15.glGenBuffers();
|
||||
float[] a = new float[]{
|
||||
0,0, 0.0f,0.0f,
|
||||
1,0, 1.0f,0.0f,
|
||||
1,1, 1.0f,1.0f,
|
||||
0,1, 0.0f,1.0f
|
||||
};
|
||||
FloatBuffer buff = BufferUtils.createFloatBuffer(a.length);
|
||||
buff.put(a).flip();
|
||||
this.numberOfVertices = a.length/(2+2);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public void render(){
|
||||
Shaders.MAIN_SHADERS.bind();
|
||||
Shaders.MAIN_SHADERS.uniform("camera", Camera.matrix);
|
||||
Matrix4f transform = new Matrix4f();
|
||||
transform.translate(super.x,super.y,0);
|
||||
transform.scale(this.getWitdh(),this.getHeight(),1);
|
||||
Shaders.MAIN_SHADERS.uniform("transform", transform);
|
||||
Shaders.MAIN_SHADERS.uniform("projection", DisplayManager.projection);
|
||||
Shaders.MAIN_SHADERS.uniform("color", Color4f.WHITE);
|
||||
|
||||
texture.bind();
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
|
||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vert"));
|
||||
GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vert"), 2, GL11.GL_FLOAT, false, (2+2)*4, 0);
|
||||
|
||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"));
|
||||
GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, (2+2)*4, 2*4);
|
||||
|
||||
GL11.glDrawArrays(GL11.GL_QUADS, 0, numberOfVertices);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
texture.unbind();
|
||||
Shaders.MAIN_SHADERS.unbind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor of a Label. Call the full constructor -> Label("", 100, 100, Color.white, "Arial", 30)
|
||||
*/
|
||||
public GUILabel(){
|
||||
this("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Label from the text param and default statement.
|
||||
* Call the full constructor -> Label(text, 100, 100, Color.white, "Arial", 30)
|
||||
* @param text (String) : the text to print
|
||||
*/
|
||||
public GUILabel(String text){
|
||||
this(text, 100, 100, Color.white, "Arial", 30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the actual Color of the Label
|
||||
* @return color (java.awt.Color) : the Color of the Label
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Color of the Label. Automaticaly update the Label to use the new Color
|
||||
* @param color (java.awt.Color) : the new Color of the Label
|
||||
*/
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
if(this.texture != null)this.texture.destroy();
|
||||
this.texture = Texture.loadFont(text,color,font,size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the text of the Label
|
||||
* @return text (String) : the text of the Label
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text of the Label. Automaticaly update the Label to use the new text
|
||||
* @param text (String) : the new text to display
|
||||
*/
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
if(this.texture != null)this.texture.destroy();
|
||||
this.texture = Texture.loadFont(text,color,font,size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the x coordonnate of the Label (upper left corner)
|
||||
* @return x (float) : the x coordonnate of the Label
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the x coordonnate of the Label (upper left corner)
|
||||
* @param x (float) : the new x coordonnate of the Label
|
||||
*/
|
||||
public void setX(int x) {
|
||||
super.setX(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the y coordonnate of the Label (upper left corner)
|
||||
* @return y (float) : the y coordonnate of the Label
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the y coordonnate of the Label (upper left corner)
|
||||
* @param y (float) : the new y coordonnate of the Label
|
||||
*/
|
||||
public void setY(int y) {
|
||||
super.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set both x and y coordonnate of the Label
|
||||
* @param x (float) : the new x coordonnate of the Label
|
||||
* @param y (float) : the new y coordonnate of the Label
|
||||
*/
|
||||
public void setPosition(int x, int y){
|
||||
this.setX(x);
|
||||
this.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the witdh of the Label
|
||||
* @return witdh (int) : the width
|
||||
*/
|
||||
public int getWitdh() {
|
||||
return this.texture.width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of the Label
|
||||
* @return height (int) : the height
|
||||
*/
|
||||
public int getHeight() {
|
||||
return this.texture.height;
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
GL15.glDeleteBuffers(vbo);
|
||||
texture.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* make the image transparent
|
||||
* @param obj_img (BufferedImage) : the BufferedImage to make transparent
|
||||
*/
|
||||
/* private void makeTransparent(BufferedImage obj_img){
|
||||
byte alpha = (byte)255;
|
||||
alpha %= 0xff;
|
||||
for (int cx=0;cx<obj_img.getWidth();cx++) {
|
||||
for (int cy=0;cy<obj_img.getHeight();cy++) {
|
||||
int color = obj_img.getRGB(cx, cy);
|
||||
|
||||
int mc = (alpha << 24) | 0x00ffffff;
|
||||
int newcolor = color & mc;
|
||||
obj_img.setRGB(cx, cy, newcolor);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
14
src/main/java/globalgamejam/gui/IActionGUI.java
Normal file
14
src/main/java/globalgamejam/gui/IActionGUI.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package globalgamejam.gui;
|
||||
|
||||
/**
|
||||
* Created by trexr on 20/01/2017.
|
||||
*/
|
||||
public interface IActionGUI {
|
||||
public void enter(float mouseX,float mouseY);
|
||||
public void leave(float mouseX,float mouseY);
|
||||
public void move(float mouseX,float mouseY);
|
||||
public void hover(float mouseX,float mouseY);
|
||||
public void clicked(float mouseX,float mouseY,int buttonKey,int buttonState);
|
||||
public void joystickButtonState(int idJoy,int id,int state);
|
||||
public void joystickAxisState(int idJoy,int id,float value);
|
||||
}
|
44
src/main/java/globalgamejam/input/IO.java
Normal file
44
src/main/java/globalgamejam/input/IO.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package globalgamejam.input;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import globalgamejam.game.HighScore;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class IO {
|
||||
|
||||
public static String loadFile(String path) throws Exception{
|
||||
String r = "";
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
|
||||
String buffer = "";
|
||||
while ((buffer = reader.readLine()) != null) {
|
||||
r += buffer + "\n";
|
||||
}
|
||||
reader.close();
|
||||
return r;
|
||||
}
|
||||
|
||||
public static HighScore loadHighScore(String path) throws Exception{
|
||||
FileInputStream fin = new FileInputStream(path);
|
||||
ObjectInputStream ois = new ObjectInputStream(fin);
|
||||
return (HighScore) ois.readObject();
|
||||
}
|
||||
|
||||
public static void writeHighScore(String path,HighScore highscore) {
|
||||
try (ObjectOutputStream oos =
|
||||
new ObjectOutputStream(new FileOutputStream(path))) {
|
||||
oos.writeObject(highscore);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
286
src/main/java/globalgamejam/input/Input.java
Normal file
286
src/main/java/globalgamejam/input/Input.java
Normal file
|
@ -0,0 +1,286 @@
|
|||
package globalgamejam.input;
|
||||
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.lwjgl.glfw.GLFWCursorPosCallback;
|
||||
import org.lwjgl.glfw.GLFWJoystickCallback;
|
||||
import org.lwjgl.glfw.GLFWScrollCallback;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.math.Vector2f;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Input{
|
||||
|
||||
public static GLFWScrollCallback scroll;
|
||||
public static GLFWCursorPosCallback mousePos;
|
||||
public static GLFWJoystickCallback joyCall;
|
||||
|
||||
private static ArrayList<Integer> joysticks = new ArrayList<Integer>();
|
||||
|
||||
private static Vector2f mousePosition = new Vector2f();
|
||||
private static Vector2f dMouse = new Vector2f();
|
||||
private static Vector2f previousDMouse = new Vector2f();
|
||||
|
||||
public static final int NONE = 0,PRESSED = 1,RELEASED = 2,REPEATED = 3,UP = 4,DOWN = 5,
|
||||
NBRE_KEY = 0x15D,NBRE_BUTTON = 10,
|
||||
MOUSE_OFFSET = NBRE_KEY + 1,MOUSE_WHEEL_OFFSET = MOUSE_OFFSET + 1,
|
||||
NBRE_MAX_JOYSTICK = 16;
|
||||
|
||||
private static HashMap<Integer,Integer> state = new HashMap<Integer,Integer>();
|
||||
|
||||
private static double ywheel = 0;
|
||||
|
||||
public static void init(){
|
||||
for(int i = 0;i < NBRE_MAX_JOYSTICK;i++){
|
||||
if(glfwJoystickPresent(GLFW_JOYSTICK_1 + i))joysticks.add(GLFW_JOYSTICK_1 + i);
|
||||
}
|
||||
glfwSetJoystickCallback(joyCall = new GLFWJoystickCallback() {
|
||||
|
||||
@Override
|
||||
public void invoke(int id, int event) {
|
||||
if (event == GLFW_CONNECTED)
|
||||
{
|
||||
joysticks.add(id);
|
||||
System.out.println(glfwGetJoystickName(id) + " connecter");
|
||||
}
|
||||
else if (event == GLFW_DISCONNECTED)
|
||||
{
|
||||
joysticks.remove(id);
|
||||
System.out.println("Manettes #" + id + " deconnecter");
|
||||
}
|
||||
}
|
||||
});
|
||||
glfwSetScrollCallback(Main.windowID, scroll = new GLFWScrollCallback() {
|
||||
public void invoke(long window, double xoffset, double yoffset) {
|
||||
scroll(window, xoffset, yoffset);
|
||||
}
|
||||
});
|
||||
glfwSetCursorPosCallback(Main.windowID, mousePos = new GLFWCursorPosCallback() {
|
||||
public void invoke(long window, double xpos, double ypos) {
|
||||
mousepos(window, xpos, ypos);
|
||||
}
|
||||
});
|
||||
for(int i = 0;i < NBRE_KEY;i++){
|
||||
state.put(i, NONE);
|
||||
}
|
||||
for(int i = 0;i < NBRE_BUTTON;i++){
|
||||
state.put(i + MOUSE_OFFSET, NONE);
|
||||
}
|
||||
state.put(MOUSE_WHEEL_OFFSET, NONE);
|
||||
}
|
||||
|
||||
public static void update(){
|
||||
for(Entry<Integer, Integer> set : state.entrySet()){
|
||||
int i = set.getKey();
|
||||
int st = set.getValue();
|
||||
if(i > -1 && i < NBRE_KEY){
|
||||
if(glfwGetKey(Main.windowID, i) == 0 && st == NONE)continue;
|
||||
if(glfwGetKey(Main.windowID, i) == 1 && st == NONE){
|
||||
state.replace(i, PRESSED);
|
||||
}else if(glfwGetKey(Main.windowID, i) == 1 && st == PRESSED){
|
||||
state.replace(i, REPEATED);
|
||||
}else if(glfwGetKey(Main.windowID, i) == 0 && (st == PRESSED || st == REPEATED)){
|
||||
state.replace(i, RELEASED);
|
||||
}else if(glfwGetKey(Main.windowID, i) == 0 && st == RELEASED){
|
||||
state.replace(i, NONE);
|
||||
}
|
||||
}else if(i >= MOUSE_OFFSET && i < MOUSE_OFFSET + NBRE_BUTTON){
|
||||
if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && st == NONE)continue;
|
||||
if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 1 && st == NONE){
|
||||
state.replace(i, PRESSED);
|
||||
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 1 && st == PRESSED){
|
||||
state.replace(i, REPEATED);
|
||||
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && (st == PRESSED || st == REPEATED)){
|
||||
state.replace(i, RELEASED);
|
||||
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && st == RELEASED){
|
||||
state.replace(i, NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
int st = state.get(MOUSE_WHEEL_OFFSET);
|
||||
if(ywheel > 0 && (st == NONE || st == UP)){
|
||||
state.replace(MOUSE_WHEEL_OFFSET, UP);
|
||||
}else if(ywheel < 0 && (st == NONE || st == DOWN)){
|
||||
state.replace(MOUSE_WHEEL_OFFSET, DOWN);
|
||||
}else if(ywheel == 0 && (st == DOWN || st == UP)){
|
||||
state.replace(MOUSE_WHEEL_OFFSET, NONE);
|
||||
}
|
||||
ywheel = 0;
|
||||
if(dMouse.equals(previousDMouse)){
|
||||
dMouse = new Vector2f();
|
||||
}else{
|
||||
previousDMouse = dMouse;
|
||||
}
|
||||
}
|
||||
|
||||
public static void destroy(){
|
||||
mousePos.free();
|
||||
scroll.free();
|
||||
}
|
||||
|
||||
public static void scroll(long window, double xoffset, double yoffset) {
|
||||
ywheel = yoffset;
|
||||
}
|
||||
|
||||
public static void mousepos(long window, double xpos, double ypos) {
|
||||
dMouse.x = (float) (xpos - mousePosition.x);
|
||||
dMouse.y = (float) (ypos - mousePosition.y);
|
||||
mousePosition.x = (float) xpos;
|
||||
mousePosition.y = (float) ypos;
|
||||
}
|
||||
|
||||
public static boolean isButtonDown(int button){
|
||||
return state.get(button + MOUSE_OFFSET) == PRESSED;
|
||||
}
|
||||
|
||||
public static boolean isButtonUp(int button){
|
||||
return state.get(button + MOUSE_OFFSET) == RELEASED;
|
||||
}
|
||||
|
||||
public static boolean isButton(int button){
|
||||
return state.get(button + MOUSE_OFFSET) == PRESSED || state.get(button + MOUSE_OFFSET) == REPEATED;
|
||||
}
|
||||
|
||||
public static int getButtonState(int button){
|
||||
return state.get(button + MOUSE_OFFSET);
|
||||
}
|
||||
|
||||
public static boolean isKeyDown(int key){
|
||||
return state.get(key) == PRESSED;
|
||||
}
|
||||
|
||||
public static boolean isKeyUp(int key){
|
||||
return state.get(key) == RELEASED;
|
||||
}
|
||||
|
||||
public static boolean isKey(int key){
|
||||
return state.get(key) == PRESSED || state.get(key) == REPEATED;
|
||||
}
|
||||
|
||||
public static int getKeyState(int key){
|
||||
return state.get(key);
|
||||
}
|
||||
|
||||
public static int isMouseWheelState(){
|
||||
return state.get(MOUSE_WHEEL_OFFSET);
|
||||
}
|
||||
|
||||
public static boolean isMouseWheelUp(){
|
||||
return state.get(MOUSE_WHEEL_OFFSET) == UP;
|
||||
}
|
||||
|
||||
public static boolean isMouseWheelDown(){
|
||||
return state.get(MOUSE_WHEEL_OFFSET) == DOWN;
|
||||
}
|
||||
|
||||
public static GLFWScrollCallback getScroll() {
|
||||
return scroll;
|
||||
}
|
||||
|
||||
public static void setScroll(GLFWScrollCallback scroll) {
|
||||
Input.scroll = scroll;
|
||||
}
|
||||
|
||||
public static GLFWCursorPosCallback getMousePos() {
|
||||
return mousePos;
|
||||
}
|
||||
|
||||
public static void setMousePos(GLFWCursorPosCallback mousePos) {
|
||||
Input.mousePos = mousePos;
|
||||
}
|
||||
|
||||
public static Vector2f getMousePosition() {
|
||||
return mousePosition;
|
||||
}
|
||||
|
||||
public static void setMousePosition(Vector2f mousePosition) {
|
||||
Input.mousePosition = mousePosition;
|
||||
}
|
||||
|
||||
public static Vector2f getDMouse() {
|
||||
return dMouse;
|
||||
}
|
||||
|
||||
public static void setDMouse(Vector2f dMouse) {
|
||||
Input.dMouse = dMouse;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Integer> getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public static void setState(HashMap<Integer, Integer> state) {
|
||||
Input.state = state;
|
||||
}
|
||||
|
||||
public static double getYwheel() {
|
||||
return ywheel;
|
||||
}
|
||||
|
||||
public static void setYwheel(double ywheel) {
|
||||
Input.ywheel = ywheel;
|
||||
}
|
||||
|
||||
public static int getNone() {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public static int getPressed() {
|
||||
return PRESSED;
|
||||
}
|
||||
|
||||
public static int getReleased() {
|
||||
return RELEASED;
|
||||
}
|
||||
|
||||
public static int getRepeated() {
|
||||
return REPEATED;
|
||||
}
|
||||
|
||||
public static int getUp() {
|
||||
return UP;
|
||||
}
|
||||
|
||||
public static int getDown() {
|
||||
return DOWN;
|
||||
}
|
||||
|
||||
public static int getNbreKey() {
|
||||
return NBRE_KEY;
|
||||
}
|
||||
|
||||
public static int getNbreButton() {
|
||||
return NBRE_BUTTON;
|
||||
}
|
||||
|
||||
public static int getMouseOffset() {
|
||||
return MOUSE_OFFSET;
|
||||
}
|
||||
|
||||
public static int getMouseWheelOffset() {
|
||||
return MOUSE_WHEEL_OFFSET;
|
||||
}
|
||||
|
||||
public static FloatBuffer getJoysticksAxis(int i){
|
||||
return glfwGetJoystickAxes(joysticks.get(i));
|
||||
}
|
||||
|
||||
public static ByteBuffer getJoysticksButton(int i){
|
||||
return glfwGetJoystickButtons(joysticks.get(i));
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getJoysticks() {
|
||||
return joysticks;
|
||||
}
|
||||
|
||||
}
|
286
src/main/java/globalgamejam/interfaces/MainInterfaces.java
Normal file
286
src/main/java/globalgamejam/interfaces/MainInterfaces.java
Normal file
|
@ -0,0 +1,286 @@
|
|||
package globalgamejam.interfaces;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.game.MainGame;
|
||||
import globalgamejam.gui.ActionGUI;
|
||||
import globalgamejam.gui.GUI;
|
||||
import globalgamejam.gui.GUILabel;
|
||||
import globalgamejam.input.Input;
|
||||
|
||||
/**
|
||||
* Created by trexr on 20/01/2017.
|
||||
*/
|
||||
public class MainInterfaces {
|
||||
|
||||
private MainGame game;
|
||||
|
||||
private ArrayList<GUI> guis;
|
||||
private GUILabel p1,p2,timer;
|
||||
|
||||
private ArrayList<GUI> guisHelp;
|
||||
private GUILabel helpLabel;
|
||||
private GUILabel joueur1Help;
|
||||
private GUILabel joueur1HelpRotationG;
|
||||
private GUILabel joueur1HelpRotationD;
|
||||
private GUILabel joueur1HelpDeplacementVerticaleH;
|
||||
private GUILabel joueur1HelpDeplacementVerticaleB;
|
||||
private GUILabel joueur1HelpDeplacementHorizontaleG;
|
||||
private GUILabel joueur1HelpDeplacementHorizontaleD;
|
||||
private GUILabel joueur2Help;
|
||||
private GUILabel joueur2HelpRotationG;
|
||||
private GUILabel joueur2HelpRotationD;
|
||||
private GUILabel joueur2HelpDeplacementVerticaleH;
|
||||
private GUILabel joueur2HelpDeplacementVerticaleB;
|
||||
private GUILabel joueur2HelpDeplacementHorizontaleG;
|
||||
private GUILabel joueur2HelpDeplacementHorizontaleD;
|
||||
private GUILabel manetteHelp;
|
||||
private GUILabel manetteHelpDirection;
|
||||
private GUILabel manetteHelpRotation;
|
||||
|
||||
private ArrayList<GUI> guisPartieTerminer;
|
||||
private GUILabel labelPartieTerminer;
|
||||
private GUILabel recommencerPartie;
|
||||
private GUILabel quitter;
|
||||
private GUILabel[] highScoresLabel;
|
||||
|
||||
|
||||
public MainInterfaces(MainGame game){
|
||||
this.game = game;
|
||||
guis = new ArrayList<GUI>();
|
||||
guisHelp = new ArrayList<GUI>();
|
||||
guisPartieTerminer = new ArrayList<GUI>();
|
||||
init();
|
||||
}
|
||||
|
||||
public void init(){
|
||||
p1 = new GUILabel("Player 1 : ", Main.WIDTH/4,10, Color.RED,"Arial",16);
|
||||
p2 = new GUILabel("Player 2 : ", Main.WIDTH/4 * 3,10, Color.BLUE,"Arial",16);
|
||||
timer = new GUILabel(" ", Main.WIDTH/4 * 2,10, Color.BLACK,"Arial",16);
|
||||
guis.add(p1);
|
||||
guis.add(p2);
|
||||
guis.add(timer);
|
||||
|
||||
//Menu Help
|
||||
helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",64);
|
||||
helpLabel.setX(Main.WIDTH/2 - helpLabel.getWitdh()/2);
|
||||
guisHelp.add(helpLabel);
|
||||
//Joueur 1
|
||||
joueur1Help = new GUILabel("JOUEUR 1",Main.WIDTH/4,100,Color.WHITE,"Arial",32);
|
||||
joueur1Help.setX(Main.WIDTH/4 - joueur1Help.getWitdh()/2);
|
||||
joueur1HelpRotationG = new GUILabel("A = rotation a gauche",Main.WIDTH/4,140,Color.WHITE,"Arial",16);
|
||||
joueur1HelpRotationG.setX(Main.WIDTH/4 - joueur1HelpRotationG.getWitdh()/2);
|
||||
joueur1HelpRotationD = new GUILabel("E = rotation a droite",Main.WIDTH/4,160,Color.WHITE,"Arial",16);
|
||||
joueur1HelpRotationD.setX(Main.WIDTH/4 - joueur1HelpRotationD.getWitdh()/2);
|
||||
joueur1HelpDeplacementVerticaleH = new GUILabel("Z = Haut",Main.WIDTH/4,180,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementVerticaleH.setX(Main.WIDTH/4 - joueur1HelpDeplacementVerticaleH.getWitdh()/2);
|
||||
joueur1HelpDeplacementVerticaleB = new GUILabel("S = Bas",Main.WIDTH/4,200,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementVerticaleB.setX(Main.WIDTH/4 - joueur1HelpDeplacementVerticaleB.getWitdh()/2);
|
||||
joueur1HelpDeplacementHorizontaleG = new GUILabel("A = Gauche",Main.WIDTH/4,220,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementHorizontaleG.setX(Main.WIDTH/4 - joueur1HelpDeplacementHorizontaleG.getWitdh()/2);
|
||||
joueur1HelpDeplacementHorizontaleD = new GUILabel("D = Droite",Main.WIDTH/4,240,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementHorizontaleD.setX(Main.WIDTH/4 - joueur1HelpDeplacementHorizontaleD.getWitdh()/2);
|
||||
guisHelp.add(joueur1Help);
|
||||
guisHelp.add(joueur1HelpRotationG);
|
||||
guisHelp.add(joueur1HelpRotationD);
|
||||
guisHelp.add(joueur1HelpDeplacementVerticaleH);
|
||||
guisHelp.add(joueur1HelpDeplacementVerticaleB);
|
||||
guisHelp.add(joueur1HelpDeplacementHorizontaleG);
|
||||
guisHelp.add(joueur1HelpDeplacementHorizontaleD);
|
||||
//Joueur 2
|
||||
joueur2Help = new GUILabel("JOUEUR 2",Main.WIDTH/4,100,Color.WHITE,"Arial",32);
|
||||
joueur2Help.setX(Main.WIDTH/4 * 3 - joueur2Help.getWitdh()/2);
|
||||
joueur2HelpRotationG = new GUILabel("U = rotation a gauche",Main.WIDTH/4,140,Color.WHITE,"Arial",16);
|
||||
joueur2HelpRotationG.setX(Main.WIDTH/4 * 3 - joueur1HelpRotationG.getWitdh()/2);
|
||||
joueur2HelpRotationD = new GUILabel("O = rotation a droite",Main.WIDTH/4,160,Color.WHITE,"Arial",16);
|
||||
joueur2HelpRotationD.setX(Main.WIDTH/4 * 3 - joueur1HelpRotationD.getWitdh()/2);
|
||||
joueur2HelpDeplacementVerticaleH = new GUILabel("I = Haut",Main.WIDTH/4,180,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementVerticaleH.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementVerticaleH.getWitdh()/2);
|
||||
joueur2HelpDeplacementVerticaleB = new GUILabel("K = Bas",Main.WIDTH/4,200,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementVerticaleB.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementVerticaleB.getWitdh()/2);
|
||||
joueur2HelpDeplacementHorizontaleG = new GUILabel("J = Gauche",Main.WIDTH/4,220,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementHorizontaleG.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementHorizontaleG.getWitdh()/2);
|
||||
joueur2HelpDeplacementHorizontaleD = new GUILabel("L = Droite",Main.WIDTH/4,240,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementHorizontaleD.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementHorizontaleD.getWitdh()/2);
|
||||
guisHelp.add(joueur2Help);
|
||||
guisHelp.add(joueur2HelpRotationG);
|
||||
guisHelp.add(joueur2HelpRotationD);
|
||||
guisHelp.add(joueur2HelpDeplacementVerticaleH);
|
||||
guisHelp.add(joueur2HelpDeplacementVerticaleB);
|
||||
guisHelp.add(joueur2HelpDeplacementHorizontaleG);
|
||||
guisHelp.add(joueur2HelpDeplacementHorizontaleD);
|
||||
//Manette
|
||||
manetteHelp = new GUILabel("Manettes",Main.WIDTH/2,270,Color.WHITE,"Arial",32);
|
||||
manetteHelp.setX(Main.WIDTH/2 - manetteHelp.getWitdh()/2);
|
||||
manetteHelpDirection = new GUILabel("Stick Gauche = Direction",Main.WIDTH/2,310,Color.WHITE,"Arial",16);
|
||||
manetteHelpDirection.setX(Main.WIDTH/2 - manetteHelpDirection.getWitdh()/2);
|
||||
manetteHelpRotation = new GUILabel("Stick Droit = Rotation",Main.WIDTH/2,330,Color.WHITE,"Arial",16);
|
||||
manetteHelpRotation.setX(Main.WIDTH/2 - manetteHelpRotation.getWitdh()/2);
|
||||
guisHelp.add(manetteHelp);
|
||||
guisHelp.add(manetteHelpDirection);
|
||||
guisHelp.add(manetteHelpRotation);
|
||||
|
||||
//Menu Partie Terminer
|
||||
labelPartieTerminer = new GUILabel("PARTIE TERMINER",Main.WIDTH/2,10,Color.WHITE,"Arial",32);
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
|
||||
recommencerPartie = new GUILabel("RECOMMENCER (A)",Main.WIDTH/2,100,Color.WHITE,"Arial",16);
|
||||
recommencerPartie.setX(Main.WIDTH/2 - recommencerPartie.getWitdh()/2);
|
||||
recommencerPartie.setAction(new ActionGUI(){
|
||||
@Override
|
||||
public void enter(float mouseX,float mouseY){
|
||||
recommencerPartie.setColor(new Color(1, 1, 1, 0.5f));
|
||||
}
|
||||
@Override
|
||||
public void leave(float mouseX,float mouseY){
|
||||
recommencerPartie.setColor(Color.WHITE);
|
||||
}
|
||||
@Override
|
||||
public void clicked(float mouseX,float mouseY,int buttonKey,int buttonState){
|
||||
game.reset();
|
||||
}
|
||||
@Override
|
||||
public void joystickButtonState(int idJoy,int id,int state){
|
||||
if(idJoy == GLFW.GLFW_JOYSTICK_1){
|
||||
if(state == 1 && id == 0){
|
||||
game.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
quitter = new GUILabel("QUITTER (B)", Main.WIDTH/2, 120, Color.WHITE, "Arial", 16);
|
||||
quitter.setX(Main.WIDTH/2 - quitter.getWitdh()/2);
|
||||
quitter.setAction(new ActionGUI(){
|
||||
@Override
|
||||
public void enter(float mouseX,float mouseY){
|
||||
quitter.setColor(new Color(1, 1, 1, 0.5f));
|
||||
}
|
||||
@Override
|
||||
public void leave(float mouseX,float mouseY){
|
||||
quitter.setColor(Color.WHITE);
|
||||
}
|
||||
@Override
|
||||
public void clicked(float mouseX,float mouseY,int buttonKey,int buttonState){
|
||||
Main.isDestroy = true;
|
||||
}
|
||||
@Override
|
||||
public void joystickButtonState(int idJoy,int id,int state){
|
||||
if(idJoy == GLFW.GLFW_JOYSTICK_1){
|
||||
if(state == 1 && id == 1){
|
||||
Main.isDestroy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
highScoresLabel = new GUILabel[10];
|
||||
for(int i = 0;i<10;i++){
|
||||
highScoresLabel[i] = new GUILabel(this.game.highScore.getTopScores()[i] + "",Main.WIDTH/2,150 + 20 * i,Color.WHITE,"Arial",16);
|
||||
highScoresLabel[i].setX(Main.WIDTH/2 - highScoresLabel[i].getWitdh()/2);
|
||||
guisPartieTerminer.add(highScoresLabel[i]);
|
||||
}
|
||||
guisPartieTerminer.add(labelPartieTerminer);
|
||||
guisPartieTerminer.add(recommencerPartie);
|
||||
guisPartieTerminer.add(quitter);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
boolean joysticksHelp = false;
|
||||
if(Input.getJoysticks().size() > 0){
|
||||
try{
|
||||
ByteBuffer b = Input.getJoysticksButton(0);
|
||||
if(b.get(3) == 1)joysticksHelp = true;
|
||||
}catch(Exception e){}
|
||||
}
|
||||
if(Input.isKey(this.game.HELP_KEY) || joysticksHelp){
|
||||
for(GUI g : guisHelp)g.update();
|
||||
}else if(this.game.scores[0] <= 0 || this.game.scores[1] <= 0 || MainGame.time_in_sec <= 0){
|
||||
int score = 0;
|
||||
if(!this.game.isEnd){
|
||||
if(this.game.scores[1]<this.game.scores[0]){
|
||||
this.game.highScore.put((int)this.game.scores[0]);
|
||||
score = (int)this.game.scores[0];
|
||||
}else{
|
||||
this.game.highScore.put((int)this.game.scores[1]);
|
||||
score = (int)this.game.scores[1];
|
||||
}
|
||||
this.game.saveHighScore();
|
||||
game.audioBackground.pauseSound();
|
||||
if(game.audioEffect != null){
|
||||
game.audioEffect.pauseSound();
|
||||
}
|
||||
}
|
||||
for(int i = 0;i<10;i++){
|
||||
highScoresLabel[i].setText(this.game.highScore.getTopScores()[i] + "");
|
||||
highScoresLabel[i].setX(Main.WIDTH/2 - highScoresLabel[i].getWitdh()/2);
|
||||
if(this.game.highScore.getTopScores()[i] == score){
|
||||
highScoresLabel[i].setColor(Color.RED);
|
||||
}else{
|
||||
highScoresLabel[i].setColor(Color.WHITE);
|
||||
}
|
||||
}
|
||||
for(GUI g : guisPartieTerminer)g.update();
|
||||
}else{
|
||||
p1.setText("Player 1 : " + (int)this.game.scores[0]);
|
||||
p1.setX((Main.WIDTH)/4 - p1.getWitdh()/2);
|
||||
p2.setText("Player 2 : " + (int)this.game.scores[1]);
|
||||
p2.setX((Main.WIDTH)/4*3 - p2.getWitdh()/2);
|
||||
int sec = (int)MainGame.time_in_sec;
|
||||
int min = sec/60;
|
||||
sec -= min * 60;
|
||||
timer.setText(min + ":" + sec);
|
||||
timer.setX((Main.WIDTH)/4*2 - timer.getWitdh()/2);
|
||||
MainGame.time_in_sec -= Main.delta;
|
||||
for(GUI g : guis)g.update();
|
||||
}
|
||||
}
|
||||
|
||||
public void render(){
|
||||
boolean joysticksHelp = false;
|
||||
if(Input.getJoysticks().size() > 0){
|
||||
try{
|
||||
ByteBuffer b = Input.getJoysticksButton(0);
|
||||
if(b.get(3) == 1)joysticksHelp = true;
|
||||
}catch(Exception e){}
|
||||
}
|
||||
if(Input.isKey(this.game.HELP_KEY) || joysticksHelp){
|
||||
for(GUI g : guisHelp)g.render();
|
||||
}else if(this.game.scores[0] <= 0 || this.game.scores[1] <= 0){
|
||||
if(this.game.scores[0] <= 0){
|
||||
labelPartieTerminer.setText("PARTIE TERMINER (GAGNANT : JOUEUR 2)");
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}else{
|
||||
labelPartieTerminer.setText("PARTIE TERMINER (GAGNANT : JOUEUR 1)");
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}
|
||||
for(GUI g : guisPartieTerminer)g.render();
|
||||
}else if(MainGame.time_in_sec <= 0){
|
||||
if(this.game.scores[0] < this.game.scores[1]){
|
||||
labelPartieTerminer.setText("PARTIE TERMINER (GAGNANT : JOUEUR 2)");
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}else{
|
||||
labelPartieTerminer.setText("PARTIE TERMINER (GAGNANT : JOUEUR 1)");
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}
|
||||
for(GUI g : guisPartieTerminer)g.render();
|
||||
}else{
|
||||
for(GUI g : guis)g.render();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
for(GUI g : guis)g.destroy();
|
||||
guis.clear();
|
||||
for(GUI g : guisHelp)g.destroy();
|
||||
guisHelp.clear();
|
||||
for(GUI g : guisPartieTerminer)g.destroy();
|
||||
guisPartieTerminer.clear();
|
||||
}
|
||||
|
||||
}
|
113
src/main/java/globalgamejam/math/Color4f.java
Normal file
113
src/main/java/globalgamejam/math/Color4f.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Color4f {
|
||||
|
||||
public static final Color4f
|
||||
RED = new Color4f(1,0,0,1),
|
||||
BLUE = new Color4f(0,0,1,1),
|
||||
GREEN = new Color4f(0,1,0,1),
|
||||
YELLOW = new Color4f(1,1,0,1),
|
||||
PURPLE = new Color4f(1,0,1,1),
|
||||
CYAN = new Color4f(0,1,1,1),
|
||||
BLACK = new Color4f(0,0,0,1),
|
||||
WHITE = new Color4f(1,1,1,1);
|
||||
|
||||
public float r,g,b,a;
|
||||
|
||||
public Color4f(float r,float g,float b,float a){
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public static Color4f mul (Color4f a, float b){
|
||||
return new Color4f(a.r * b,a.g * b,a.b * b,a.a * b);
|
||||
}
|
||||
|
||||
public static Color4f mul (float o,Color4f... a){
|
||||
float r = 0;
|
||||
float b = 0;
|
||||
float g = 0;
|
||||
float al = 0;
|
||||
for(Color4f c : a){
|
||||
r += c.r;
|
||||
g += c.g;
|
||||
b += c.b;
|
||||
al += c.a;
|
||||
}
|
||||
r /= a.length;
|
||||
g /= a.length;
|
||||
b /= a.length;
|
||||
al /= a.length;
|
||||
return new Color4f(r * o,g * o,b * o,al * o);
|
||||
}
|
||||
|
||||
public static Color4f mul (Color4f... a){
|
||||
float r = 0;
|
||||
float b = 0;
|
||||
float g = 0;
|
||||
float al = 0;
|
||||
for(Color4f c : a){
|
||||
r += c.r;
|
||||
g += c.g;
|
||||
b += c.b;
|
||||
al += c.a;
|
||||
}
|
||||
r /= a.length;
|
||||
g /= a.length;
|
||||
b /= a.length;
|
||||
al /= a.length;
|
||||
return new Color4f(r,g,b,al);
|
||||
}
|
||||
|
||||
public Color4f() {
|
||||
}
|
||||
|
||||
public float getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public void setR(float r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public float getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(float g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
public float getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(float b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public float getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(float a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public void bind(){
|
||||
glColor4f(r,g,b,a);
|
||||
}
|
||||
|
||||
public void unbind(){
|
||||
BLACK.bind();
|
||||
}
|
||||
|
||||
}
|
70
src/main/java/globalgamejam/math/Mathf.java
Normal file
70
src/main/java/globalgamejam/math/Mathf.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Mathf {
|
||||
|
||||
public static final float PI = 3.14159265358979323846f;
|
||||
public static final float EPSILON = 1.401298e-45f;
|
||||
|
||||
public static float cos(float angle){
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
|
||||
public static float acos(float angle){
|
||||
return (float)Math.acos(angle);
|
||||
}
|
||||
|
||||
public static float sin(float angle){
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
public static float asin(float angle){
|
||||
return (float)Math.asin(angle);
|
||||
}
|
||||
|
||||
public static float toRadians(float angle){
|
||||
return (float)Math.toRadians(angle);
|
||||
}
|
||||
|
||||
public static float toDegrees(float angle){
|
||||
return (float)Math.toDegrees(angle);
|
||||
}
|
||||
|
||||
public static float atan2(float a,float b){
|
||||
return (float)Math.atan2(a,b);
|
||||
}
|
||||
|
||||
public static float cut(float nbre,float a){
|
||||
return (float)((int)(nbre*Math.pow(10, a))/Math.pow(10, a));
|
||||
}
|
||||
|
||||
public static boolean equals(float a,float b,float tolerance){
|
||||
return (a + tolerance >= b) && (a - tolerance <= b);
|
||||
}
|
||||
|
||||
public static float sqrt(float a){
|
||||
return (float)Math.sqrt(a);
|
||||
}
|
||||
|
||||
public static float exp(float a){
|
||||
return (float)Math.sqrt(a);
|
||||
}
|
||||
|
||||
public static float log(float a){
|
||||
return (float)Math.log(a);
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
if(value < min){
|
||||
value = min;
|
||||
}
|
||||
if(value > max){
|
||||
value = max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
192
src/main/java/globalgamejam/math/Matrix4f.java
Normal file
192
src/main/java/globalgamejam/math/Matrix4f.java
Normal file
|
@ -0,0 +1,192 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
|
||||
import java.nio.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Matrix4f {
|
||||
|
||||
public float[][] m = null;
|
||||
|
||||
public Matrix4f(){
|
||||
m = new float[][]{
|
||||
{1,0,0,0},
|
||||
{0,1,0,0},
|
||||
{0,0,1,0},
|
||||
{0,0,0,1}
|
||||
};
|
||||
}
|
||||
|
||||
public Matrix4f(float[][] m){
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public Matrix4f loadIdentity(){
|
||||
m = new float[][]{
|
||||
{1,0,0,0},
|
||||
{0,1,0,0},
|
||||
{0,0,1,0},
|
||||
{0,0,0,1}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix4f rotate(Quaternion q){
|
||||
Matrix4f rot = q.toMatrixRotation();
|
||||
m = mul(rot).getM();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void rotate(float x,float y,float z){
|
||||
x = Mathf.toRadians(x);
|
||||
y = Mathf.toRadians(y);
|
||||
z = Mathf.toRadians(z);
|
||||
Matrix4f rx = new Matrix4f(new float[][]{
|
||||
{1,0,0,0},
|
||||
{0,Mathf.cos(x),-Mathf.sin(x),0},
|
||||
{0,Mathf.sin(x),Mathf.cos(x),0},
|
||||
{0,0,0,1}
|
||||
});
|
||||
|
||||
Matrix4f ry = new Matrix4f(new float[][]{
|
||||
{Mathf.cos(y),0,Mathf.sin(y),0},
|
||||
{0,1,0,0},
|
||||
{-Mathf.sin(y),0,Mathf.cos(y),0},
|
||||
{0,0,0,1}
|
||||
});
|
||||
|
||||
Matrix4f rz = new Matrix4f(new float[][]{
|
||||
{Mathf.cos(z),-Mathf.sin(z),0,0},
|
||||
{Mathf.sin(z),Mathf.cos(z),0,0},
|
||||
{0,0,1,0},
|
||||
{0,0,0,1}
|
||||
});
|
||||
Matrix4f m1 = (rz.mul(ry.mul(rx)));
|
||||
m = mul(m1).getM();
|
||||
}
|
||||
|
||||
public static Matrix4f rotate(Vector3f forward, Vector3f up, Vector3f right)
|
||||
{
|
||||
Matrix4f mat = new Matrix4f(new float[][]{
|
||||
{right.getX(), right.getY(), right.getZ() ,0},
|
||||
{up.getX(), up.getY(), up.getZ() ,0},
|
||||
{forward.getX(),forward.getY(), forward.getZ() ,0},
|
||||
{0,0,0,1}
|
||||
});
|
||||
return mat;
|
||||
}
|
||||
|
||||
public Matrix4f translate(float x,float y,float z){
|
||||
Matrix4f mat = new Matrix4f(new float[][]{
|
||||
{1,0,0,x},
|
||||
{0,1,0,y},
|
||||
{0,0,1,z},
|
||||
{0,0,0,1}
|
||||
});
|
||||
m = mul(mat).getM();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix4f scale(float x,float y,float z){
|
||||
Matrix4f mat = new Matrix4f(new float[][]{
|
||||
{x,0,0,0},
|
||||
{0,y,0,0},
|
||||
{0,0,z,0},
|
||||
{0,0,0,1}
|
||||
});
|
||||
m = mul(mat).getM();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix4f mul(Matrix4f mat){
|
||||
Matrix4f ma = new Matrix4f();
|
||||
for(int i = 0;i < 4;i++){
|
||||
for(int j = 0;j < 4;j++){
|
||||
ma.m[i][j] = m[i][0] * mat.m[0][j] +
|
||||
m[i][1] * mat.m[1][j] +
|
||||
m[i][2] * mat.m[2][j] +
|
||||
m[i][3] * mat.m[3][j];
|
||||
}
|
||||
}
|
||||
return ma;
|
||||
}
|
||||
|
||||
public Matrix4f Ortho2D(float left, float right, float bottom, float top, float near, float far)
|
||||
{
|
||||
float width = right - left;
|
||||
float height = top - bottom;
|
||||
float depth = far - near;
|
||||
|
||||
m = new float[][]{
|
||||
{2/width,0,0,-(right + left)/width},
|
||||
{0,2/height,0,-(top + bottom)/height},
|
||||
{0,0,-2/depth,-(far + near)/depth},
|
||||
{0,0,0,1}
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix4f perspective(float fov, float aspectRatio, float zNear, float zFar)
|
||||
{
|
||||
float f = fov;
|
||||
fov = Mathf.toRadians(f);
|
||||
float tanHalfFOV = (float)Math.tan(fov / 2);
|
||||
float zRange = zNear - zFar;
|
||||
|
||||
m = new float[][]{
|
||||
{1.0f / (tanHalfFOV * aspectRatio),0,0,0},
|
||||
{0,1.0f / tanHalfFOV,0,0},
|
||||
{0,0,(-zNear -zFar)/zRange,2.0f * zFar * zNear / zRange},
|
||||
{0,0,1,0}
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FloatBuffer getBuffer(){
|
||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(4 * 4);
|
||||
for(int i = 0;i < 4;i++){
|
||||
buffer.put(m[i]);
|
||||
}
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
int size = 3;
|
||||
int max = 10;
|
||||
StringJoiner st = new StringJoiner("\n","--------Mat4-Begin--------\n","\n--------Mat4-End----------");
|
||||
for(int i = 0;i < 4;i++){
|
||||
StringJoiner st2 = new StringJoiner(" | ");
|
||||
for(int j = 0;j < 4;j++){
|
||||
String value = Mathf.cut(m[i][j], size) + "";
|
||||
for(int k = value.length();k < max;k++){
|
||||
value += " ";
|
||||
}
|
||||
st2.add(value);
|
||||
}
|
||||
st.add(st2.toString());
|
||||
}
|
||||
return st.toString();
|
||||
}
|
||||
|
||||
public float[][] getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(float[][] m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public Matrix4f copy(){
|
||||
return new Matrix4f(this.getM());
|
||||
}
|
||||
|
||||
}
|
134
src/main/java/globalgamejam/math/Quaternion.java
Normal file
134
src/main/java/globalgamejam/math/Quaternion.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Quaternion {
|
||||
|
||||
public float x,y,z,w;
|
||||
|
||||
public Quaternion(){
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
w = 0;
|
||||
}
|
||||
|
||||
public Quaternion(Vector3f axis,float angle){
|
||||
float sin = Mathf.sin(Mathf.toRadians(angle/2.0f));
|
||||
float cos = Mathf.cos(Mathf.toRadians(angle/2.0f));
|
||||
x = axis.getX() * sin;
|
||||
y = axis.getY() * sin;
|
||||
z = axis.getZ() * sin;
|
||||
w = cos;
|
||||
}
|
||||
|
||||
public Quaternion(Vector3f rot){
|
||||
this(rot.x,rot.y,rot.z);
|
||||
}
|
||||
|
||||
public Quaternion (float yaw, float roll, float pitch) {
|
||||
yaw = Mathf.toRadians(yaw);
|
||||
roll = Mathf.toRadians(roll);
|
||||
pitch = Mathf.toRadians(pitch);
|
||||
float angle;
|
||||
float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw;
|
||||
angle = pitch * 0.5f;
|
||||
sinPitch = Mathf.sin(angle);
|
||||
cosPitch = Mathf.cos(angle);
|
||||
angle = roll * 0.5f;
|
||||
sinRoll = Mathf.sin(angle);
|
||||
cosRoll = Mathf.cos(angle);
|
||||
angle = yaw * 0.5f;
|
||||
sinYaw = Mathf.sin(angle);
|
||||
cosYaw = Mathf.cos(angle);
|
||||
|
||||
// variables used to reduce multiplication calls.
|
||||
float cosRollXcosPitch = cosRoll * cosPitch;
|
||||
float sinRollXsinPitch = sinRoll * sinPitch;
|
||||
float cosRollXsinPitch = cosRoll * sinPitch;
|
||||
float sinRollXcosPitch = sinRoll * cosPitch;
|
||||
|
||||
w = (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw);
|
||||
x = (cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw);
|
||||
y = (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw);
|
||||
z = (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw);
|
||||
|
||||
normalize();
|
||||
}
|
||||
|
||||
public void normalize(){
|
||||
float n = (float)(1.0/Math.sqrt(norm()));
|
||||
x *= n;
|
||||
y *= n;
|
||||
z *= n;
|
||||
w *= n;
|
||||
}
|
||||
|
||||
public float norm(){
|
||||
return w * w + x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
public Quaternion Euler(Vector3f rot) {
|
||||
x = Mathf.toRadians(rot.x);
|
||||
y = Mathf.toRadians(rot.y);
|
||||
z = Mathf.toRadians(rot.z);
|
||||
float c1 = Mathf.cos(y/2);
|
||||
float s1 = Mathf.sin(y/2);
|
||||
float c2 = Mathf.cos(z/2);
|
||||
float s2 = Mathf.sin(z/2);
|
||||
float c3 = Mathf.cos(x/2);
|
||||
float s3 = Mathf.sin(x/2);
|
||||
float c1c2 = c1*c2;
|
||||
float s1s2 = s1*s2;
|
||||
this.w =c1c2*c3 - s1s2*s3;
|
||||
this.x =c1c2*s3 + s1s2*c3;
|
||||
this.y =s1*c2*c3 + c1*s2*s3;
|
||||
this.z =c1*s2*c3 - s1*c2*s3;
|
||||
return new Quaternion(x, y, z, w);
|
||||
}
|
||||
|
||||
public Vector3f toEulerAngles(){
|
||||
Vector3f euler = new Vector3f();
|
||||
|
||||
float sqw = w * w;
|
||||
float sqx = x * x;
|
||||
float sqy = y * y;
|
||||
float sqz = z * z;
|
||||
float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise
|
||||
// is correction factor
|
||||
float test = x * y + z * w;
|
||||
if (test > 0.499 * unit) { // singularity at north pole
|
||||
euler.y = 2 * Mathf.atan2(x, w);
|
||||
euler.z = Mathf.PI/2.0f;
|
||||
euler.x = 0;
|
||||
} else if (test < -0.499 * unit) { // singularity at south pole
|
||||
euler.y = -2 * Mathf.atan2(x, w);
|
||||
euler.z = -Mathf.PI/2.0f;
|
||||
euler.x = 0;
|
||||
} else {
|
||||
euler.y = Mathf.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // roll or heading
|
||||
euler.z = Mathf.asin(2 * test / unit); // pitch or attitude
|
||||
euler.x = Mathf.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // yaw or bank
|
||||
}
|
||||
return euler.toDegrees();
|
||||
}
|
||||
|
||||
public Quaternion(float axisX,float axisY,float axisZ,float angle){
|
||||
float sin = Mathf.sin(Mathf.toRadians(angle/2.0f));
|
||||
float cos = Mathf.cos(Mathf.toRadians(angle/2.0f));
|
||||
x = axisX * sin;
|
||||
y = axisY * sin;
|
||||
z = axisZ * sin;
|
||||
w = cos;
|
||||
}
|
||||
|
||||
public Matrix4f toMatrixRotation(){
|
||||
Vector3f forward = new Vector3f(2.0f * (x * z - w * y), 2.0f * (y * z + w * x), 1.0f - 2.0f * (x * x + y * y));
|
||||
Vector3f up = new Vector3f(2.0f * (x * y + w * z), 1.0f - 2.0f * (x * x + z * z), 2.0f * (y * z - w * x));
|
||||
Vector3f right = new Vector3f(1.0f - 2.0f * (y * y + z * z), 2.0f * (x * y - w * z), 2.0f * (x * z + w * y));
|
||||
|
||||
return Matrix4f.rotate(forward, up, right);
|
||||
}
|
||||
|
||||
}
|
45
src/main/java/globalgamejam/math/Vector2f.java
Normal file
45
src/main/java/globalgamejam/math/Vector2f.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Vector2f {
|
||||
|
||||
public float x,y;
|
||||
|
||||
public Vector2f(){
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
public Vector2f(float x,float y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
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 String toString(){
|
||||
StringJoiner st = new StringJoiner(",","vec2(",")");
|
||||
st.add("" + x);
|
||||
st.add("" + y);
|
||||
return st.toString();
|
||||
}
|
||||
}
|
110
src/main/java/globalgamejam/math/Vector3f.java
Normal file
110
src/main/java/globalgamejam/math/Vector3f.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Vector3f {
|
||||
|
||||
public float x,y,z;
|
||||
|
||||
public Vector3f(){
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
public Vector3f(float x,float y,float z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3f(Vector2f vec,float z){
|
||||
this(vec.x,vec.y,z);
|
||||
}
|
||||
public Vector3f(Vector2f vec){
|
||||
this(vec.x,vec.y,0);
|
||||
}
|
||||
|
||||
public Vector3f(Vector3f vec){
|
||||
this(vec.x,vec.y,vec.z);
|
||||
}
|
||||
|
||||
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 getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float length(){
|
||||
return Mathf.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
public Vector3f lookAt(Vector3f d){
|
||||
Vector3f rot = new Vector3f();
|
||||
float x1 = d.x - x;
|
||||
float y1 = d.y - y;
|
||||
float z1 = d.z - z;
|
||||
|
||||
return rot;
|
||||
}
|
||||
|
||||
public Vector3f normalize(){
|
||||
float length = length();
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3f mul(float m){
|
||||
x *= m;
|
||||
y *= m;
|
||||
z *= m;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
StringJoiner st = new StringJoiner(",","vec3(",")");
|
||||
st.add("" + x);
|
||||
st.add("" + y);
|
||||
st.add("" + z);
|
||||
return st.toString();
|
||||
}
|
||||
|
||||
public Vector3f toRadians() {
|
||||
x = Mathf.toRadians(x);
|
||||
y = Mathf.toRadians(y);
|
||||
z = Mathf.toRadians(z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3f toDegrees() {
|
||||
x = Mathf.toDegrees(x);
|
||||
y = Mathf.toDegrees(y);
|
||||
z = Mathf.toDegrees(z);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
59
src/main/java/globalgamejam/math/Vector4f.java
Normal file
59
src/main/java/globalgamejam/math/Vector4f.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package globalgamejam.math;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Vector4f {
|
||||
|
||||
public float x,y,z,w;
|
||||
|
||||
public Vector4f(float x,float y,float z,float w){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public Vector4f(Vector3f v,float w){
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
this.z = v.z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
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 getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
240
src/main/java/globalgamejam/physics/PhysicalEntity.java
Normal file
240
src/main/java/globalgamejam/physics/PhysicalEntity.java
Normal file
|
@ -0,0 +1,240 @@
|
|||
package globalgamejam.physics;
|
||||
|
||||
import globalgamejam.game.Mur;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jean-Baptiste
|
||||
*
|
||||
*/
|
||||
public class PhysicalEntity {
|
||||
|
||||
private final static float MAX_SPEED = 15f;
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
|
||||
private float sizeRadius;
|
||||
private float sizeX;
|
||||
private float sizeY;
|
||||
|
||||
private float xVelocity;
|
||||
private float yVelocity;
|
||||
private float speedFactor;
|
||||
|
||||
private float speed;
|
||||
|
||||
private float frictionFactor;
|
||||
|
||||
/* public PhysicalEntity(float x, float y, float sizeRadius, float speedFactor, float xVelocity, float yVelocity, float frictionFactor) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.sizeX = sizeRadius * 2;
|
||||
this.sizeY = sizeRadius * 2;
|
||||
this.sizeRadius = sizeRadius;
|
||||
this.xVelocity = xVelocity;
|
||||
this.yVelocity = yVelocity;
|
||||
this.frictionFactor = frictionFactor;
|
||||
this.speedFactor = speedFactor;
|
||||
this.speed = 0;
|
||||
}*/
|
||||
|
||||
public PhysicalEntity(float x, float y, float sizeX, float sizeY, float speedFactor, float xVelocity, float yVelocity, float frictionFactor) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
this.sizeRadius = sizeX / 2;
|
||||
this.xVelocity = xVelocity;
|
||||
this.yVelocity = yVelocity;
|
||||
this.frictionFactor = frictionFactor;
|
||||
this.speedFactor = speedFactor;
|
||||
this.speed = 0;
|
||||
}
|
||||
|
||||
public boolean collideWith(PhysicalEntity entity){
|
||||
if(entity == null){
|
||||
return false;
|
||||
}
|
||||
// if(this.sizeRadius == -1 || entity.sizeRadius == -1){
|
||||
return this.collideWithSquareHitBox(entity);
|
||||
/* }
|
||||
else{
|
||||
return this.collideWithRoundHitBox(entity);
|
||||
}*/
|
||||
}
|
||||
|
||||
public boolean collideWithSquareHitBox(PhysicalEntity entity){
|
||||
|
||||
// on teste une collision avec une hitbox carré
|
||||
return (this.x + this.sizeX / 2 >= entity.x - entity.sizeX / 2
|
||||
&& this.x - this.sizeX / 2 <= entity.x + entity.sizeX / 2
|
||||
&& this.y + this.sizeY / 2 >= entity.y - entity.sizeY / 2
|
||||
&& this.y - this.sizeY / 2 <= entity.y + entity.sizeY / 2);
|
||||
}
|
||||
|
||||
public boolean collideWithRoundHitBox(PhysicalEntity entity){
|
||||
|
||||
if(entity == null){
|
||||
return false;
|
||||
}
|
||||
float distX = Math.abs(this.x - entity.x);
|
||||
float distY = Math.abs(this.y - entity.y);
|
||||
|
||||
float dist = (float)Math.sqrt( distX * distX + distY * distY );
|
||||
|
||||
return dist <= this.sizeRadius + entity.sizeRadius;
|
||||
}
|
||||
|
||||
public void resolveCollideWith(PhysicalEntity entity){
|
||||
|
||||
if(entity instanceof Mur){
|
||||
|
||||
// on a touché le bas du Mur
|
||||
if(this.y <= entity.y - entity.sizeY / 2 && this.yVelocity > 0){
|
||||
this.yVelocity *= -1;
|
||||
}
|
||||
|
||||
// on a touché le haut du Mur
|
||||
if(this.y >= entity.y + entity.sizeY / 2 && this.yVelocity < 0){
|
||||
this.yVelocity *= -1;
|
||||
}
|
||||
|
||||
// on a touché le coté gauche du Mur
|
||||
if(this.x <= entity.x - entity.sizeX / 2 && this.xVelocity > 0){
|
||||
this.xVelocity *= -1;
|
||||
}
|
||||
|
||||
// on a touché le coté droit du Mur
|
||||
if(this.x >= entity.x + entity.sizeX / 2 && this.xVelocity < 0){
|
||||
this.xVelocity *= -1;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
float xVel = entity.getSpeed() * (this.getX() - entity.getX()) / this.getSizeRadius();
|
||||
float yVel = entity.getSpeed() * (this.getY() - entity.getY()) / this.getSizeRadius();
|
||||
|
||||
this.addVelocity(xVel, yVel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Déplace l'entity et actualise ça vélocité
|
||||
*/
|
||||
public void move(){
|
||||
this.x += this.xVelocity;
|
||||
this.y += this.yVelocity;
|
||||
|
||||
this.xVelocity *= 1 - this.frictionFactor;
|
||||
this.yVelocity *= 1 - this.frictionFactor;
|
||||
|
||||
if(this.xVelocity < 0.01 && this.xVelocity > -0.01){
|
||||
this.xVelocity = 0;
|
||||
}
|
||||
|
||||
if(this.yVelocity < 0.01 && this.yVelocity > -0.01){
|
||||
this.yVelocity = 0;
|
||||
}
|
||||
|
||||
this.speed = (float)Math.sqrt( this.xVelocity * this.xVelocity + this.yVelocity * this.yVelocity );
|
||||
|
||||
if(this.speed >= PhysicalEntity.MAX_SPEED){
|
||||
this.xVelocity = (this.xVelocity * PhysicalEntity.MAX_SPEED) / this.speed;
|
||||
this.yVelocity = (this.yVelocity * PhysicalEntity.MAX_SPEED) / this.speed;
|
||||
|
||||
this.speed = PhysicalEntity.MAX_SPEED;
|
||||
}
|
||||
|
||||
this.moveTile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setPosition(float x, float y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void addPosition(float x, float y){
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
}
|
||||
|
||||
public void setVelocity(float x, float y){
|
||||
this.xVelocity = x;
|
||||
this.yVelocity = y;
|
||||
}
|
||||
|
||||
public void addVelocity(float x, float y){
|
||||
this.xVelocity += x;
|
||||
this.yVelocity += y;
|
||||
}
|
||||
|
||||
protected void moveTile(){
|
||||
|
||||
}
|
||||
|
||||
public float getX(){
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public float getY(){
|
||||
return this.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the speed
|
||||
*/
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param speed the speed to set
|
||||
*/
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public float getSpeedFactor() {
|
||||
return speedFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sizeRadius
|
||||
*/
|
||||
public float getSizeRadius() {
|
||||
return (this.sizeX + this.sizeY) / 2;
|
||||
}
|
||||
/*
|
||||
public void setSizeRadius(float size){
|
||||
this.sizeRadius = size;
|
||||
this.sizeX = size;
|
||||
this.sizeY = size;
|
||||
}*/
|
||||
|
||||
public void setSizeXY(float sizeX, float sizeY){
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the xVelocity
|
||||
*/
|
||||
public float getxVelocity() {
|
||||
return xVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the yVelocity
|
||||
*/
|
||||
public float getyVelocity() {
|
||||
return yVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.x + " " + this.y;
|
||||
}
|
||||
}
|
32
src/main/java/globalgamejam/render/Camera.java
Normal file
32
src/main/java/globalgamejam/render/Camera.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package globalgamejam.render;
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import globalgamejam.*;
|
||||
import globalgamejam.input.*;
|
||||
import globalgamejam.math.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Camera {
|
||||
|
||||
public static Matrix4f matrix = new Matrix4f();
|
||||
public static float rotation = 0.0f;//rotation de la camera
|
||||
public static Vector2f pos = new Vector2f();
|
||||
|
||||
public static void init(){
|
||||
matrix = new Matrix4f();
|
||||
rotation = 0.0f;
|
||||
pos = new Vector2f();
|
||||
}
|
||||
|
||||
public static void transform(){
|
||||
matrix.loadIdentity();
|
||||
matrix.translate(-pos.x,-pos.y,0);
|
||||
matrix.rotate(new Quaternion(new Vector3f(0,0,1),rotation));
|
||||
}
|
||||
|
||||
}
|
47
src/main/java/globalgamejam/render/DisplayManager.java
Normal file
47
src/main/java/globalgamejam/render/DisplayManager.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package globalgamejam.render;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import globalgamejam.*;
|
||||
import globalgamejam.math.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class DisplayManager {
|
||||
|
||||
public static Matrix4f projection = new Matrix4f();
|
||||
|
||||
public static void clear(){
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
public static void preRender2D(){
|
||||
projection.loadIdentity();
|
||||
// projection.Ortho2D(-Main.WIDTH/2.0f, Main.WIDTH/2.0f, -Main.HEIGHT/2.0f, Main.HEIGHT/2.0f, -1, 1);
|
||||
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
//glDepthFunc(GL_LESS);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
public static void preRenderGUI(){
|
||||
projection.loadIdentity();
|
||||
//Permet de centrer la camera au centre de l'ecran
|
||||
projection.Ortho2D(0, Main.WIDTH, Main.HEIGHT, 0, -1, 1);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
//glDepthFunc(GL_LESS);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
public static void render2D(){
|
||||
Main.game.render2D();
|
||||
}
|
||||
|
||||
public static void renderGUI(){
|
||||
Main.game.renderGUI();
|
||||
}
|
||||
|
||||
}
|
107
src/main/java/globalgamejam/render/FrameBufferObject.java
Normal file
107
src/main/java/globalgamejam/render/FrameBufferObject.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package globalgamejam.render;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.math.Matrix4f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
/**
|
||||
* Created by MrDev023 on 14/01/2017.
|
||||
*/
|
||||
public class FrameBufferObject {
|
||||
|
||||
private int fbo,fboTexID,renderID,vbo,size;
|
||||
|
||||
public FrameBufferObject(){
|
||||
int width = Main.WIDTH;
|
||||
int height = Main.HEIGHT;
|
||||
this.fbo = glGenFramebuffers();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
//Creation de la texture qui va contenir la sortie RGB du shader
|
||||
int renderedTexture = glGenTextures();
|
||||
glBindTexture(GL_TEXTURE_2D, renderedTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
//Creation du tampon de profondeur
|
||||
int depthrenderbuffer = glGenRenderbuffers();
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
|
||||
|
||||
//Definir le render Texture
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, renderedTexture, 0);
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
throw new IllegalStateException("FBO not loaded !");
|
||||
fboTexID = renderedTexture;
|
||||
renderID = depthrenderbuffer;
|
||||
|
||||
|
||||
this.vbo = GL15.glGenBuffers();
|
||||
float[] a = new float[]{
|
||||
0,0, 0.0f,0.0f,
|
||||
1,0, 1.0f,0.0f,
|
||||
1,1, 1.0f,1.0f,
|
||||
0,1, 0.0f,1.0f
|
||||
};
|
||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(a.length);
|
||||
buffer.put(a).flip();
|
||||
size = a.length/(2+2);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
|
||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vert"));
|
||||
GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vert"), 2, GL11.GL_FLOAT, false, (2+2)*4, 0);
|
||||
|
||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"));
|
||||
GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, (2+2)*4, 2*4);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public void startRenderToFBO(){
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
IntBuffer drawBuffs = BufferUtils.createIntBuffer(1);
|
||||
drawBuffs.put(0, GL_COLOR_ATTACHMENT0);
|
||||
GL20.glDrawBuffers(drawBuffs);
|
||||
glViewport(0,0,Main.WIDTH,Main.HEIGHT);
|
||||
}
|
||||
|
||||
public void stopRenderToFBO(){
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
public void renderFBO(){
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0,0,Main.WIDTH,Main.HEIGHT);
|
||||
|
||||
Shaders.MAIN_FBO.bind();
|
||||
Shaders.MAIN_FBO.uniform("projection", (new Matrix4f()).Ortho2D(0,1,0,1,-1,1).mul(new Matrix4f().translate(.5f,.5f,0)));
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fboTexID);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
||||
GL11.glDrawArrays(GL11.GL_QUADS, 0, size);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
Shaders.MAIN_SHADERS.unbind();
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
glDeleteTextures(fboTexID);
|
||||
glDeleteRenderbuffers(renderID);
|
||||
glDeleteFramebuffers(fbo);
|
||||
}
|
||||
|
||||
}
|
100
src/main/java/globalgamejam/render/Shaders.java
Normal file
100
src/main/java/globalgamejam/render/Shaders.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package globalgamejam.render;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
||||
import globalgamejam.input.*;
|
||||
import globalgamejam.math.*;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Shaders {
|
||||
|
||||
public int program;
|
||||
|
||||
public static Shaders MAIN_SHADERS,MAIN_FBO;
|
||||
|
||||
static{
|
||||
try{
|
||||
MAIN_SHADERS = new Shaders("res/shaders/main.vert","res/shaders/main.frag");
|
||||
MAIN_FBO = new Shaders("res/shaders/fbo.vert","res/shaders/fbo.frag");
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Shaders(String vertexFile,String fragmentFile) throws Exception{
|
||||
String fragmentShader = IO.loadFile(fragmentFile);
|
||||
String vertexShader = IO.loadFile(vertexFile);
|
||||
|
||||
if(program != -1)glDeleteProgram(program);
|
||||
program = glCreateProgram();
|
||||
int vert = glCreateShader(GL_VERTEX_SHADER);
|
||||
int frag = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(vert, vertexShader);
|
||||
glShaderSource(frag, fragmentShader);
|
||||
glCompileShader(vert);
|
||||
if (glGetShaderi(vert, GL_COMPILE_STATUS) == GL_FALSE) {
|
||||
System.err.println(glGetShaderInfoLog(vert, 2048));
|
||||
System.exit(1);
|
||||
}else{
|
||||
System.out.println(vertexFile + " compiled !");
|
||||
}
|
||||
glCompileShader(frag);
|
||||
if (glGetShaderi(frag, GL_COMPILE_STATUS) == GL_FALSE) {
|
||||
System.err.println(glGetShaderInfoLog(frag, 2048));
|
||||
System.exit(1);
|
||||
}else{
|
||||
System.out.println(fragmentFile + " compiled !");
|
||||
}
|
||||
glAttachShader(program, vert);
|
||||
glAttachShader(program, frag);
|
||||
glLinkProgram(program);
|
||||
glValidateProgram(program);
|
||||
glDeleteShader(frag);
|
||||
glDeleteShader(vert);
|
||||
}
|
||||
|
||||
public void bind(){
|
||||
glUseProgram(program);
|
||||
}
|
||||
|
||||
public void unbind(){
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
public int getAttribLocation(String name){
|
||||
return glGetAttribLocation(program, name);
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
if(program == 0)return;
|
||||
if(glIsProgram(program))unbind();
|
||||
glDeleteProgram(program);
|
||||
}
|
||||
|
||||
public void uniform(String name,float v){
|
||||
glUniform1f(glGetUniformLocation(program, name), v);
|
||||
}
|
||||
|
||||
public void uniform(String name,Vector3f vec){
|
||||
glUniform3f(glGetUniformLocation(program, name), vec.x,vec.y,vec.z);
|
||||
}
|
||||
|
||||
public void uniform(String name,Vector4f vec){
|
||||
glUniform4f(glGetUniformLocation(program, name), vec.x,vec.y,vec.z,vec.w);
|
||||
}
|
||||
|
||||
public void uniform(String name,Matrix4f mat){
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, name),true, mat.getBuffer());
|
||||
}
|
||||
|
||||
public void uniform(String name, Color4f v) {
|
||||
glUniform4f(glGetUniformLocation(program, name), v.getR(),v.getG(),v.getB(),v.getA());
|
||||
}
|
||||
|
||||
public void uniform(String name,int v){
|
||||
glUniform1i(glGetUniformLocation(program,name), v);
|
||||
}
|
||||
|
||||
}
|
160
src/main/java/globalgamejam/render/Texture.java
Normal file
160
src/main/java/globalgamejam/render/Texture.java
Normal file
|
@ -0,0 +1,160 @@
|
|||
package globalgamejam.render;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL12.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
|
||||
import javax.imageio.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
public class Texture {
|
||||
|
||||
private static final int BYTES_PER_PIXEL = 4;//3 for RGB, 4 for RGBA
|
||||
public int width, height;
|
||||
int id;
|
||||
|
||||
public Texture(int width,int height,int id){
|
||||
this.id = id;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public static Texture loadFont(String text, Color color, String font, int size){
|
||||
text = text.toUpperCase();
|
||||
Font f_font = new Font(font, Font.BOLD, size);
|
||||
|
||||
// to get the width of the text
|
||||
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
FontMetrics fm = img.getGraphics().getFontMetrics(f_font);
|
||||
|
||||
int width = fm.stringWidth(text);
|
||||
int height = fm.getHeight();
|
||||
|
||||
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
// makeTransparent(image);
|
||||
|
||||
Graphics g = image.getGraphics();
|
||||
g.setFont(f_font);
|
||||
g.setColor(color);
|
||||
g.drawString(text, 0, size);
|
||||
g.dispose();
|
||||
|
||||
int[] pixels = new int[image.getWidth() * image.getHeight()];
|
||||
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
|
||||
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); //4 for RGBA, 3 for RGB
|
||||
|
||||
for(int y = 0; y < image.getHeight(); y++){
|
||||
for(int x = 0; x < image.getWidth(); x++){
|
||||
int pixel = pixels[y * image.getWidth() + x];
|
||||
buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component
|
||||
buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
|
||||
buffer.put((byte) (pixel & 0xFF)); // Blue component
|
||||
buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
|
||||
}
|
||||
}
|
||||
|
||||
buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
|
||||
|
||||
// You now have a ByteBuffer filled with the color data of each pixel.
|
||||
// Now just create a texture ID and bind it. Then you can load it using
|
||||
// whatever OpenGL method you want, for example:
|
||||
|
||||
int textureID = glGenTextures(); //Generate texture ID
|
||||
glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
|
||||
|
||||
//Setup wrap mode
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
||||
|
||||
//Setup texture scaling filtering
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
//Send texel data to OpenGL
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return new Texture(image.getWidth(),image.getHeight(),textureID);
|
||||
}
|
||||
|
||||
public static Texture loadTexture(String path){
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new File(path));
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
int[] pixels = new int[width * height];
|
||||
|
||||
image.getRGB(0, 0, width, height, pixels, 0,width);
|
||||
|
||||
int[] data = new int[pixels.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int a = (pixels[i] & 0xff000000) >> 24;
|
||||
int r = (pixels[i] & 0xff0000) >> 16;
|
||||
int g = (pixels[i] & 0xff00) >> 8;
|
||||
int b = (pixels[i] & 0xff);
|
||||
|
||||
data[i] = a << 24 | b << 16 | g << 8 | r;
|
||||
}
|
||||
|
||||
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
|
||||
buffer.put(data);
|
||||
buffer.flip();
|
||||
|
||||
int id = glGenTextures();
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
System.out.println("Texture loaded ! " + width + "x" + height + " id:" + id);
|
||||
|
||||
return new Texture(width, height, id);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getID(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public void bind(){
|
||||
if(!glIsEnabled(GL_TEXTURE_2D))glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
}
|
||||
|
||||
public void unbind(){
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
glDeleteTextures(id);
|
||||
}
|
||||
|
||||
}
|
14
src/main/java/globalgamejam/tiles/CoffreTile.java
Normal file
14
src/main/java/globalgamejam/tiles/CoffreTile.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class CoffreTile extends Tile {
|
||||
public CoffreTile(String texturePath, float x, float y){
|
||||
super();
|
||||
super.setTexture(Texture.loadTexture(texturePath));
|
||||
super.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
super.setPosition(new Vector2f(x, y));
|
||||
super.applyTransform();
|
||||
}
|
||||
}
|
27
src/main/java/globalgamejam/tiles/EffectTile.java
Normal file
27
src/main/java/globalgamejam/tiles/EffectTile.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class EffectTile extends Tile {
|
||||
|
||||
public EffectTile(String texturePath, float x, float y){
|
||||
super();
|
||||
super.setTexture(Texture.loadTexture(texturePath));
|
||||
super.setColor(new Color4f(1, 1, 1, 0));
|
||||
super.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
super.setPosition(new Vector2f(x, y));
|
||||
super.applyTransform();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(String path){
|
||||
super.setTexture(Texture.loadTexture(path));
|
||||
super.setColor(new Color4f(1, 1, 1, 1));
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
super.setColor(new Color4f(1, 1, 1, 0));
|
||||
}
|
||||
}
|
11
src/main/java/globalgamejam/tiles/Fond.java
Normal file
11
src/main/java/globalgamejam/tiles/Fond.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class Fond extends Tile {
|
||||
public Fond(String path){
|
||||
super();
|
||||
|
||||
super.setTexture(Texture.loadTexture(path));
|
||||
}
|
||||
}
|
16
src/main/java/globalgamejam/tiles/MurTile.java
Normal file
16
src/main/java/globalgamejam/tiles/MurTile.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class MurTile extends Tile{
|
||||
|
||||
public MurTile(float x, float y, String path){
|
||||
super();
|
||||
super.setPosition(new Vector2f(x, y));
|
||||
super.setTexture(Texture.loadTexture(path));
|
||||
super.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
|
||||
super.applyTransform();
|
||||
}
|
||||
}
|
19
src/main/java/globalgamejam/tiles/ObjetTile.java
Normal file
19
src/main/java/globalgamejam/tiles/ObjetTile.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class ObjetTile extends Tile {
|
||||
|
||||
public ObjetTile(String texturePath, float x, float y){
|
||||
super();
|
||||
this.setTexture(Texture.loadTexture(texturePath));
|
||||
|
||||
this.setPosition(new Vector2f(x, y));
|
||||
|
||||
this.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
|
||||
this.applyTransform();
|
||||
}
|
||||
}
|
24
src/main/java/globalgamejam/tiles/PlayerTile.java
Normal file
24
src/main/java/globalgamejam/tiles/PlayerTile.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jean-Baptiste
|
||||
*
|
||||
*/
|
||||
public class PlayerTile extends Tile {
|
||||
|
||||
public PlayerTile(String texturePath, float x, float y){
|
||||
super();
|
||||
|
||||
this.setTexture(Texture.loadTexture(texturePath));
|
||||
|
||||
this.setPosition(new Vector2f(x, y));
|
||||
|
||||
this.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
|
||||
this.applyTransform();
|
||||
}
|
||||
}
|
145
src/main/java/globalgamejam/tiles/Tile.java
Normal file
145
src/main/java/globalgamejam/tiles/Tile.java
Normal file
|
@ -0,0 +1,145 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.*;
|
||||
import globalgamejam.render.Camera;
|
||||
import globalgamejam.render.DisplayManager;
|
||||
import globalgamejam.render.Shaders;
|
||||
import globalgamejam.render.Texture;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
* Created by MrDev023 (Florian RICHER) on 14/01/2017.
|
||||
*/
|
||||
public abstract class Tile {
|
||||
|
||||
private int vbo;
|
||||
private Texture texture;
|
||||
private Color4f color;
|
||||
private Vector2f position;
|
||||
private Vector2f scale;
|
||||
private float rotation;
|
||||
private Matrix4f transform;
|
||||
private int size;
|
||||
|
||||
public Tile(){
|
||||
this.texture = Texture.loadTexture("res/textures/default.png");
|
||||
this.transform = new Matrix4f();
|
||||
this.position = new Vector2f();
|
||||
this.scale = new Vector2f();
|
||||
this.rotation = 0;
|
||||
this.color = Color4f.WHITE;
|
||||
this.vbo = GL15.glGenBuffers();
|
||||
float[] a = new float[]{
|
||||
-.5f,-.5f, 0.0f,1.0f,
|
||||
.5f,-.5f, 1.0f,1.0f,
|
||||
.5f,.5f, 1.0f,0.0f,
|
||||
-.5f,.5f, 0.0f,0.0f
|
||||
};
|
||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(a.length);
|
||||
buffer.put(a).flip();
|
||||
size = a.length/(2+2);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
|
||||
public void render(){
|
||||
Shaders.MAIN_SHADERS.bind();
|
||||
Shaders.MAIN_SHADERS.uniform("camera", Camera.matrix);
|
||||
Shaders.MAIN_SHADERS.uniform("transform", transform);
|
||||
Shaders.MAIN_SHADERS.uniform("projection", DisplayManager.projection);
|
||||
Shaders.MAIN_SHADERS.uniform("color", this.color);
|
||||
|
||||
// GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
texture.bind();
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
||||
|
||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vert"));
|
||||
GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vert"), 2, GL11.GL_FLOAT, false, (2+2)*4, 0);
|
||||
|
||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"));
|
||||
GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, (2+2)*4, 2*4);
|
||||
|
||||
GL11.glDrawArrays(GL11.GL_QUADS, 0, size);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
texture.unbind();
|
||||
Shaders.MAIN_SHADERS.unbind();
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
GL15.glDeleteBuffers(vbo);
|
||||
texture.destroy();
|
||||
transform = null;
|
||||
this.position = null;
|
||||
this.rotation = 0;
|
||||
this.scale = null;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture) {
|
||||
|
||||
this.texture.destroy();
|
||||
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setTexture(String path) {
|
||||
this.setTexture(Texture.loadTexture(path));
|
||||
}
|
||||
|
||||
public Color4f getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color4f color4f) {
|
||||
this.color = color4f;
|
||||
}
|
||||
|
||||
public int getVbo() {
|
||||
return vbo;
|
||||
}
|
||||
|
||||
public Matrix4f getTransform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
public Vector2f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector2f getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setPosition(Vector2f position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setScale(Vector2f scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void applyTransform(){
|
||||
this.transform.loadIdentity();
|
||||
this.transform.translate(this.position.x,this.position.y,0);
|
||||
this.transform.rotate(new Quaternion(new Vector3f(0,0,1),this.rotation));
|
||||
this.transform.scale(this.scale.x,this.scale.y,1);
|
||||
}
|
||||
}
|
12
src/main/java/globalgamejam/tiles/VaguesTile.java
Normal file
12
src/main/java/globalgamejam/tiles/VaguesTile.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class VaguesTile extends Tile {
|
||||
|
||||
public VaguesTile(String path){
|
||||
super();
|
||||
super.setTexture(Texture.loadTexture(path));
|
||||
}
|
||||
|
||||
}
|
610
src/main/java/globalgamejam/world/MainWorld.java
Normal file
610
src/main/java/globalgamejam/world/MainWorld.java
Normal file
|
@ -0,0 +1,610 @@
|
|||
package globalgamejam.world;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.audio.Audio;
|
||||
import globalgamejam.game.Coffre;
|
||||
import globalgamejam.game.EObjetType;
|
||||
import globalgamejam.game.EffectEnum;
|
||||
import globalgamejam.game.MainGame;
|
||||
import globalgamejam.game.Mur;
|
||||
import globalgamejam.game.Objet;
|
||||
import globalgamejam.game.Player;
|
||||
import globalgamejam.input.Input;
|
||||
import globalgamejam.math.Mathf;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.tiles.CoffreTile;
|
||||
import globalgamejam.tiles.EffectTile;
|
||||
import globalgamejam.tiles.Fond;
|
||||
import globalgamejam.tiles.Tile;
|
||||
import globalgamejam.tiles.VaguesTile;
|
||||
|
||||
/**
|
||||
* Created by trexr on 20/01/2017.
|
||||
*/
|
||||
public class MainWorld {
|
||||
|
||||
private ArrayList<Tile> arrierePlan;
|
||||
private ArrayList<Tile> objetPlan;
|
||||
private ArrayList<Tile> premierPlan;
|
||||
|
||||
private MainGame game;
|
||||
|
||||
private Player player1,player2;
|
||||
private VaguesTile vagues;
|
||||
private float vaguesValue;
|
||||
|
||||
private ArrayList<Objet> listObjet;
|
||||
private ArrayList<Mur> listMur;
|
||||
private Mur mur1,mur2,mur3,murGauche,murDroit,murHaut,murBas;
|
||||
private long tempsEntreVague,TempsAncienneVague;
|
||||
private boolean etatVague;
|
||||
|
||||
private float maxVague = 0;
|
||||
private boolean maxVagueAtteint = false;
|
||||
private boolean despawnVagueACalculer = false;
|
||||
|
||||
private int nextVagueHeight;
|
||||
|
||||
private Coffre coffre;
|
||||
private int compteurVague;
|
||||
private boolean vagueCoffre;
|
||||
|
||||
private EffectEnum actualEffect;
|
||||
private EffectTile effectTileJ1;
|
||||
private EffectTile effectTileJ2;
|
||||
private long timeStartEffect;
|
||||
private long durationEffect;
|
||||
private long timeElapsedEffect;
|
||||
|
||||
public MainWorld(MainGame game){
|
||||
this.game = game;
|
||||
init();
|
||||
}
|
||||
|
||||
public void init(){
|
||||
|
||||
try {
|
||||
if(game.audioBackground != null){
|
||||
game.audioBackground.pauseSound();
|
||||
}
|
||||
game.audioBackground = game.audioBennyHill;
|
||||
game.audioBackground.rewindSound();
|
||||
} catch (Exception e) {}
|
||||
|
||||
arrierePlan = new ArrayList<>();
|
||||
objetPlan = new ArrayList<>();
|
||||
premierPlan = new ArrayList<>();
|
||||
listObjet = new ArrayList<>();
|
||||
listMur = new ArrayList<>();
|
||||
player1 = new Player("res/textures/perso.png", Main.WIDTH/4-20, 150);
|
||||
player2 = new Player("res/textures/perso2.png", Main.WIDTH/4 * 3-20, 150);
|
||||
|
||||
Fond fond = new Fond("res/textures/sand.jpg");
|
||||
fond.getTransform().translate(Main.WIDTH/2, Main.HEIGHT/2, 0);
|
||||
fond.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
|
||||
|
||||
vagues = new VaguesTile("res/textures/vagues.png");
|
||||
vagues.getTransform().translate(Main.WIDTH/2, -Main.HEIGHT/2, 0);
|
||||
vagues.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
|
||||
|
||||
this.murGauche = new Mur(0,Main.HEIGHT/2+40,"res/textures/murcoté.png");
|
||||
this.murDroit = new Mur(Main.WIDTH,Main.HEIGHT/2+40,"res/textures/murcoté.png");
|
||||
this.murHaut = new Mur(Main.WIDTH/2,Main.HEIGHT+10,"res/textures/murhauteur.png");
|
||||
this.murBas = new Mur(Main.WIDTH/2,80,"res/textures/murbas.png");
|
||||
this.mur1 = new Mur(Main.WIDTH/2,Main.HEIGHT-20,"res/textures/murmilieuhaut.png");
|
||||
this.mur2 = new Mur(Main.WIDTH/2, Main.HEIGHT/2+30 ,"res/textures/murmilieumilieu.png");
|
||||
this.mur3 = new Mur(Main.WIDTH/2, 100, "res/textures/murmilieubas.png");
|
||||
arrierePlan.add(fond);
|
||||
|
||||
arrierePlan.add(mur1.getTile());
|
||||
arrierePlan.add(mur2.getTile());
|
||||
arrierePlan.add(mur3.getTile());
|
||||
arrierePlan.add(murGauche.getTile());
|
||||
arrierePlan.add(murDroit.getTile());
|
||||
arrierePlan.add(murHaut.getTile());
|
||||
arrierePlan.add(murBas.getTile());
|
||||
|
||||
listMur.add(mur1);
|
||||
listMur.add(mur2);
|
||||
listMur.add(mur3);
|
||||
listMur.add(murGauche);
|
||||
listMur.add(murDroit);
|
||||
listMur.add(murHaut);
|
||||
listMur.add(murBas);
|
||||
|
||||
premierPlan.add(vagues);
|
||||
|
||||
premierPlan.add(player1.getTile());
|
||||
premierPlan.add(player2.getTile());
|
||||
|
||||
tempsEntreVague=0;
|
||||
TempsAncienneVague=System.currentTimeMillis();
|
||||
etatVague =false;
|
||||
|
||||
maxVague = 0;
|
||||
maxVagueAtteint = false;
|
||||
despawnVagueACalculer = false;
|
||||
compteurVague=0;
|
||||
vagueCoffre = true;
|
||||
actualEffect = null;
|
||||
|
||||
effectTileJ1 = new EffectTile("res/textures/default_transp.png", 100, 583);
|
||||
effectTileJ2 = new EffectTile("res/textures/default_transp.png", 500, 583);
|
||||
premierPlan.add(effectTileJ1);
|
||||
premierPlan.add(effectTileJ2);
|
||||
|
||||
genererBonusMalus(4);
|
||||
|
||||
game.audioBackground.playSound();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
if(actualEffect != null){
|
||||
timeElapsedEffect = System.currentTimeMillis() - timeStartEffect;
|
||||
if(timeElapsedEffect >= durationEffect){
|
||||
actualEffect = null;
|
||||
effectTileJ1.clear();
|
||||
effectTileJ2.clear();
|
||||
game.audioEffect.pauseSound();
|
||||
game.audioBackground.setGain(0.4f);
|
||||
}
|
||||
}
|
||||
|
||||
boolean joysticksHelp = false;
|
||||
if(Input.getJoysticks().size() > 0){
|
||||
try{
|
||||
ByteBuffer b = Input.getJoysticksButton(0);
|
||||
if(b.get(3) == 1)joysticksHelp = true;
|
||||
}catch(Exception e){}
|
||||
}
|
||||
this.moveObjets();
|
||||
|
||||
if(!Input.isKey(this.game.HELP_KEY) && !joysticksHelp){
|
||||
//Player 1
|
||||
boolean keyBoard1Enable = false;
|
||||
float xDep = 0, yDep = 0;
|
||||
if(Input.getJoysticks().size() > 0){
|
||||
try{
|
||||
FloatBuffer bufferAxis = Input.getJoysticksAxis(0);
|
||||
xDep = bufferAxis.get(0) * player1.getSpeed();
|
||||
yDep = bufferAxis.get(1) * player1.getSpeed();
|
||||
|
||||
/* if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}*/
|
||||
float rot = player1.getSpeed() * -bufferAxis.get(2) / 2.0f;
|
||||
if(actualEffect == EffectEnum.INVERSE_COMMAND_J1){
|
||||
xDep *= -1;
|
||||
yDep *= -1;
|
||||
rot *= -1;
|
||||
}
|
||||
|
||||
if(actualEffect != EffectEnum.HEAVY_J1){
|
||||
player1.move(xDep, yDep);
|
||||
}
|
||||
|
||||
player1.rotate(rot);
|
||||
}catch(Exception e){
|
||||
keyBoard1Enable = true;
|
||||
}
|
||||
}else{
|
||||
keyBoard1Enable = true;
|
||||
}
|
||||
if(keyBoard1Enable){
|
||||
if(Input.isKey(GLFW.GLFW_KEY_W)){
|
||||
// xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() + 90));
|
||||
// yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() + 90));
|
||||
yDep = player1.getSpeed() / 2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_S)){
|
||||
// xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() - 90));
|
||||
// yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() - 90));
|
||||
yDep = -player1.getSpeed() / 2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_A)){
|
||||
xDep = -player1.getSpeed() / 2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_D)){
|
||||
xDep = player1.getSpeed() / 2.0f;
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
|
||||
float rot = 0;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_Q)){
|
||||
rot = player1.getSpeed()/2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_E)){
|
||||
rot = -player1.getSpeed()/2.0f;
|
||||
}
|
||||
if(actualEffect == EffectEnum.INVERSE_COMMAND_J1){
|
||||
xDep *= -1;
|
||||
yDep *= -1;
|
||||
rot *= -1;
|
||||
}
|
||||
|
||||
if(actualEffect != EffectEnum.HEAVY_J1){
|
||||
player1.move(xDep, yDep);
|
||||
}
|
||||
|
||||
player1.rotate(rot);
|
||||
}
|
||||
|
||||
if(player1.collideWithRoundHitBox(coffre)){
|
||||
System.out.println("coffre collide J1");
|
||||
coffre.makeEffect(1);
|
||||
objetPlan.remove(coffre.getTile());
|
||||
coffre = null;
|
||||
}
|
||||
|
||||
//Player 2
|
||||
boolean keyBoard2Enable = false;
|
||||
xDep = 0;
|
||||
yDep = 0;
|
||||
if(Input.getJoysticks().size() > 1){
|
||||
try{
|
||||
FloatBuffer bufferAxis = Input.getJoysticksAxis(1);
|
||||
xDep = bufferAxis.get(0) * player2.getSpeed();
|
||||
yDep = bufferAxis.get(1) * player2.getSpeed();
|
||||
|
||||
/* if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}*/
|
||||
|
||||
float rot = player2.getSpeed() * -bufferAxis.get(2) / 2.0f;
|
||||
if(actualEffect == EffectEnum.INVERSE_COMMAND_J2){
|
||||
xDep *= -1;
|
||||
yDep *= -1;
|
||||
rot *= -1;
|
||||
}
|
||||
|
||||
if(actualEffect != EffectEnum.HEAVY_J2){
|
||||
player2.move(xDep, yDep);
|
||||
}
|
||||
|
||||
player2.rotate(rot);
|
||||
}catch(Exception e){
|
||||
keyBoard2Enable = true;
|
||||
}
|
||||
}else{
|
||||
keyBoard2Enable = true;
|
||||
}
|
||||
|
||||
if(keyBoard2Enable){
|
||||
if(Input.isKey(GLFW.GLFW_KEY_I)){
|
||||
// xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() + 90));
|
||||
// yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() + 90));
|
||||
yDep = player1.getSpeed() / 2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_K)){
|
||||
// xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 90));
|
||||
// yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 90));
|
||||
yDep = -player1.getSpeed() / 2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_J)){
|
||||
// xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 180));
|
||||
// yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 180));
|
||||
xDep = -player1.getSpeed() / 2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_L)){
|
||||
// xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle()));
|
||||
// yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle()));
|
||||
xDep = player1.getSpeed() / 2.0f;
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
float rot = 0;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_U)){
|
||||
rot = player2.getSpeed()/2.0f;
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_O)){
|
||||
rot = -player2.getSpeed()/2.0f;
|
||||
}
|
||||
if(actualEffect == EffectEnum.INVERSE_COMMAND_J2){
|
||||
xDep *= -1;
|
||||
yDep *= -1;
|
||||
rot *= -1;
|
||||
}
|
||||
|
||||
if(actualEffect != EffectEnum.HEAVY_J2){
|
||||
player2.move(xDep, yDep);
|
||||
}
|
||||
|
||||
player2.rotate(rot);
|
||||
}
|
||||
|
||||
if(player2.collideWithRoundHitBox(coffre)){
|
||||
System.out.println("coffre collide J2");
|
||||
coffre.makeEffect(2);
|
||||
objetPlan.remove(coffre.getTile());
|
||||
coffre = null;
|
||||
}
|
||||
|
||||
if(!Input.isKey(this.game.HELP_KEY) && this.game.scores[0] > 0 && this.game.scores[1] > 0 && MainGame.time_in_sec > 0){
|
||||
if(actualEffect != EffectEnum.SCORE_FREEZE){
|
||||
for(Objet o : this.listObjet){
|
||||
|
||||
float gainScore = o.getType().getPoints() * Main.delta;
|
||||
|
||||
if(o.getTile().getPosition().x < Main.WIDTH/2.0f){
|
||||
|
||||
if(actualEffect == EffectEnum.MUSIC_MULTIPLICATOR_J1){
|
||||
gainScore = (float)Math.max(gainScore, 2.0);
|
||||
gainScore *= 1.5;
|
||||
}
|
||||
|
||||
this.game.scores[0] += gainScore;
|
||||
}else{
|
||||
|
||||
if(actualEffect == EffectEnum.MUSIC_MULTIPLICATOR_J2){
|
||||
gainScore = (float)Math.max(gainScore, 0.0);
|
||||
gainScore *= 1.5;
|
||||
}
|
||||
|
||||
this.game.scores[1] += gainScore;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Objet> listObjetADespawn = new ArrayList<>();
|
||||
|
||||
if(despawnVagueACalculer){
|
||||
despawnVagueACalculer = false;
|
||||
|
||||
for(Objet o : this.listObjet){
|
||||
if(o.underWave(this.vagues.getPosition().y + this.vagues.getTexture().height / 2)){
|
||||
if(o.shouldDespawn()){
|
||||
listObjetADespawn.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Objet o : listObjetADespawn){
|
||||
this.objetPlan.remove(o.getTile());
|
||||
this.listObjet.remove(o);
|
||||
}
|
||||
|
||||
genererBonusMalus((int)(Math.random() * 4) + 2);
|
||||
GenererCoffre();
|
||||
}
|
||||
|
||||
for(Objet o : this.listObjet){
|
||||
|
||||
if(player1.brosseCollideWith(o)){
|
||||
o.resolveCollideWith(player1.getBrosse());
|
||||
}
|
||||
|
||||
if(player2.brosseCollideWith(o)){
|
||||
o.resolveCollideWith(player2.getBrosse());
|
||||
}
|
||||
|
||||
for(Objet o2 : this.listObjet){
|
||||
if(!o.equals(o2) && o.collideWith(o2)){
|
||||
o.resolveCollideWith(o2);
|
||||
}
|
||||
}
|
||||
|
||||
for(Mur m : this.listMur){
|
||||
if(o.collideWith(m)){
|
||||
o.resolveCollideWith(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(System.currentTimeMillis()-TempsAncienneVague>=tempsEntreVague){
|
||||
etatVague = vagues.getPosition().y>-224.0f;
|
||||
vaguesValue += Main.delta * 2;
|
||||
applyVaguesCoeff((Math.cos(vaguesValue)>0.5)?
|
||||
((float)Math.cos(vaguesValue)-0.5f)*2:0,(int)Main.HEIGHT/8,nextVagueHeight);
|
||||
if(vagues.getPosition().y==-225.0f && etatVague){
|
||||
tempsEntreVague = (long) (Math.random() * 5000 + 5000);
|
||||
TempsAncienneVague=System.currentTimeMillis();
|
||||
etatVague =false;
|
||||
nextVagueHeight = (int)(Math.random() * (Main.HEIGHT/4f*3f - 160f) + 160f);
|
||||
compteurVague++;
|
||||
System.out.println(compteurVague);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void render(){
|
||||
boolean joysticksHelp = false;
|
||||
if(Input.getJoysticks().size() > 0){
|
||||
try{
|
||||
ByteBuffer b = Input.getJoysticksButton(0);
|
||||
if(b.get(3) == 1)joysticksHelp = true;
|
||||
}catch(Exception e){}
|
||||
}
|
||||
if(!Input.isKey(this.game.HELP_KEY) && this.game.scores[0] > 0 && this.game.scores[1] > 0 && MainGame.time_in_sec > 0 && !joysticksHelp){
|
||||
for(Tile t : arrierePlan)t.render();
|
||||
if(coffre!=null){
|
||||
//System.out.println("dd");
|
||||
coffre.getTile().render();
|
||||
}
|
||||
for(Tile t : objetPlan)t.render();
|
||||
for(Tile t : premierPlan)t.render();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
for(Tile t : arrierePlan)t.destroy();
|
||||
arrierePlan.clear();
|
||||
for(Tile t : objetPlan)t.destroy();
|
||||
objetPlan.clear();
|
||||
for(Tile t : premierPlan)t.destroy();
|
||||
premierPlan.clear();
|
||||
for(Objet t : listObjet)t.getTile().destroy();;
|
||||
listObjet.clear();
|
||||
for(Mur t : listMur)t.getTile().destroy();
|
||||
listMur.clear();
|
||||
|
||||
}
|
||||
|
||||
public void genererBonusMalus(int nombre){
|
||||
int minWidth = 80;
|
||||
int maxWidth = Main.WIDTH - minWidth;
|
||||
EObjetType[] types = EObjetType.values();
|
||||
for(int i = 0;i < nombre;i++){
|
||||
EObjetType type = types[(int)(Math.random() * types.length)];
|
||||
Objet o = new Objet(type.getFilename(), (float)(Math.random() * (maxWidth - minWidth)) + minWidth, 150, 0, 0, 5, 0.02f);
|
||||
o.setType(type);
|
||||
objetPlan.add(o.getTile());
|
||||
listObjet.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyVaguesCoeff(float coeff,int offset,int height){
|
||||
vagues.getTransform().loadIdentity();
|
||||
vagues.setPosition(new Vector2f(Main.WIDTH/2, -Main.HEIGHT/2 + height*coeff + offset));
|
||||
vagues.setScale(new Vector2f(Main.WIDTH,Main.HEIGHT));
|
||||
vagues.applyTransform();
|
||||
|
||||
if(vagues.getPosition().y >= this.maxVague){
|
||||
this.maxVague = vagues.getPosition().y;
|
||||
}
|
||||
else if(!this.maxVagueAtteint){
|
||||
this.maxVagueAtteint = true;
|
||||
|
||||
this.despawnVagueACalculer = true;
|
||||
}
|
||||
else if(vagues.getPosition().y == -225.0){
|
||||
this.maxVague = -225.0f;
|
||||
this.maxVagueAtteint = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void moveObjets(){
|
||||
for(Objet o : this.listObjet){
|
||||
o.move();
|
||||
}
|
||||
}
|
||||
|
||||
private void inverserObjetGaucheDroite(){
|
||||
for(Objet o : this.listObjet){
|
||||
|
||||
float distMilieu = Main.WIDTH/2.0f - o.getX();
|
||||
|
||||
o.setPosition(Main.WIDTH/2.0f + distMilieu, o.getY());
|
||||
|
||||
o.setVelocity(-o.getxVelocity(), o.getyVelocity());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void GenererCoffre(){
|
||||
|
||||
if(coffre != null){
|
||||
objetPlan.remove(coffre.getTile());
|
||||
coffre = null;
|
||||
}
|
||||
|
||||
final float ChancePop = 0.6f;
|
||||
int minHeight = 150;
|
||||
int maxHeight = Main.HEIGHT - 50;
|
||||
int minWidth = 80;
|
||||
int maxWidth = Main.HEIGHT - minWidth;
|
||||
if(!vagueCoffre){
|
||||
vagueCoffre=true;
|
||||
}
|
||||
else{
|
||||
if(Math.random()>=1-ChancePop&& compteurVague>=4){
|
||||
System.out.println("dfjkl");
|
||||
vagueCoffre = false;
|
||||
coffre = new Coffre("res/textures/coffre.png",(float) (Math.random() *(maxWidth-minWidth) + minWidth),(float) (Math.random() *(maxHeight-minHeight) + minHeight)){
|
||||
|
||||
@Override
|
||||
public void makeEffect(int numPlayerHitCoffre){
|
||||
effectTileJ1.clear();
|
||||
effectTileJ2.clear();
|
||||
|
||||
double effectRand = Math.random();
|
||||
|
||||
if(effectRand < 0.2){
|
||||
// effet 1 avec 20% de chance
|
||||
actualEffect = EffectEnum.INVERSE_SCREEN;
|
||||
inverserObjetGaucheDroite();
|
||||
}
|
||||
else if(effectRand < 0.4){
|
||||
// effet 2 avec 20% de chance
|
||||
if(numPlayerHitCoffre == 1){
|
||||
actualEffect = EffectEnum.MUSIC_MULTIPLICATOR_J1;
|
||||
effectTileJ1.setTexture("res/textures/noteMusic.png");
|
||||
}
|
||||
else{
|
||||
actualEffect = EffectEnum.MUSIC_MULTIPLICATOR_J2;
|
||||
effectTileJ2.setTexture("res/textures/noteMusic.png");
|
||||
}
|
||||
if(game.audioEffect != null){
|
||||
game.audioEffect.pauseSound();
|
||||
game.audioEffect.rewindSound();
|
||||
}
|
||||
try{
|
||||
game.audioBackground.setGain(0.1f);
|
||||
game.audioEffect = game.audioMacarena;
|
||||
game.audioEffect.playSound();
|
||||
} catch(Exception e){}
|
||||
}
|
||||
else if(effectRand < 0.6){
|
||||
// effet 3 avec 20% de chance
|
||||
if(numPlayerHitCoffre == 1){
|
||||
actualEffect = EffectEnum.INVERSE_COMMAND_J2;
|
||||
effectTileJ2.setTexture("res/textures/inverser.png");
|
||||
}
|
||||
else{
|
||||
actualEffect = EffectEnum.INVERSE_COMMAND_J1;
|
||||
effectTileJ1.setTexture("res/textures/inverser.png");
|
||||
}
|
||||
}
|
||||
else if(effectRand < 0.8){
|
||||
// effet 4 avec 20% de chance
|
||||
actualEffect = EffectEnum.SCORE_FREEZE;
|
||||
effectTileJ1.setTexture("res/textures/gel.png");
|
||||
effectTileJ2.setTexture("res/textures/gel.png");
|
||||
|
||||
}
|
||||
else{
|
||||
// effet 5 avec 20% de chance
|
||||
if(numPlayerHitCoffre == 1){
|
||||
actualEffect = EffectEnum.HEAVY_J2;
|
||||
effectTileJ2.setTexture("res/textures/stop.png");
|
||||
}
|
||||
else{
|
||||
actualEffect = EffectEnum.HEAVY_J1;
|
||||
effectTileJ1.setTexture("res/textures/stop.png");
|
||||
}
|
||||
}
|
||||
|
||||
durationEffect = 7_000; // ms
|
||||
timeStartEffect = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in a new issue