Skip to content

Commit

Permalink
v0.1.0: We have sound! And its horrible!
Browse files Browse the repository at this point in the history
Not really my fault, I blame @miguelosmondo
  • Loading branch information
tube42 committed Jan 4, 2019
1 parent bb8807a commit e888c18
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 6 deletions.
1 change: 0 additions & 1 deletion android/assets/save/settings.txt

This file was deleted.

Binary file added android/assets/sound/music0.ogg
Binary file not shown.
Binary file added android/assets/sound/new0.ogg
Binary file not shown.
Binary file added android/assets/sound/new1.ogg
Binary file not shown.
Binary file added android/assets/sound/new2.ogg
Binary file not shown.
Binary file added android/assets/sound/new3.ogg
Binary file not shown.
Binary file added android/assets/sound/new4.ogg
Binary file not shown.
Binary file added android/assets/sound/new5.ogg
Binary file not shown.
Binary file added android/assets/sound/new6.ogg
Binary file not shown.
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
targetSdkVersion 28

// game version (matches git tag)
versionCode 9
versionName "0.0.9"
versionCode 10
versionName "0.1.0"
}
buildTypes {
release {
Expand Down
10 changes: 9 additions & 1 deletion core/src/se/tube42/p9/P9.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package se.tube42.p9;

import java.util.*;
import com.badlogic.gdx.*;
import com.badlogic.gdx.assets.loaders.SoundLoader;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
Expand Down Expand Up @@ -98,5 +101,10 @@ public void load_assets()
tmp = AssetService.load(ascale + "/lang.png", true);
Assets.tex_lang = AssetService.divide(tmp, 1, 4);

}

Assets.sound_new = SoundService.loadSound("new");
Assets.music = SoundService.loadMusic("music0");
}


}
3 changes: 3 additions & 0 deletions core/src/se/tube42/p9/data/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ public final class Assets

public static TextureRegion [] tex_icons, tex_rect;
public static TextureRegion [] tex_splash, tex_lang;

public static Sound [] sound_new;
public static Music music;
}

83 changes: 83 additions & 0 deletions core/src/se/tube42/p9/logic/SoundService.java
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);
}
}
5 changes: 4 additions & 1 deletion core/src/se/tube42/p9/view/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void resize(int w, int h) {

// position stars stars
final int starsize = lui.getSize();
final int star_y0 = lui.getY();
final int star_y0 = sel_y0 + (sel_size - starsize) / 2;
final int star_x0 = (w - 3 * starsize) / 2;
for (int i = 0; i < stars.length; i++) {
final StarItem si = stars[i];
Expand Down Expand Up @@ -299,6 +299,9 @@ private int board_check() {
text0.set(BaseItem.ITEM_A, 1f, 0).configure(0.3f, null)
.pause(0.5f)
.tail(1f).configure(0.5f, null);

SoundService.playNew(World.board.cnt, WORD_MAX_SIZE);

return WORD_NEW;
} else {
text0.setText(ServiceProvider.translate("seen"));
Expand Down
2 changes: 1 addition & 1 deletion core/src/se/tube42/p9/view/MenuScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void resize(int w, int h) {
public void onShow() {
position();
animate(true);

SoundService.playMusic(true);
}

public void onHide() {
Expand Down

3 comments on commit e888c18

@miguelosmondo
Copy link

@miguelosmondo miguelosmondo commented on e888c18 Jan 5, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tube42
Copy link
Owner Author

@tube42 tube42 commented on e888c18 Jan 6, 2019

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.

@tube42
Copy link
Owner Author

@tube42 tube42 commented on e888c18 Jan 6, 2019

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 :)

Please sign in to comment.