forked from: Circular Beat v1.0
forked from Circular Beat v1.0 (diff: 665)
ActionScript3 source code
/**
* Copyright fluxus ( http://wonderfl.net/user/fluxus )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/o73j
*/
// forked from matsu4512's Circular Beat v1.0
package
{
{
{
}
for(var i:int = 0; i < data.length; i++){
var note:Note = data[i];
note.x = 0;
note.y = -R;
note.time = next;
if(key && note.type != "R")timeList.push(note.time);
note.num = i;
note.alpha = 0;
note.scaleX = note.scaleY = 1;
note.display = false;
next += (60*1000/note.t)*(4/note.n);
totalNotes++;
if(note.type == "r") notesR.push(note);
else if(note.type == "b") notesB.push(note);
else if(note.type == "g"){
var note2:Note = new Note("g2", note.n);
note2.x = note.x;
note2.y = note.y;
note2.time = note.time;
notesG.push(note);
notesG.push(note2);
}
else if(note.type == "R"){
if(score < 0) score = 0;
resultView.updateScore(score);
}
//コンボ加算
private function addCombo():void{
combo++;
if(maxCombo < combo) maxCombo = combo;
resultView.updateCombo(combo);
}
//コンボリセット
private function resetCombo():void{
combo = 0;
resultView.updateCombo(combo);
}
//ノートの更新
private function updateNotes(list:Vector.<Note>, delta:Number):void{
var i:int = list.length;
while(i--){
var note:Note = list[i];
note.time -= delta;
if(note.time <= T){
if(!note.display){
if(delay >= 100){
note.time += delay-100;
}
// note.time+=delay;
// trace(delay)
note.display = true;
addChild(note);
note.draw();
}
note.update(Math.PI-Math.PI*note.time/T, R);
if(note.time <= -200){
if(note.type != ""){
bad++;
addScore(-30);
resultView.judge("", "");
resetCombo();
}
removeChild(note);
list.splice(i, 1);
}
}
}
}
//シミュレーターの更新
public function update(delta:Number):void{
if(CircularBeat.gameMode == 1){
if(key){
startTime += delta;
if(startTime >= 2750 && f){
sc.driver.play(musicData.sionData);
f = false;
}
}
updateNotes(notesR, delta);
updateNotes(notesG, delta);
updateNotes(notesB, delta);
if(notesR.length == 0 && notesG.length == 0 && notesB.length == 0){
CircularBeat.gameMode = 2;
resultView.result(score, 100*totalNotes, perfect, great, good, bad);
}
}
}
//判定
public function judge2(list:Vector.<Note>):void{
var ok:Boolean = false;
for(var i:int = 0; i < list.length; i++){
if(Math.abs(list[i].time) <= 150){
if(!key){
if(list[i].type.charAt(0) == "r"){
sc.playData(list[i].t, list[i].note, list[i].n);
}
else if(list[i].type.charAt(0) == "b"){
sc.playData(list[i].t, list[i].note, list[i].n);
}
else if(list[i].type.charAt(0) == "g"){
sc.playData(list[i].t, list[i].note, list[i].n);
}
}
if(Math.abs(list[i].time) <= 40){
perfect++;
glowCircle.glow2(list[i].type.charAt(0));
resultView.judge("", list[i].type.charAt(0));
addScore(100);
addCombo();
}
else if(list[i].time <= 80){
great++;
glowCircle.glow(list[i].type.charAt(0));
resultView.judge("", list[i].type.charAt(0));
addScore(50);
addCombo();
}
else{
good++;
resultView.judge("", list[i].type.charAt(0));
addScore(10);
addCombo();
}
list[i].remove();
if(list[i].type.charAt(0) == "g"){
list[i+1].remove();
list.splice(i, 2);
}
else list.splice(i, 1);
ok = true;
break;
}
}
if(!ok){
bad++;
resultView.judge("", "");
addScore(-30);
resetCombo();
glowCircle.glow("d");
}
}
public function judge(type:int):void{
// trace("push", new Date().getTime())
if(type == 0) judge2(notesR);
else if(type == 1) judge2(notesB);
else if(type == 2) judge2(notesG);
}
}
{
public var f:Boolean = false;
public var n:Number, type:String, time:int, t:int, note:int, v:int;
public var data:SiONData;
public var pos:Number;
public var display:Boolean = false, num:int;
public function Note(type:String, n:int):void{
this.n = n;
this.type = type;
this.pos = 0;
}
public function draw():void{
var c:uint;
if(type == "b") c = 0xFF;
else if(type == "r")c = 0xFF0000;
else c = 0xFF00;
this.filters = [new BlurFilter(2,2,1), new GlowFilter(c, 1, 4, 4, 2, 4)];
graphics.lineStyle(3,0xFFFFFF);
graphics.drawCircle(0,0,8);
graphics.endFill();
alpha = 0;
}
public function remove():void{
var t:ITween = BetweenAS3.to(this, {alpha:0, scaleX:2, scaleY:2}, 0.1);
t.onComplete = onComp;
t.play();
}
private function onComp():void{
parent.removeChild(this);
}
public function update(pos:Number, r:Number):void{
this.pos = pos;
x = Math.cos(pos-Math.PI/2)*r;
y = Math.sin(pos-Math.PI/2)*r;
if(time >= 1800 && time <= 2000) alpha = 1-(time-1800)/200;
if(time < 0) alpha = (200 + time)/200;
if(type == "" || type == "") x *= -1;
}
}
{
private var title:String, score:int, rate:Number, clear:Boolean;
private var titleLabel:Label, scoreLabel:Label, resultLabel:Label, perfectLabel:Label, greatLabel:Label, goodLabel:Label, badLabel:Label, scoreLabel2:Label, scoreRateLabel:Label, clearLabel:Label, comboLabel:Label, maxComboLabel:Label, highScoreLabel:Label;
private var playingSp:Sprite=new Sprite(), resultSp:Sprite=new Sprite();
private var bf:GlowFilter = new GlowFilter(0xFF, 1, 4, 4, 2, 2), gf:GlowFilter = new GlowFilter(0xFF00, 1, 4, 4, 2, 2), rf:GlowFilter = new GlowFilter(0xFF0000, 1, 4, 4, 2, 2);
public function ResultView()
private function createLabel(sp:Sprite, str:String, x:int, y:int):Label{
var label:Label = new Label(sp, x, y, str);
label.textField.textColor = 0xFFFFFF;
return label;
}
public function play(title:String):void{
this.title = title;
titleLabel.textField.text = " "+title;
titleLabel.x = -titleLabel.textField.width/2;
fadeIn(playingSp);
}
public function result(score:int, maxScore:int, perfect:int, great:int, good:int, bad:int):void{
this.score = score;
perfectLabel.text = "" + perfect.toString();
greatLabel.text = " " + great.toString();
goodLabel.text = "" + good.toString();
badLabel.text = "" + bad.toString();
scoreLabel2.text = ": " + score.toString() + "/" + maxScore.toString();
this.rate = score/maxScore;
if(rate < 0.7) clear = false;
else clear = true;
if(rate < 0) rate = 0;
scoreRateLabel.text = "" + (rate*100).toFixed(1) + "%";
clearLabel.alpha = 0;
clearLabel.x = -200;
if(score/maxScore >= 0.7) clearLabel.text = "";
else clearLabel.text = "";
var t:ITween = BetweenAS3.delay(BetweenAS3.to(clearLabel, {x:-clearLabel.width/2, alpha:1}, 0.5), 2.5);
t.onComplete = resultComp;
BetweenAS3.parallel(getTween(perfectLabel, 0.5), getTween(greatLabel, 0.7), getTween(goodLabel, 0.9), getTween(badLabel, 1.1), getTween(scoreLabel2, 1.3), getTween(scoreRateLabel, 1.5), t).play();
if((rate*100) >= 70)
SharedObjectController.saveMusicData(title, 1, score);
else SharedObjectController.saveMusicData(title, 0, score);
fadeOut(playingSp);
fadeIn(resultSp);
}
private function resultComp():void{
CircularBeat.gameMode = 3;
}
private function getTween(label:Label, delay:Number):ITween{
label.alpha = 0;
label.x = -200;
return BetweenAS3.delay(BetweenAS3.to(label, {alpha:1, x:-100}, 0.5), delay);
}
public function updateScore(score:int):void{
scoreLabel.text = ""+score.toString();
}
public function updateCombo(combo:int):void{
if(combo > 1){
comboLabel.visible = true;
comboLabel.text = combo.toString() + " ";
comboLabel.x = -comboLabel.width/2;
}
else comboLabel.visible = false;
}
private function fadeIn(sp:Sprite):void{
sp.alpha = 0;
sp.visible = true;
BetweenAS3.to(sp, {alpha:1}, 1).play();
}
private function fadeOut(sp:Sprite):void{
var t:ITween = BetweenAS3.to(sp, {alpha:0}, 1);
t.play();
}
public function fadeOutAll():void{
fadeOut(playingSp);
fadeOut(resultSp);
}
public function judge(string:String, color:String):void{
var sp:Sprite = new Sprite();
var tf:TextField = new TextField();
if(color == "r") tf.filters = [rf];
else if(color == "b") tf.filters = [bf];
else if(color == "g") tf.filters = [gf];
sp.addChild(tf);
tf.autoSize = TextFieldAutoSize.LEFT;
tf.defaultTextFormat = new TextFormat(null, 24);
tf.textColor = 0xFFFFFF;
tf.text = string;
tf.x = -tf.textWidth/2;
tf.y = -tf.textHeight/2;
sp.alpha = 0;
sp.scaleX = sp.scaleY = 0.5;
addChild(sp);
sp.y = 150;
var t:ITween = BetweenAS3.to(sp, {alpha:0.8, scaleX:1, scaleY:1}, 0.2);
t.onComplete = function(tf:TextField):void{removeChild(sp);};
t.onCompleteParams = [tf];
t.play();
}
}
{
public static function getMusicData(name:String):Object{
var shareObj:SharedObject = SharedObject.getLocal("");
if(shareObj.data.musicData == undefined){
shareObj.data.musicData = {};
shareObj.data.musicData[name] = {clear:-1, score:0};
}
else if(shareObj.data.musicData[name] == undefined){
shareObj.data.musicData[name] = {clear:-1, score:0};
}
return shareObj.data.musicData[name];
}
public static function saveMusicData(name:String, clear:int, score:int):Boolean{
var shareObj:SharedObject = SharedObject.getLocal("");
var res:Boolean = shareObj.data.musicData[name].score < score;
shareObj.data.musicData[name].clear = Math.max(shareObj.data.musicData[name].clear, clear);
shareObj.data.musicData[name].score = Math.max(shareObj.data.musicData[name].score, score);
return res;
}
}
{
}
}
}