~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to app-squix/squix/EdgeTimer.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
/**
 
9
 * Counts down to the creation of a new EdgeWalker.
 
10
 * This game object is not visible, something else must
 
11
 * show the time
 
12
 */
 
13
class EdgeTimer extends GameObject
 
14
{
 
15
        public var timeAt( default, null ) : Float;
 
16
        public var timeTo( default, null ) : Float;
 
17
        
 
18
        var edgeCW : Int;
 
19
        var active : Bool;
 
20
        var profile : Int;
 
21
        
 
22
        public function new( game : Game )
 
23
        {
 
24
                super( game );
 
25
                
 
26
                profile = game.global.numEdgeMonsters;  //start at next starting point from initial monsters
 
27
                game.edgeTimer = this;
 
28
                edgeCW = GridUtil.cClockwise;
 
29
                resetTimer();
 
30
                
 
31
                active = true;
 
32
                game.addEventListener( GameEvent.GameOver, onGameOver );
 
33
                game.addEventListener( GameEvent.NewLevel, onNewLevel );
 
34
        }
 
35
        
 
36
        override function onGameOver( ge : GameEvent )
 
37
        {
 
38
                active = false;
 
39
                timeAt = 0;
 
40
        }
 
41
        
 
42
        function onNewLevel( ge : GameEvent )
 
43
        {
 
44
                timeAt = 0;
 
45
        }
 
46
        
 
47
        override function _stepTime( elapsed : Float )
 
48
        {
 
49
                timeAt += elapsed;
 
50
                if( timeAt < timeTo )
 
51
                        return;
 
52
                        
 
53
                new EdgeMonster( game, profile++ );
 
54
                flashx.SoundManager.playSound( "eyesEnter" ); 
 
55
                resetTimer();
 
56
        }
 
57
        
 
58
        function resetTimer()
 
59
        {
 
60
                timeAt = 0;
 
61
                timeTo = game.global.edgeMonsterCreateTime;
 
62
                edgeCW = GridUtil.reverseCW( edgeCW );
 
63
        }
 
64
        
 
65
        override function destroy()
 
66
        {
 
67
                super.destroy();
 
68
                Assert.isTrue( game.edgeTimer == this );
 
69
                game.edgeTimer = null;
 
70
                game.removeEventListener( GameEvent.GameOver, onGameOver );
 
71
                game.removeEventListener( GameEvent.NewLevel, onNewLevel );
 
72
        }
 
73
}
 
 
b'\\ No newline at end of file'