1
1
package
2
- {
3
- import flash.utils.Dictionary ;
4
-
2
+ {
5
3
import org.flixel.* ;
6
4
7
5
public class Block extends FlxSprite
8
6
{
9
7
[Embed (source="assets/green.png" )] private var ImgBlock: Class ;
10
- private var counter: Number = 0 ;
8
+
9
+ private var actionTimer: Number = 0 ;
11
10
public var allBlocks: FlxGroup = new FlxGroup();
12
11
public var landed: Boolean = false ;
13
12
public var ceiling: Block = null ;
14
- // public var isThreeTall:Boolean = false;
13
+ public var maxTowerHeight: Number = 5 ;
14
+ public var curTowerHeight: Number = 1 ;
15
+ public var tower: FlxGroup = new FlxGroup;
15
16
16
17
public function Block (X :Number = 0 , Y :Number = 0 )
17
18
{
18
19
super (X , Y , ImgBlock);
19
20
immovable = true ;
20
21
}
21
-
22
-
22
+
23
23
public function move (dx :Number ,dy :Number ):void
24
24
{
25
- // dx = dx*frameWidth;
26
- // dy = dy*frameWidth;
27
-
28
25
if (canMove(dx,dy))
29
26
{
30
27
x += dx;
@@ -38,9 +35,7 @@ package
38
35
39
36
public function canMove (dx :Number , dy :Number ):Boolean
40
37
{
41
- // trace(x+dx >=0, x+dx <= FlxG.width - 4, y + dy <= FlxG.height - 4, !overlapsAt(x + dx, y + dy, allBlocks));
42
-
43
- return doesNotOvelapAt(x + dx, y + dy, allBlocks)//!overlapsAt(x + dx, y + dy, allBlocks)
38
+ return doesNotOvelapAt(x + dx, y + dy, allBlocks)
44
39
&& x + dx >= 0
45
40
&& x + dx <= FlxG. width - 4
46
41
&& y + dy <= FlxG. height - 4 ;
@@ -74,66 +69,49 @@ package
74
69
if (doesNotOvelapAt(x , y - frameHeight, allBlocks))
75
70
{
76
71
ceiling = null ;
72
+ }
73
+ }
74
+
75
+ public function towerHeight ():Number
76
+ {
77
+ return towerHeightHelper(this ,curTowerHeight);
78
+ }
79
+
80
+ public function towerHeightHelper (block :Block ,height :Number ):Number
81
+ {
82
+ if (block. ceiling == null )
83
+ {
84
+ return 1 ;
77
85
}
78
- // if (doesNotOverlapAt(x,y - frameHeight,allBlocks))
79
- // {
80
- // ceiling = null;
81
- // }
82
- // if (doesNotOverlapAt(x, y + frameHeight, allBlocks))
83
- // {
84
- // ceiling = null;
85
- // }
86
-
86
+ return towerHeightHelper(block. ceiling,block. ceiling. curTowerHeight) + curTowerHeight;
87
87
}
88
88
89
- public function isThreeTall ():Boolean
89
+ public function isMaxTowerHeight ():Boolean
90
90
{
91
- return ceiling != null && ceiling . ceiling != null ;
91
+ return towerHeight() == maxTowerHeight ;
92
92
}
93
93
94
94
override public function update ():void
95
- {
95
+ {
96
+ trace (towerHeight());
96
97
97
- // var i:String;
98
- // var block:Block;
99
- // var shouldAdd:Boolean = true;
100
- // for (i in allBlocks.members)
101
- // {
102
- // if (block == allBlocks.members[i])
103
- // {
104
- // trace("a match");
105
- // shouldAdd = false;
106
- // }
107
- // }
108
- // if (shouldAdd)
109
- // {
110
- // trace("adding me");
111
- // allBlocks.add(this);
112
- // }
113
-
114
- counter += FlxG. elapsed;
115
- if (counter >= 0.5 )
98
+ actionTimer += FlxG. elapsed;
99
+ // Should action timer reset?
100
+ if (actionTimer >= 0.5 )
116
101
{
117
- counter = 0 ;
102
+ // Yes, reset action timer; steady fall
103
+ actionTimer = 0 ;
118
104
move (0 ,frameHeight);
119
105
}
120
106
if (! canMove(0 ,frameHeight))
121
107
{
122
- // trace("hit ground");
123
108
landed = true ;
124
109
}
125
110
else
126
111
{
127
112
landed = false ;
128
113
}
129
114
addCeiling();
130
- // trace(ceiling);
131
-
132
- // if (isThreeTall())
133
- // {
134
- // isThreeTall = true;
135
- //// trace("three tall");
136
- // }
137
115
}
138
116
}
139
117
}
0 commit comments