import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.Lib; import flash.text.TextField; import gamelib2d.Sfxr; class Main { static var screen: Sprite; static var tf: TextField = new TextField (); static var firstTime: Bool = true; static var lastX: Int = -1; static var lastY: Int = -1; static var mutateCount: Int = 0; static var sfxr: Sfxr; public function new () { screen = new Sprite (); screen.addEventListener (Event.ENTER_FRAME, onEnterFrame); screen.addEventListener (MouseEvent.CLICK, onClick); } static var category: Int; static function onClick (e: Event) { var mx: Int = Std.int (screen.mouseX); var my: Int = Std.int (screen.mouseY); if (mx != lastX || my != lastY) { sfxr = new Sfxr (0.75, 44100, 16, 0.0, mx, my); category = (mx + my) % 8; if (category == 0) sfxr.randomize (); else sfxr.create (category); mutateCount = 0; } else { sfxr.mutate (); mutateCount++; } sfxr.generate (); sfxr.play (); tf.htmlText = "sfxr.setRandSeed (" + mx + ", " + my + ");
"; if (category == 0) tf.htmlText += "sfxr.randomize
"; else tf.htmlText += "sfxr.create (" + category + ");
"; if (mutateCount > 0) tf.htmlText += "for (i in 0..." + mutateCount + ") sfxr.mutate ();
"; tf.htmlText += "sfxr.generate ();"; lastX = mx; lastY = my; } static function onEnterFrame (e: Event) { if (firstTime) { flash.Lib.current.addChild (screen); firstTime = false; init (); } } static function init () { tf = new TextField (); tf.width = 530; tf.height = 380; tf.x = 10; tf.y = 10; tf.htmlText = "Click anywhere to play sounds"; tf.multiline = true; screen.addChild (tf); } static function main() { #if debug org.flashdevelop.utils.FlashConnect.redirect(); #end new Main (); } }