~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to app-squix/squix/MiniPuzzleComplete.hx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
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.
 
4
 * </license> 
 
5
 */
 
6
package squix;
 
7
 
 
8
import flash.display.Sprite;
 
9
import mathx.Point2;
 
10
import mathx.MatPoint;
 
11
import mathx.Matrix;
 
12
 
 
13
/**
 
14
 * Implements the animations/logic for ending the level with a completed mini-puzzle
 
15
 */
 
16
class MiniPuzzleComplete extends GameObject
 
17
{
 
18
        var miniPuzzle : MiniPuzzle;    //maintains beyond end of game level
 
19
        var timeout : Float;
 
20
                
 
21
        var board : Matrix<ui.anim.Actor>;
 
22
        
 
23
        var cleared : Bool;     //the board has been cleared completely
 
24
        
 
25
        public function new( game : Game, miniPuzzle : MiniPuzzle )
 
26
        {
 
27
                super( game, GameObject.activeLevelObject );
 
28
                this.miniPuzzle = miniPuzzle;
 
29
                cleared = false;
 
30
                
 
31
                timeout = game.global.puzzleEndTime;
 
32
                game.startLevelEnd();
 
33
                
 
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() )
 
37
                {
 
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 )
 
41
                                );
 
42
                        actor.setVisible( false );
 
43
                        game.corePanel.addActor( actor );       
 
44
                        board.set( mpgi.x, mpgi.y, actor );
 
45
                        
 
46
                        //filter setup
 
47
                        var fil = new Array<flash.filters.BitmapFilter>();
 
48
                        fil.push( 
 
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,
 
53
                                        4, 4,   //blur
 
54
                                        10, //strength
 
55
                                        flash.filters.BitmapFilterQuality.HIGH, //quality
 
56
                                        flash.filters.BitmapFilterType.INNER
 
57
                                        )
 
58
                                );
 
59
                        actor.filters = fil;
 
60
                }
 
61
                doSize();
 
62
                
 
63
                //update stats
 
64
                Options.ifSetLevelStatus( game.curLevel, Options.statusPuzzle );
 
65
                game.numLives+=game.global.puzzleCompleteLivesBonus;
 
66
                
 
67
                flashx.SoundManager.playSound( "puzzleComplete" ); 
 
68
        }
 
69
        
 
70
        override function _stepTime( elapsed : Float )
 
71
        {
 
72
                timeout -= elapsed;
 
73
                if( timeout < 0 )
 
74
                {
 
75
                        game.endLevelEnd();
 
76
                        destroy();
 
77
                }
 
78
                
 
79
                //time relative to overall time
 
80
                var tat = timeout / game.global.puzzleEndTime;
 
81
                
 
82
                //in the middle of the animation we actually clear the surface (producing a revealing effect)
 
83
                if( !cleared && tat < 0.5 )
 
84
                {
 
85
                        cleared = true;
 
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 );
 
90
                }
 
91
                
 
92
                var maxli = board.toLinearIndex( board.size );
 
93
                for( pbti in board.xOrderIter() )
 
94
                {
 
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 );
 
98
                        var at = li / maxli;
 
99
                        
 
100
                        //phase in initially
 
101
                        var inTat = 1 - (tat - 0.5)*2;
 
102
                        if( at < inTat )
 
103
                                actor.setVisible( true );
 
104
                                
 
105
                        //then phase out
 
106
                        var outTat = (0.5 - tat)*2;
 
107
                        if( at < outTat )
 
108
                                actor.setVisible( false );
 
109
                }
 
110
        }
 
111
        
 
112
        function doSize()
 
113
        {
 
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() )
 
118
                {
 
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 ) ); 
 
122
                }
 
123
        }
 
124
        
 
125
        override function destroy()
 
126
        {
 
127
                super.destroy();
 
128
                for( pbti in board.xOrderIter() )
 
129
                        game.corePanel.removeActor( board.get(pbti.x,pbti.y) );
 
130
        }
 
131
}