summaryrefslogtreecommitdiff
path: root/game.bmx
diff options
context:
space:
mode:
Diffstat (limited to 'game.bmx')
-rw-r--r--game.bmx83
1 files changed, 77 insertions, 6 deletions
diff --git a/game.bmx b/game.bmx
index 64bf2d5..d07d1a3 100644
--- a/game.bmx
+++ b/game.bmx
@@ -10,6 +10,59 @@ Import "particle.bmx"
Import "sounds.bmx"
Import "gametypes.bmx"
+Type TBufferedKey
+ Global list:TList
+ Field key:Int
+ Field del:Int
+ Field cnt:Int
+
+ Function Clear()
+ list=CreateList()
+ End Function
+
+ Function Create:TBufferedKey(key:Int, del:Int=30)
+ Local o:TBufferedKey=New TBufferedKey
+ o.key=key
+ o.del=del
+ o.cnt=0
+ list.AddLast(o)
+ Return o
+ End Function
+
+ Function Flush()
+ For Local k:TBufferedKey=EachIn list
+ k.cnt=0
+ Next
+ End Function
+
+ Function Idle()
+ For Local k:TBufferedKey=EachIn list
+ If k.cnt
+ k.cnt:-1
+ EndIf
+ Next
+ End Function
+
+ Method ForceRelease()
+ cnt=999999
+ End Method
+
+ Method Poll:Int()
+ If KeyDown(key)
+ If cnt
+ cnt:-1
+ Return False
+ Else
+ cnt=del
+ Return True
+ EndIf
+ Else
+ cnt=0
+ Return False
+ EndIf
+ End Method
+End Type
+
Type TGame
Field level:Int
Field score:Int
@@ -24,6 +77,11 @@ Type TGame
Field drop:Int
Field fade:TFadeScreen
Field bdrop:TGameBackdrop
+ Field kleft:TBufferedKey
+ Field kright:TBufferedKey
+ Field krotleft:TBufferedKey
+ Field krotright:TBufferedKey
+ Field kdrop:TBufferedKey
Method New()
score=0
@@ -41,6 +99,13 @@ Type TGame
CreateNext(False)
fade=TFadeScreen.FadeIn()
bdrop=New TGameBackdrop
+
+ TBufferedKey.Clear()
+ kleft=TBufferedKey.Create(GameConfig.kleft)
+ kright=TBufferedKey.Create(GameConfig.kright)
+ krotleft=TBufferedKey.Create(GameConfig.krotleft)
+ krotright=TBufferedKey.Create(GameConfig.krotright)
+ kdrop=TBufferedKey.Create(GameConfig.kdrop,1)
End Method
Method SetInitLevel(l:Int)
@@ -117,6 +182,7 @@ Type TGame
SetScale(1,1)
FlushKeys
+ TBufferedKey.Flush()
End Method
Method Play:Int()
@@ -163,30 +229,33 @@ Type TGame
LevelUp()
EndIf
+ kdrop.ForceRelease()
+
If Not gm.overflow
score:+level*2
- CreateNext((total Mod 15)=0) ' 15
+ CreateNext((total Mod 17)=0) ' 17
Else
FlushKeys()
+ TBufferedKey.Flush()
EndIf
EndIf
EndIf
- If KeyHit(GameConfig.kleft)
+ If kleft.Poll()
block.x:-1
If block.Collides(gm)
block.x:+1
EndIf
EndIf
- If KeyHit(GameConfig.kright)
+ If kright.Poll()
block.x:+1
If block.Collides(gm)
block.x:-1
EndIf
EndIf
- If KeyHit(GameConfig.krotright)
+ If krotright.Poll()
block.RotateRight()
If block.Collides(gm)
block.x:-1
@@ -197,7 +266,7 @@ Type TGame
EndIf
EndIf
- If KeyHit(GameConfig.krotleft)
+ If krotleft.Poll()
block.RotateLeft()
If block.Collides(gm)
block.x:+1
@@ -208,10 +277,12 @@ Type TGame
EndIf
EndIf
- If KeyDown(GameConfig.kdrop)
+ If kdrop.Poll()
timer=0
'drop=True
EndIf
+ Else
+ TBufferedKey.Idle()
EndIf
score:+gm.Draw()*level*20