Skip to content

Commit

Permalink
- Add sounds! Bloop for picking key up and background music
Browse files Browse the repository at this point in the history
- Fixed some issues in loading/handling of levels
- Fixed level 10 not having a floor
  • Loading branch information
SgtCoDFish committed Aug 2, 2014
1 parent ce9bf10 commit a8c011f
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 25 deletions.
Binary file added android/assets/audio/bloop.wav
Binary file not shown.
File renamed without changes.
7 changes: 5 additions & 2 deletions android/assets/levels/level10.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
<image source="../fontsets/numbers.png" width="320" height="32"/>
</tileset>
<layer name="floor" width="8" height="17">
<properties>
<property name="solid" value="true"/>
</properties>
<data encoding="base64" compression="zlib">
eJxjYBi8gJWAPDsBvfjk2aGYF4g5gVgIiAWhNCOSPCH9uAAPAXkGIuR5CMjTAwAAueQAtQ==
eJxjYCAPsACxOJl6iQWsBOTZCejFJ88OxbxAzAnEQkAsCKUZkeQJ6ccFeAjIMxAhz0NAnhJAbPwBAPDcAOs=
</data>
</layer>
<layer name="levelnumber" width="8" height="17">
Expand All @@ -26,7 +29,7 @@
<property name="dx" value="3"/>
</properties>
<data encoding="base64" compression="zlib">
eJxjYCAPsACxOJl6RwHxgAmImYFYlMrmEht/AEVkAFE=
eJxjYBgFgxkwATEzEIsOkP0ADmwAGw==
</data>
</layer>
<layer name="key" width="8" height="17">
Expand Down
9 changes: 9 additions & 0 deletions core/src/com/sgtcodfish/mobiusListing/MobiusListingGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.sgtcodfish.mobiusListing.levels.LevelEntityFactory;
import com.sgtcodfish.mobiusListing.player.PlayerConstants;
import com.sgtcodfish.mobiusListing.player.PlayerEntityFactory;
import com.sgtcodfish.mobiusListing.systems.AudioSystem;
import com.sgtcodfish.mobiusListing.systems.CollisionBoxRenderingDebugSystem;
import com.sgtcodfish.mobiusListing.systems.FocusTakerSystem;
import com.sgtcodfish.mobiusListing.systems.LevelAdvanceSystem;
Expand Down Expand Up @@ -52,6 +53,7 @@ public enum MobiusState {
private MovementSystem movementSystem = null;
private TerrainCollisionSystem terrainCollisionSystem = null;
private LinkingSystem linkingSystem = null;
private AudioSystem audioSystem = null;

private TerrainCollisionBoxRenderingDebugSystem terrainDebugSystem = null;

Expand Down Expand Up @@ -89,6 +91,7 @@ public void create() {
movementSystem = new MovementSystem(0.0f);
terrainCollisionSystem = new TerrainCollisionSystem(null);
linkingSystem = new LinkingSystem();
audioSystem = new AudioSystem();

world.setSystem(new PlayerInputSystem(this));
world.setSystem(new PlatformInputSystem(camera, terrainCollisionSystem));
Expand All @@ -103,6 +106,7 @@ public void create() {
world.setSystem(new FocusTakerSystem(camera));
world.setSystem(new TiledRenderingSystem(batch, camera));
world.setSystem(new SpriteRenderingSystem(batch, camera));
world.setSystem(audioSystem);

if (DEBUG) {
terrainDebugSystem = new TerrainCollisionBoxRenderingDebugSystem(camera, terrainCollisionSystem);
Expand All @@ -121,6 +125,7 @@ public void create() {

levelEntityFactory = new LevelEntityFactory(world, batch);
nextLevel();
audioSystem.start();
}

@Override
Expand Down Expand Up @@ -196,6 +201,10 @@ public void resume() {

@Override
public void dispose() {
if (audioSystem != null) {
audioSystem.dispose();
}

if (playerEntityFactory != null) {
playerEntityFactory.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ public int worldToTileCoordinatesX(float x) {
public int worldToTileCoordinatesY(float y) {
int ty = (int) (y / layer.getTileHeight());

if (ty < 0 || ty >= layer.getHeight()) {
if (ty < 0) {
ty = ty % actualHeightInTiles();
} else if (ty >= actualHeightInTiles()) {
ty = actualHeightInTiles() - 1;
}

return ty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public class LevelEntityFactory implements Disposable {
// set to true to output detailed info about each level during loading
public static boolean VERBOSE_LOAD = false;

// note: level5, level9, level15 removed.
// note: level5, level7, level9, level11, level12, level15, level27 removed.
// level11: thin corridors
// level12: over-edge fade platform
public static final String[] MAP_NAMES = { "level0.tmx", "level1.tmx", "level2.tmx",
"level3.tmx", "level4.tmx", "level6.tmx", "level7.tmx", "level8.tmx", "level10.tmx", "level11.tmx",
"level12.tmx", "level13.tmx", "level14.tmx", "level16.tmx", "level17.tmx", "level18.tmx", "level19.tmx",
"level20.tmx", "level21.tmx", "level22.tmx", "level23.tmx", "level24.tmx", "level25.tmx", "level26.tmx",
"level27.tmx", "level28.tmx", "level29.tmx", "level30.tmx", "level31.tmx", "level32.tmx" };
"level3.tmx", "level4.tmx", "level6.tmx", "level8.tmx", "level10.tmx", "level13.tmx", "level14.tmx",
"level16.tmx", "level17.tmx", "level18.tmx", "level19.tmx", "level20.tmx", "level21.tmx", "level22.tmx",
"level23.tmx", "level24.tmx", "level25.tmx", "level26.tmx", "level28.tmx", "level29.tmx", "level30.tmx",
"level31.tmx", "level32.tmx" };

public static final String[] VITAL_LAYERS = { "floor", "key", "exit", "playerspawn" };

Expand Down Expand Up @@ -105,7 +107,7 @@ public LevelEntityFactory(World world, Batch batch, String folderName) {
/**
* <p>
* Generates an array of entities for the next level, and returns it.
* Returns null if there are no more levels.
* Returns false if there are no more levels.
* </p>
*
* @return true if a level was loaded, false if there are no more levels.
Expand All @@ -117,7 +119,7 @@ public boolean loadNextLevel() {
return false;
} else {
if (Gdx.app.getLogLevel() == Application.LOG_DEBUG) {
Gdx.app.debug("NEXT_LEVEL", "Level's manager contains "
Gdx.app.debug("NEXT_LEVEL", "Level " + getCurrentLevelGroupName() + "'s manager contains "
+ world.getManager(GroupManager.class).getEntities(levels.get(levelNumber)).size + " entities.");
}

Expand Down Expand Up @@ -314,14 +316,17 @@ protected void loadLevel(TmxMapLoader loader, FileHandle handle) {

levelSpawns.put(groupName, spawn);
}
}

if (isSolidLayer(layer)) {
if (collisionMaps.get(groupName) == null) {
collisionMaps.put(groupName, TerrainCollisionMap.generateCollisionMap(map, invertedMap));
} else {
throw new GdxRuntimeException("Modifying collision maps NYI");
}
if (collisionMaps.get(groupName) == null) {
TerrainCollisionMap tempCollMap = TerrainCollisionMap.generateCollisionMap(map, invertedMap);
if (tempCollMap == null) {
Gdx.app.error("LOAD_LEVELS", "Could not create collision map for level " + groupName + ".");
} else {
collisionMaps.put(groupName, tempCollMap);
}
} else {
throw new GdxRuntimeException("Modifying collision maps NYI");
}

levels.add(groupName);
Expand Down
81 changes: 81 additions & 0 deletions core/src/com/sgtcodfish/mobiusListing/systems/AudioSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.sgtcodfish.mobiusListing.systems;

import java.util.ArrayList;

import com.artemis.systems.VoidEntitySystem;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.utils.Disposable;

/**
* <p>
* Handles playing all audio.
* </p>
*
* @author Ashley Davis (SgtCoDFish)
*/
public class AudioSystem extends VoidEntitySystem implements Disposable {
public static final String AUDIO_PREFIX = "audio/";

private Music backgroundMusic = null;
private Sound bloop = null;

private ArrayList<MobiusSounds> soundQueue = null;

public enum MobiusSounds {
BLOOP;
}

public AudioSystem() {
}

@Override
public void initialize() {
soundQueue = new ArrayList<AudioSystem.MobiusSounds>();

backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal(AUDIO_PREFIX + "soundtrack.mp3"));
backgroundMusic.setLooping(true);
backgroundMusic.setVolume(0.5f);

bloop = Gdx.audio.newSound(Gdx.files.internal(AUDIO_PREFIX + "bloop.wav"));
}

@Override
protected void processSystem() {
if (soundQueue.size() > 0) {
Gdx.app.debug("AUDIO_SYSTEM_PROCESS", "Processing " + soundQueue.size() + " queued sounds.");
for (MobiusSounds sound : soundQueue) {
switch (sound) {
case BLOOP: {
bloop.play();
break;
}

default: {
Gdx.app.debug("AUDIO_SYSTEM_PROCESS", "Invalid sound in sound queue, size is " + soundQueue.size());
}
}
}

soundQueue.clear();
}
}

public void start() {
backgroundMusic.play();
}

public void stop() {
backgroundMusic.pause();
}

public void enqueue(MobiusSounds sound) {
soundQueue.add(sound);
}

public void dispose() {
backgroundMusic.dispose();
bloop.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
* @author Ashley Davis (SgtCoDFish)
*/
public class MovementSystem extends EntityProcessingSystem {
public static final float FRICTION = 0.75f; // TODO:
// Implement
// friction
// and
// air
// resistance
public static final float FRICTION = 0.75f;
// TODO: Implement friction and air resistance
public static final float AIR_RESISTANCE = 0.75f;

private ComponentMapper<Position> positionMapper = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.sgtcodfish.mobiusListing.components.Solid;
import com.sgtcodfish.mobiusListing.components.Velocity;
import com.sgtcodfish.mobiusListing.player.PlayerConstants;
import com.sgtcodfish.mobiusListing.systems.AudioSystem.MobiusSounds;

/**
* @author Ashley Davis (SgtCoDFish)
Expand Down Expand Up @@ -158,5 +159,6 @@ protected void collect(Entity one, Entity item) {
Gdx.app.debug("PICKUP", collectable.item.name + " was picked up!");

linkingSystem.scheduleForRemoval(item);
world.getSystem(AudioSystem.class).enqueue(MobiusSounds.BLOOP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sgtcodfish.mobiusListing.components.PlayerState;
import com.sgtcodfish.mobiusListing.components.Position;
import com.sgtcodfish.mobiusListing.components.StaticSprite;
import com.sgtcodfish.mobiusListing.components.Velocity;

/**
* Handles drawing Entities with a Position and Renderable component
Expand Down Expand Up @@ -68,10 +69,20 @@ protected void process(Entity e) {
batch.begin();

if (playerSprite != null) {
int mirror = (playerSprite.mirrored ? -1 : 1);
Velocity v = world.getMapper(Velocity.class).get(e);
int mirror = 1;

if (v != null) {
if (v.velocity.x > 0.0f) {
mirror = 1;
} else if (v.velocity.x < 0.0f) {
mirror = -1;
}
}

batch.draw(playerSprite.getFrame(playerStateMapper.get(e).state, world.getDelta()), p.position.x,
p.position.y, playerSprite.spriteWidth, mirror * playerSprite.spriteHeight);
batch.draw(playerSprite.getFrame(playerStateMapper.get(e).state, world.getDelta()), p.position.x
+ (mirror < 0 ? playerSprite.spriteWidth : 0), p.position.y, playerSprite.spriteWidth * mirror,
playerSprite.spriteHeight);

} else if (staticSprite != null) {
int mirror = (staticSprite.mirrored ? -1 : 1);
Expand Down

0 comments on commit a8c011f

Please sign in to comment.