SiONさわってみた
SiONで音色を変更
clickでjump
radioButtonで音色変更
/**
* Copyright nackpan ( http://wonderfl.net/user/nackpan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/h7zt
*/
//SiONで音色を変更
//clickでjump
//radioButtonで音色変更
package {
import flash.display.Sprite;
import com.bit101.components.Label;
import com.bit101.components.RadioButton;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.text.TextField;
import org.si.sion.SiONData;
import org.si.sion.SiONDriver;
import flash.events.Event;
import flash.events.MouseEvent;
import org.si.sion.SiONVoice;
import org.si.sion.utils.SiONPresetVoice;
import flash.display.GradientType;
import flash.display.SpreadMethod;
public class FlashTest extends Sprite {
private var driver:SiONDriver = new SiONDriver();
private var jumpMelody:SiONData;
private var jewelMelody:SiONData;
private var sp:Sprite;
private var jewel:Sprite;
private var jumpStage:Sprite;
private var ground:Sprite;
private var clickFlag:Boolean = false;
private var vx:Number = 0;
private var vy:Number = 0;
private var jumpFlag:Boolean = false;
private var goRightFlag:Boolean = true;
private var count:int = 0;
private var jewelStatus:int = 0;
private var jewelCount:int = 0;
private var loader:Loader;
//
private var presetVoice:SiONPresetVoice;
private var xList0:Array = [50, 130, 200, 270];
private var nameList0:Array = ["Cosmo Lead", "slap bass", "Calm Bell","Clarinet #2 Brighter"];
private var voiceList0:Array = ["valsound.lead4", "valsound.bass34", "valsound.bell1", "valsound.wind2"];
//
private var xList1:Array = [50, 125, 200, 305];
private var nameList1:Array = ["Calm Bell","Harp #2","E.mute Trampet","Clav. coad"];
private var voiceList1:Array = ["valsound.bell1", "valsound.bell7", "valsound.brass2", "valsound.piano3"];
//
private var toneStr:Array = ["valsound.lead4", "valsound.bell1"];
public function FlashTest() {
// write as3 code here..
if (stage) load();
else addEventListener(Event.ADDED_TO_STAGE, load);
}
public function load(e:Event=null):void
{
var url:String = "http://assets.wonderfl.net/images/related_images/f/f7/f771/f771c3c24bfacb2a3ae90070753128bd066fc36c";
var urlReq:URLRequest = new URLRequest( url );
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(urlReq , new LoaderContext(true));
}private function loadComplete(event:Event):void
{
var bmd:BitmapData = new BitmapData(60, 60, true, 0);
var rect:Rectangle = new Rectangle(0, 0, 100, 100);
bmd.draw(loader);
sp = new Sprite();
//addChild(sp);
var bmp:Bitmap = new Bitmap(bmd);
sp.addChild(bmp);
bmp.x = -30;
bmp.y = -30;
init();
}
private function init(e:Event = null):void
{
presetVoice = new SiONPresetVoice();
jumpMelody = driver.compile("#TABLE0{(64,0)12,0};#TABLE1{(90,960)12}; o5 na0,2 np1,2 g2");
jewelMelody = driver.compile("#TABLE0{(128,0)6,0};#TABLE1{(40,600)6}; o6 na0,2 np1,2 c2");
driver.play();
jumpStage = new Sprite();
addChild(jumpStage);
with (jumpStage) {
graphics.clear();
graphics.beginFill(0, 0);
graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
graphics.endFill();
}
ground = new Sprite();
jumpStage.addChild(ground);
with (ground) {
graphics.clear();
graphics.lineStyle(2, 0);
graphics.moveTo(0, 230);
graphics.lineTo(stage.stageWidth, 230);
}
jumpStage.addChild(sp);
sp.x = 200;
sp.y = 200;
jewel = new Sprite();
jumpStage.addChild(jewel);
var fillType:String = GradientType.RADIAL;
var colors:Array = [0xFFFFFF, 0xFFFEFD, 0xFF4444, 0xFE4444, 0xFD4444];
var alphas:Array = [1, 1, 1, 1, 1];
var ratios:Array = [0x00, 0x02, 0xE0, 0xFA, 0xFF];
var matr:Matrix = new Matrix();
matr.createGradientBox(40, 40, 0, -20, -40);
var spreadMethod:String = SpreadMethod.REFLECT;
with (jewel) {
graphics.clear();
graphics.lineStyle(0, 0xff6666);
graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod, "rgb", 0);// .5);
graphics.drawCircle(0, 0, 20 );
graphics.endFill();
}
jewel.x = 300;
jewel.y = 160;
////ボタン
makeBtns("goupJump",300, "JUMP:", xList0, nameList0, voiceList0, toneStr, 0);
makeBtns("groupBall",350, "BALL:", xList1, nameList1, voiceList1, toneStr, 1);
jumpStage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
jumpStage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
addEventListener(Event.ENTER_FRAME, enter);
}
private function makeBtns(groupname:String, y:Number, labelname:String, xlist:Array, nameList:Array, voiceList:Array, toneStr:Array, n:int):void
{
var btns:Sprite = new Sprite();
addChild(btns);
with (btns) {
graphics.clear();
graphics.lineStyle(0, 0);
graphics.moveTo(0, 0);
graphics.lineTo(stage.stageWidth, 0);
graphics.moveTo(0, 30);
graphics.lineTo(stage.stageWidth, 30);
}
btns.x = 0;
btns.y = y;
var label:Label = new Label(btns, 10, 5, labelname);
var rbtn0:RadioButton = new RadioButton(btns, xlist[0], 10, nameList[0], true, function():void { toneStr[n] = voiceList[0];} );
var rbtn1:RadioButton = new RadioButton(btns,xlist[1],10,nameList[1],false, function():void { toneStr[n] = voiceList[1];});
var rbtn2:RadioButton = new RadioButton(btns,xlist[2],10,nameList[2],false, function():void { toneStr[n] = voiceList[2];});
var rbtn3:RadioButton = new RadioButton(btns,xlist[3],10,nameList[3],false, function():void { toneStr[n] = voiceList[3];});
rbtn0.groupName = groupname;
rbtn1.groupName = groupname;
rbtn2.groupName = groupname;
rbtn3.groupName = groupname;
}
private function onDown(event:MouseEvent):void
{
clickFlag = true;
}
private function onUp(event:Event):void
{
clickFlag = false;
}
private function onMove(event:Event):void
{
if (mouseX > sp.x + 20) {
sp.scaleX = 1;
goRightFlag = true;
}
if(mouseX < sp.x - 20){
sp.scaleX = -1;
goRightFlag = false;
}
}
private function enter(event:Event):void
{
if (!jumpFlag) {
if (clickFlag) {
driver.sequenceOn(jumpMelody, presetVoice[toneStr[0]]);
jumpFlag = true;
vy = -20;
}
}else {
vy += 1;
sp.y += vy;
if (sp.y > 200 && vy > 0) {
jumpFlag = false;
sp.y = 200;
}
if (goRightFlag) {
vx = 2;
sp.x += vx;
}else {
vx = -2;
sp.x += vx;
}
}
if (vy < 0 && !clickFlag) {
vy = 0;
}
//jewel.check();
var len:Number = Math.sqrt((sp.x + vx - jewel.x) * (sp.x + vx - jewel.x)
+ (sp.y + vy - jewel.y) * (sp.y + vy - jewel.y));
if (len < 55 && jewelStatus == 0) {
driver.sequenceOn(jewelMelody, presetVoice[toneStr[1]]);
//jewel.visible = false;
jewelStatus = 1;
jewelCount = 0;
}
if (jewelStatus == 1) {
jewelCount++;
if (jewelCount >= 4) {
jewelStatus = 2;
jewel.visible = false;
}
jewel.alpha -= .1;
}
if (jewelStatus == 2) {
jewelCount++;
if(jewelCount >= 30) {
jewel.visible = true;
jewel.alpha = 1;
jewel.x = Math.round(Math.random() * stage.stageWidth);
jewel.y = Math.round(Math.random() * 200);
jewelStatus = 0;
}
}
count++;
}
}
}