Skip to content

Commit

Permalink
Sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Draknek committed Feb 8, 2011
1 parent c8f67e3 commit 3935bd8
Show file tree
Hide file tree
Showing 14 changed files with 1,759 additions and 394 deletions.
86 changes: 43 additions & 43 deletions Aimer.as
@@ -1,43 +1,43 @@
package package
{ {
import net.flashpunk.graphics.Image; import net.flashpunk.graphics.Image;
/** /**
* ... * ...
* @author William David Hunt * @author William David Hunt
*/ */
public class Aimer extends Enemy public class Aimer extends Enemy
{ {
[Embed(source = 'assets/enemy_32_3.png')] [Embed(source = 'assets/enemy_32_3.png')]
private const SPRITE:Class; private const SPRITE:Class;


public function Aimer(_x:Number = 0, _y:Number = 0, _vx:Number = 0, _vy:Number = 0) public function Aimer(_x:Number = 0, _y:Number = 0, _vx:Number = 0, _vy:Number = 0)
{ {
super(_x, _y, _vx, _vy); super(_x, _y, _vx, _vy);
image = new Image(SPRITE); image = new Image(SPRITE);
image.centerOO(); image.centerOO();
graphic = image; graphic = image;
} }


override public function update():void override public function update():void
{ {
x += vx; x += vx;
y += vy; y += vy;


var p1:Player = Level(world).p1; var p1:Player = Level(world).p1;
var p2:Player = Level(world).p2; var p2:Player = Level(world).p2;


if (time % 150 == 0) { if (time % 150 == 0) {
shootAt(p1.x, p1.y); shootAt(p1.x, p1.y);
shootAt(p2.x, p2.y); shootAt(p2.x, p2.y);
} }


if (x < -50 || x > 700 || y < -50 || y > 550) { if (x < -50 || x > 700 || y < -50 || y > 550) {
world.remove(this); world.remove(this);
} }


time += 1; time += 1;
} }


} }


} }
115 changes: 115 additions & 0 deletions Audio.as
@@ -0,0 +1,115 @@
package
{
import flash.display.*;
import flash.events.*;
import flash.net.SharedObject;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import net.flashpunk.utils.Key;

public class Audio
{
private static var sounds:Object = {}

private static var _mute:Boolean = false;
private static var so:SharedObject;
private static var menuItem:ContextMenuItem;

public static function init (o:InteractiveObject):void
{
// Setup

so = SharedObject.getLocal("audio", "/");

_mute = so.data.mute;

addContextMenu(o);

if (o.stage) {
addKeyListener(o.stage);
} else {
o.addEventListener(Event.ADDED_TO_STAGE, stageAdd);
}

// Create sounds

createSound("bounce", "2,,0.28,0.141,0.092,0.78,0.071,-0.469,,,,,,0.043,0.118,,,,1,,,0.112,,0.5");
createSound("explode", "3,,0.147,0.426,0.52,0.14,,0.199,-0.26,,,,,,,0.304,0.173,-0.177,1,,,,,0.5");
createSound("playerdie", "3,,0.332,0.39,0.67,0.07,,-0.099,-0.28,,,0.439,0.57,,,0.344,-0.089,-0.018,1,,,,,0.5");
createSound("playerhit", "3,,0.03,,0.219,0.579,,-0.473,,,,,,,,,,,1,,,0.006,,0.5");
createSound("beamspam", "0,0.1,0.317,0.032,0.337,0.519,,0.008,,,0.035,0.899,,0.35,-0.88,0.763,0.098,-0.307,0.865,0.16,0.227,0.27,-0.937,0.5");
createSound("crossshooter", "0,,0.287,0.231,0.152,0.74,0.351,-0.308,-0.032,,,-0.047,,0.471,-0.519,,-0.033,-0.185,1,0.049,0.001,0.043,0.069,0.5");
}

private static function createSound (name:String, settings:String):SfxrSynth
{
sounds[name] = new SfxrSynth;
sounds[name].setSettingsString(settings);
sounds[name].cacheMutations(4);
return sounds[name];
}

public static function play (sound:String):void
{
if (! _mute) {
sounds[sound].playCachedMutation();
}
}

// Getter and setter for mute property

public static function get mute (): Boolean { return _mute; }

public static function set mute (newValue:Boolean): void
{
if (_mute == newValue) return;

_mute = newValue;

menuItem.caption = _mute ? "Unmute" : "Mute";

so.data.mute = _mute;
so.flush();
}

// Implementation details

private static function stageAdd (e:Event):void
{
addKeyListener(e.target.stage);
}

private static function addContextMenu (o:InteractiveObject):void
{
var menu:ContextMenu = o.contextMenu || new ContextMenu;

menu.hideBuiltInItems();

menuItem = new ContextMenuItem(_mute ? "Unmute" : "Mute");

menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuListener);

menu.customItems.push(menuItem);

o.contextMenu = menu;
}

private static function addKeyListener (stage:Stage):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyListener);
}

private static function keyListener (e:KeyboardEvent):void
{
if (e.keyCode == Key.M) {
mute = ! mute;
}
}

private static function menuListener (e:ContextMenuEvent):void
{
mute = ! mute;
}
}
}

110 changes: 56 additions & 54 deletions BeamSpam.as
@@ -1,54 +1,56 @@
package package
{ {
import net.flashpunk.graphics.Image; import net.flashpunk.graphics.Image;
/** /**
* ... * ...
* @author William David Hunt * @author William David Hunt
*/ */
public class BeamSpam extends Enemy public class BeamSpam extends Enemy
{ {


[Embed(source = '../assets/enemy_32_1.png')] [Embed(source = '../assets/enemy_32_1.png')]
private const SPRITE:Class; private const SPRITE:Class;


private var angle:Number = 0; private var angle:Number = 0;
private var targetX:Number; private var targetX:Number;
private var targetY:Number; private var targetY:Number;


public function BeamSpam(_x:Number = 0, _y:Number = 0, _vx:Number = 0, _vy:Number = 0) public function BeamSpam(_x:Number = 0, _y:Number = 0, _vx:Number = 0, _vy:Number = 0)
{ {
super(_x, _y, _vx, _vy); super(_x, _y, _vx, _vy);
image = new Image(SPRITE); image = new Image(SPRITE);
image.centerOO(); image.centerOO();
graphic = image; graphic = image;
} }


override public function update():void override public function update():void
{ {
if (!world) return; if (!world) return;


if (time % 150 == 120) { if (time % 150 == 120) {
if (Toolbox.randBool()) { if (Toolbox.randBool()) {
targetX = Level(world).p1.x; targetX = Level(world).p1.x;
targetY = Level(world).p1.y; targetY = Level(world).p1.y;
} else { } else {
targetX = Level(world).p2.x; targetX = Level(world).p2.x;
targetY = Level(world).p2.y; targetY = Level(world).p2.y;
} }
} else if (time % 150 > 120 && time % 3 == 0) {
shootAt(targetX, targetY); Audio.play("beamspam");
} else { } else if (time % 150 > 120 && time % 3 == 0) {
x += vx; shootAt(targetX, targetY);
y += vy; } else {
} x += vx;

y += vy;
if (x < -50 || x > 700 || y < -50 || y > 550) { }
world.remove(this);
} if (x < -50 || x > 700 || y < -50 || y > 550) {

world.remove(this);
time += 1; }
}

time += 1;
} }


} }

}

0 comments on commit 3935bd8

Please sign in to comment.