_root.kongregateServices.connect();
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.filters.DropShadowFilter;
import flash.filters.GlowFilter;
var card_shadow:DropShadowFilter = new DropShadowFilter(4, 45, 0x000000, .5, 4, 4, 1, 3, false, false, false);
var text_glow:GlowFilter = new GlowFilter(0x000000, .6, 4, 4, 2, 3, false, false);
show_splash();
function show_splash() {
_root.attachMovie("splash","splash",_root.getNextHighestDepth());
splash.blog_button.onRelease = function() {
getURL("http://www.emanueleferonato.com/", "_blank");
};
splash.play_button.onRelease = function() {
play_the_game();
splash.removeMovieClip();
};
splash.how_to_button.onRelease = function() {
show_info();
splash.removeMovieClip();
};
}
function show_info() {
_root.attachMovie("info","info",_root.getNextHighestDepth());
info.play_button.onRelease = function() {
play_the_game();
info.removeMovieClip();
};
info.back_button.onRelease = function() {
show_splash();
info.removeMovieClip();
};
}
function play_the_game() {
big_picture = BitmapData.loadBitmap("cardz");
_root.attachMovie("table","table",_root.getNextHighestDepth());
_root.createEmptyMovieClip("game",_root.getNextHighestDepth());
game.attachMovie("higher","higher",game.getNextHighestDepth());
game.attachMovie("lower","lower",game.getNextHighestDepth());
game.createEmptyMovieClip("big_pic_obj",game.getNextHighestDepth());
big_pic_obj.attachBitmap(big_picture,game.getNextHighestDepth());
big_pic_obj._visible = false;
sequence = new Array();
Array.prototype.shuffle = function() {
for (x=0; x<52; x++) {
var from = Math.floor(Math.random()*52);
var to = this[x];
this[x] = this[from];
this[from] = to;
}
};
for (x=0; x<52; x++) {
card = game.createEmptyMovieClip("small_pic_obj_"+x, game.getNextHighestDepth());
sequence[x] = x;
small_picture = new BitmapData(79, 123);
card.attachBitmap(small_picture,game.getNextHighestDepth());
small_picture.copyPixels(big_picture,new Rectangle(0+(x%13)*79, 0+Math.floor(x/13)*123, 79, 123),new Point(0, 0));
card._visible = false;
card.filters = new Array(card_shadow);
card.onEnterFrame = function() {
switch (this.action) {
case "come" :
this._x += 40;
if (this._x>210) {
this._x = 210;
this.action = "stay";
if (cards_drawn>1) {
game.ok_ko._visible = true;
}
}
break;
case "move" :
this._x += 20;
if (this._x>310) {
this._x = 310;
this.action = "dissolve";
}
break;
case "dissolve" :
this._alpha -= 4;
game.lap_score._alpha -= 4;
if (this._alpha<0) {
can_draw = true;
game.ok_ko._visible = false;
if (cards_drawn == 52) {
endgame();
}
this.removeMovieClip();
}
break;
}
};
}
game.attachMovie("ok_ko","ok_ko",game.getNextHighestDepth(),{_x:250, _y:230, _visible:false});
game.attachMovie("score","score",game.getNextHighestDepth(),{_x:0, _y:140});
game.attachMovie("lap_score","lap_score",game.getNextHighestDepth(),{_x:-50, _y:0, _alpha:0});
game.score.filters = new Array(text_glow);
game.lap_score.filters = new Array(text_glow);
sequence.shuffle();
cards_drawn = 0;
points = 0;
can_draw = true;
draw_card();
game.higher.onRelease = function() {
if (can_draw) {
can_draw = false;
higher = true;
draw_card();
}
};
game.lower.onRelease = function() {
if (can_draw) {
can_draw = false;
higher = false;
draw_card();
}
};
}
function draw_card() {
game.ok_ko.gotoAndStop(2);
lap = 0;
if (((sequence[cards_drawn]%13)<=(sequence[cards_drawn-1]%13) and (!higher)) or ((sequence[cards_drawn]%13)>=(sequence[cards_drawn-1]%13) and (higher))) {
game.ok_ko.gotoAndStop(1);
game.lap_score.lap_text.textColor = 0x40ff40;
if (cards_drawn>0) {
if (!higher) {
lap = 13-(sequence[cards_drawn-1]%13);
}
else {
lap = sequence[cards_drawn-1]%13+1;
}
}
}
else {
lap = -5;
game.lap_score.lap_text.textColor = 0x900000;
}
game.lap_score.lap_text.text = lap;
if (cards_drawn>0) {
game.lap_score._alpha = 100;
}
points += lap;
game["small_pic_obj_"+sequence[cards_drawn]]._x = 0;
game["small_pic_obj_"+sequence[cards_drawn]]._y = 10;
game["small_pic_obj_"+sequence[cards_drawn]]._visible = true;
game["small_pic_obj_"+sequence[cards_drawn]].action = "come";
game["small_pic_obj_"+sequence[cards_drawn-1]].action = "move";
cards_drawn++;
game.score.textscore.text = "Cards left: "+(52-cards_drawn)+" - Score: "+points;
}
function endgame() {
game.removeMovieClip();
_root.attachMovie("game_over","game_over",_root.getNextHighestDepth());
game_over.gameovertext.filters = new Array(text_glow);
game_over.fame.filters = new Array(text_glow);
_root.game_over.gameovertext.text = "Your score: "+points;
_root.kongregateScores.submit(points);
game_over.fame.text = "top five players\n";
var scoresCallback:Function = function (result:Object) {
for (var i:Number = 0; i
game_over.fame.text += result.list[i].username.toLowerCase()+":"+result.list[i].score+"\n";
}
};
_root.kongregateScores.requestList(scoresCallback,this);
game_over.play_button.onRelease = function() {
play_the_game();
game_over.removeMovieClip();
};
}
No comments:
Post a Comment