Skip to content

Commit 35f95fc

Browse files
committed
arbitrarily tall towers can now happen, just need to fix it so that the whole tower deletes when the max height is specified, not just 3
1 parent ee8c36f commit 35f95fc

File tree

3 files changed

+212
-245
lines changed

3 files changed

+212
-245
lines changed

src/Block.as

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
package
2-
{
3-
import flash.utils.Dictionary;
4-
2+
{
53
import org.flixel.*;
64

75
public class Block extends FlxSprite
86
{
97
[Embed(source="assets/green.png")] private var ImgBlock:Class;
10-
private var counter:Number = 0;
8+
9+
private var actionTimer:Number = 0;
1110
public var allBlocks:FlxGroup = new FlxGroup();
1211
public var landed:Boolean = false;
1312
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;
1516

1617
public function Block(X:Number=0, Y:Number=0)
1718
{
1819
super(X, Y, ImgBlock);
1920
immovable = true;
2021
}
21-
22-
22+
2323
public function move(dx:Number,dy:Number):void
2424
{
25-
// dx = dx*frameWidth;
26-
// dy = dy*frameWidth;
27-
2825
if (canMove(dx,dy))
2926
{
3027
x += dx;
@@ -38,9 +35,7 @@ package
3835

3936
public function canMove(dx:Number, dy:Number):Boolean
4037
{
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)
4439
&& x + dx >= 0
4540
&& x + dx <= FlxG.width - 4
4641
&& y + dy <= FlxG.height - 4;
@@ -74,66 +69,49 @@ package
7469
if (doesNotOvelapAt(x, y - frameHeight, allBlocks))
7570
{
7671
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;
7785
}
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;
8787
}
8888

89-
public function isThreeTall():Boolean
89+
public function isMaxTowerHeight():Boolean
9090
{
91-
return ceiling != null && ceiling.ceiling != null;
91+
return towerHeight() == maxTowerHeight;
9292
}
9393

9494
override public function update():void
95-
{
95+
{
96+
trace(towerHeight());
9697

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)
116101
{
117-
counter = 0;
102+
// Yes, reset action timer; steady fall
103+
actionTimer = 0;
118104
move(0,frameHeight);
119105
}
120106
if (!canMove(0,frameHeight))
121107
{
122-
// trace("hit ground");
123108
landed = true;
124109
}
125110
else
126111
{
127112
landed = false;
128113
}
129114
addCeiling();
130-
// trace(ceiling);
131-
132-
// if (isThreeTall())
133-
// {
134-
// isThreeTall = true;
135-
//// trace("three tall");
136-
// }
137115
}
138116
}
139117
}

0 commit comments

Comments
 (0)