2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
8
import flash.display.Sprite;
10
import mathx.MatPoint;
14
* Implements the animations/logic for ending the level with a completed mini-puzzle
16
class MiniPuzzleComplete extends GameObject
18
var miniPuzzle : MiniPuzzle; //maintains beyond end of game level
21
var board : Matrix<ui.anim.Actor>;
23
var cleared : Bool; //the board has been cleared completely
25
public function new( game : Game, miniPuzzle : MiniPuzzle )
27
super( game, GameObject.activeLevelObject );
28
this.miniPuzzle = miniPuzzle;
31
timeout = game.global.puzzleEndTime;
34
//TODO: taken from PuzzleBoard, could it be combined?
35
board = Matrix.create( miniPuzzle.grid.size.x, miniPuzzle.grid.size.y, null );
36
for( mpgi in miniPuzzle.grid.xOrderIter() )
38
var mpg = miniPuzzle.grid.get( mpgi.x, mpgi.y );
39
var actor = new ui.anim.lib.PuzzlePiece(
40
ui.anim.lib.PuzzlePiece.decodePiece( mpg.code )
42
actor.setVisible( false );
43
game.corePanel.addActor( actor );
44
board.set( mpgi.x, mpgi.y, actor );
47
var fil = new Array<flash.filters.BitmapFilter>();
49
new flash.filters.BevelFilter(
50
5, 30, //tODO: should be done in resize where the sizes are known
51
draw.Color.rgb( 0.5,1,0 ).asInt(), 1,
52
draw.Color.rgb( 0, 0.5, 0).asInt(), 1,
55
flash.filters.BitmapFilterQuality.HIGH, //quality
56
flash.filters.BitmapFilterType.INNER
64
Options.ifSetLevelStatus( game.curLevel, Options.statusPuzzle );
65
game.numLives+=game.global.puzzleCompleteLivesBonus;
67
flashx.SoundManager.playSound( "puzzleComplete" );
70
override function _stepTime( elapsed : Float )
79
//time relative to overall time
80
var tat = timeout / game.global.puzzleEndTime;
82
//in the middle of the animation we actually clear the surface (producing a revealing effect)
83
if( !cleared && tat < 0.5 )
86
var dc = new Sprite();
87
dc.graphics.beginFill( 0 );
88
dc.graphics.drawRect( 0, 0, game.surface.width, game.surface.height );
89
game.clearSurface( dc );
92
var maxli = board.toLinearIndex( board.size );
93
for( pbti in board.xOrderIter() )
95
//get a proportional index of the piece to compare to time
96
var actor = board.get(pbti.x,pbti.y);
97
var li = board.toLinearIndex( pbti );
101
var inTat = 1 - (tat - 0.5)*2;
103
actor.setVisible( true );
106
var outTat = (0.5 - tat)*2;
108
actor.setVisible( false );
114
//position is always 0,0
115
var pw = game.surface.width / board.size.x;
116
var ph = game.surface.height / board.size.y;
117
for( pbti in board.xOrderIter() )
119
var actor = board.get(pbti.x,pbti.y);
120
game.corePanel.placeActor( actor, Point2.at( pw * (pbti.x+0.5), ph * (pbti.y+0.5) ) );
121
game.corePanel.sizeActor( actor, Point2.at( pw, ph ) );
125
override function destroy()
128
for( pbti in board.xOrderIter() )
129
game.corePanel.removeActor( board.get(pbti.x,pbti.y) );