From 0129dc56ba73e43f148b779d9ff549f286e66f1d Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 17 Dec 2005 00:20:47 +0000 Subject: Improved collapsing of spaces in game map --- gametypes.bmx | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'gametypes.bmx') diff --git a/gametypes.bmx b/gametypes.bmx index 772b9e3..24d1617 100644 --- a/gametypes.bmx +++ b/gametypes.bmx @@ -839,36 +839,41 @@ Type TGameMap special=s End Method - Method FlattenColumn(x:Int, y:Int) - Local diff:Int=0 - - For Local cy:Int=y-1 To 0 Step -1 - If map[x,cy] - diff=y-cy - Exit + Method DropColumn(x:Int, y:Int) + While y>0 + map[x,y]=map[x,y-1] + y:-1 + Wend + map[x,0]=Null + End Method + + Method AnyAbove:Int(x:Int, y:Int) + While y>=0 + If map[x,y] + Return True EndIf - Next - - If diff - For Local cy:Int=y To diff Step -1 - map[x,cy]=map[x,cy-diff] - Next - For Local cy:Int=diff To 0 Step -1 - map[x,cy]=Null - Next - EndIf + y:-1 + Wend - Return diff + Return False End Method Method Flatten() For Local x:Int=0 Until Pit.WIDTH - For Local y:Int=Pit.HEIGHT-1 To 1 Step -1 - If Not map[x,y] And FlattenColumn(x,y) - Particles.AddDust(Pit.X(x)+16,Pit.Y(y)+32) - Sound.Click() + Local y:Int=Pit.HEIGHT-1 + Local drop:Int=False + + While y>0 And AnyAbove(x,y) + If map[x,y] + If drop + Particles.AddDust(Pit.X(x)+16,Pit.Y(y)+32) + EndIf + drop=False + y:-1 + Else + DropColumn(x,y) EndIf - Next + Wend Next End Method -- cgit v1.2.3