Super Mufasa's Profile

About

 
Points: 24
Gender: Male

Pages

Contact

 

Super Mufasa
November 26, 2014 · Public

Hi I'm interested in LibGDX for developing mobile games, are there any good tutorials for learning that specific aspect of LibGDX? Thanks!

Super Mufasa
November 17, 2014 · Public

You know you're a real programmer when the funniest thing that happened all day is you misspelled "public" as "pubic".

Super Mufasa
November 13, 2014 · Public

GabeN didn't choose the thug life, the thug life chose GabeN.


Super Mufasa
October 10, 2014 · Public

Why can't I upload a profile pic? It's only 50KB and it takes forever.

Super Mufasa
October 10, 2014 · Public

I made a random music player for Slick2D, feel free to use it for whatever you want :)

package *your package here*;

import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;

public class RandomMusicPlayer {

public void RandomMusic() throws SlickException{

Music music1 = new Music("res/music1.wav");

int random;

random = (int)(Math.random() * 10); //change the 10 for more or less tracks

if(random == 1){
music1.play();
System.out.println("Track n.1");
}
}
}

Then, in the state you want to have random music:

package *your package here*;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class *your class here* extends BasicGameState{

int time = 0;
int duration = 2000;

RandomMusicPlayer musicObj = new RandomMusicPlayer();

public Play(int state){
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
if(time==duration){
musicObj.RandomMusic();
time = 0;
}
}

public int getID(){
return 1;
}

}

This will play a different song every 2 seconds, but if you want it to play every 2 minutes (or more or less) just change the duration integer just keep in mind that it is in millisecond, enjoy ;-)