-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.1.0: We have sound! And its horrible!
Not really my fault, I blame @miguelosmondo
- Loading branch information
Showing
15 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
package se.tube42.p9.logic; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
import com.badlogic.gdx.*; | ||
import com.badlogic.gdx.files.*; | ||
import com.badlogic.gdx.audio.Music; | ||
import com.badlogic.gdx.audio.Sound; | ||
|
||
|
||
import se.tube42.p9.data.*; | ||
import static se.tube42.p9.data.Constants.*; | ||
|
||
public final class SoundService | ||
{ | ||
public static Sound[] loadSound(String name) | ||
{ | ||
ArrayList<Sound> a = new ArrayList<Sound>(); | ||
|
||
try { | ||
for(int i = 0; ; i++) { | ||
String filename = "sound/" + name + i + ".ogg"; | ||
System.out.println(" " + filename); | ||
Sound s = Gdx.audio.newSound( | ||
Gdx.files.internal(filename)); | ||
a.add(s); | ||
} | ||
} catch(Exception e) { | ||
// ignored | ||
} | ||
|
||
if(a.size() == 0) { | ||
System.err.println("nothing loaded :("); | ||
Gdx.app.exit(); | ||
} | ||
Sound [] s = new Sound[a.size()]; | ||
return a.toArray(s); | ||
} | ||
|
||
public static Music loadMusic(String name) | ||
{ | ||
String filename = "sound/" + name + ".ogg"; | ||
Music m = Gdx.audio.newMusic( Gdx.files.internal(filename)); | ||
m.setLooping(true); | ||
return m; | ||
} | ||
|
||
|
||
public static void playMusic(boolean play) { | ||
Music m = Assets.music; | ||
if(Settings.sound_on && play) { | ||
if(!m.isPlaying()) | ||
m.play(); | ||
} else { | ||
m.stop(); | ||
} | ||
} | ||
|
||
private static int new_idx = 0; | ||
private static long new_time = 0; | ||
public static void playNew(int n, int max) { | ||
if(!Settings.sound_on) | ||
return; | ||
|
||
// make sure we dont play too close to last one | ||
long now = System.currentTimeMillis(); | ||
if(now - new_time < 250) { | ||
for(int i = 0; i < Assets.sound_new.length; i++) { | ||
Assets.sound_new[i].stop(); | ||
} | ||
} | ||
new_time = now; | ||
|
||
|
||
int i = n - max + Assets.sound_new.length - 1; | ||
if(i < 0) | ||
i = 0; | ||
float amp = 0.2f + 0.5f * (n / max); | ||
Assets.sound_new[i].play(amp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e888c18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e888c18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha ha, yes it can be disabled under settings. I think its turned off by default.
It doesn't sound great because I didn't have time to create good sounds, I hope I can replace them in future.
e888c18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, the "sounds" are actually the chord progression of a famous song.
I challenge everyone to play the song by finding words of proper size in quick succession :)