summaryrefslogtreecommitdiff
path: root/game.bmx
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-05-27 23:24:02 +0000
committerIan C <ianc@noddybox.co.uk>2006-05-27 23:24:02 +0000
commit26c98ba56e72beaf8a99eafbedd2b0c64ac13954 (patch)
tree6460c30f185bfdf0647055a9a32af111b8f87894 /game.bmx
parent0129dc56ba73e43f148b779d9ff549f286e66f1d (diff)
UpdatesHEADmaster
Diffstat (limited to 'game.bmx')
-rw-r--r--game.bmx676
1 files changed, 346 insertions, 330 deletions
diff --git a/game.bmx b/game.bmx
index d07d1a3..3857f30 100644
--- a/game.bmx
+++ b/game.bmx
@@ -1,330 +1,346 @@
-' Hardwire
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-Import "types.bmx"
-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
- Field gm:TGameMap
- Field timer:Int
- Field alpha:Double
- Field alphainc:Double
- Field count:Int
- Field total:Int
- Field block:TPiece
- Field nextblock:TPiece
- 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
- gm=New TGameMap
- level=1
- Particles.Clear()
- TextParticles.Clear()
- ExplosionParticles.Clear()
- alpha=0.0
- alphainc=0.01
- count=0
- total=0
- nextblock=TPiece.Create(False)
- drop=False
- 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)
- level=l
- SetTimer()
- End Method
-
- Method SetTimer()
- If drop
- timer=5
- Else
- timer=Max(HERTZ/5,(16-level)*HERTZ/5)
- EndIf
- End Method
-
- Method LevelUp()
- level:+1
- count=0
- End Method
-
- Method CreateNext(special:Int)
- block=nextblock
- block.y=-3
- block.x=Pit.WIDTH/2
- nextblock=TPiece.Create(special)
- nextblock.x=Pit.WIDTH+3
- nextblock.y=1
- drop=False
- End Method
-
- Method Pause()
- Local i:Timage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,MASKEDIMAGE|DYNAMICIMAGE|FILTEREDIMAGE)
-
- GrabImage(i,0,0)
- MidHandleImage(i)
- SetColor(255,255,255)
-
- FlushKeys()
-
- Local a:Int[]=[0,0,0,0,0,0,0,0]
- Local ac:Int[]=[7,6,5,4,3,2,1,0]
-
- While Not KeyHit(GameConfig.kpause)
- Cls
-
- Local al:Double=0.3
-
- For Local f:Int=0 Until a.length
- SetAlpha(al)
- SetRotation(a[f])
- SetScale(al*2,al*2)
- DrawImage(i,GraphicsWidth()/2,GraphicsHeight()/2)
- If ac[f]>0
- ac[f]:-1
- Else
- If f Mod 2
- a[f]:+1
- Else
- a[f]:-1
- EndIf
- EndIf
- al:+0.1
- Next
-
- SetRotation(0)
- SetScale(1,1)
- GameGFX.large.Centre("PAUSED",GraphicsHeight()/2-16)
-
- Flip
- Wend
-
- SetAlpha(1)
- SetRotation(0)
- SetScale(1,1)
-
- FlushKeys
- TBufferedKey.Flush()
- End Method
-
- Method Play:Int()
- Local playing:Int=True
-
- Cls
-
- bdrop.Draw()
-
- GameGFX.large.Draw("SCORE",0,0,255,255,0)
- GameGFX.large.Draw(score,0,20)
-
- GameGFX.large.Draw("LEVEL",0,100,255,255,0)
- GameGFX.large.Draw(level,0,120)
-
- GameGFX.large.Draw("HISCORE",0,200,255,255,0)
- If score>GameConfig.hiscore
- GameConfig.hiscore=score
- EndIf
- GameGFX.large.Draw(GameConfig.hiscore,0,220)
-
- nextblock.Draw()
-
- block.Draw()
-
- If Not gm.overflow
- If KeyHit(KEY_ESCAPE)
- playing=False
- EndIf
-
- If Not gm.BlockInteract()
- timer:-1
-
- If timer<=0
- SetTimer()
- block.y:+1
-
- If block.Collides(gm)
- block.y:-1
- block.AddToMap(gm)
- count:+1
- total:+1
- If count>10
- LevelUp()
- EndIf
-
- kdrop.ForceRelease()
-
- If Not gm.overflow
- score:+level*2
- CreateNext((total Mod 17)=0) ' 17
- Else
- FlushKeys()
- TBufferedKey.Flush()
- EndIf
- EndIf
- EndIf
-
- If kleft.Poll()
- block.x:-1
- If block.Collides(gm)
- block.x:+1
- EndIf
- EndIf
-
- If kright.Poll()
- block.x:+1
- If block.Collides(gm)
- block.x:-1
- EndIf
- EndIf
-
- If krotright.Poll()
- block.RotateRight()
- If block.Collides(gm)
- block.x:-1
- If block.Collides(gm)
- block.x:+1
- block.RotateLeft()
- EndIf
- EndIf
- EndIf
-
- If krotleft.Poll()
- block.RotateLeft()
- If block.Collides(gm)
- block.x:+1
- If block.Collides(gm)
- block.x:-1
- block.RotateRight()
- EndIf
- EndIf
- EndIf
-
- If kdrop.Poll()
- timer=0
- 'drop=True
- EndIf
- Else
- TBufferedKey.Idle()
- EndIf
-
- score:+gm.Draw()*level*20
- Else
- gm.Draw()
-
- SetAlpha(alpha)
- SetColor(255,255,255)
- DrawImage(GameGFX.gameover,GraphicsWidth()/2,GraphicsHeight()/2)
- SetAlpha(1)
- alpha:+alphainc
- If (alpha<=0.7 And alphainc<0) Or (alpha>=1.0 And alphainc>0)
- alpha=Max(0,Min(1,alpha))
- alphainc=-alphainc
- EndIf
-
- If KeyHit(KEY_ENTER) Or KeyHit(KEY_ESCAPE)
- playing=False
- EndIf
- EndIf
-
- Particles.Draw()
- ExplosionParticles.Draw()
- TextParticles.Draw()
-
- If KeyHit(GameConfig.kpause) And Not gm.overflow
- Pause()
- EndIf
-
- Sound.Process()
-
- If fade
- If fade.Fade()
- fade.Draw()
- Else
- fade=Null
- EndIf
- EndIf
-
- Flip
-
- Return playing
- End Method
-End Type
-
+' Hardwire
+'
+' Copyright (C) 2005 Ian Cowburn (ianc@noddybox.co.uk)
+'
+' This program is free software; you can redistribute it and/or modify
+' it under the terms of the GNU General Public License as published by
+' the Free Software Foundation; either version 2 of the License, or
+' (at your option) any later version.
+'
+' This program is distributed in the hope that it will be useful,
+' but WITHOUT ANY WARRANTY; without even the implied warranty of
+' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+' GNU General Public License for more details.
+'
+' You should have received a copy of the GNU General Public License
+' along with this program; if not, write to the Free Software
+' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+'
+' -------------------------------------------------------------------------
+'
+' $Id$
+'
+Strict
+Import "types.bmx"
+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
+ Field gm:TGameMap
+ Field timer:Int
+ Field alpha:Double
+ Field alphainc:Double
+ Field count:Int
+ Field total:Int
+ Field block:TPiece
+ Field nextblock:TPiece
+ 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
+ gm=New TGameMap
+ level=1
+ Particles.Clear()
+ TextParticles.Clear()
+ ExplosionParticles.Clear()
+ alpha=0.0
+ alphainc=0.01
+ count=0
+ total=0
+ nextblock=TPiece.Create(False)
+ drop=False
+ 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)
+ level=l
+ SetTimer()
+ End Method
+
+ Method SetTimer()
+ If drop
+ timer=5
+ Else
+ timer=Max(5,(20-level)*5)
+ EndIf
+ End Method
+
+ Method LevelUp()
+ level:+1
+ count=0
+ End Method
+
+ Method CreateNext(special:Int)
+ block=nextblock
+ block.y=-3
+ block.x=Pit.WIDTH/2
+ nextblock=TPiece.Create(special)
+ nextblock.x=Pit.WIDTH+3
+ nextblock.y=1
+ drop=False
+ End Method
+
+ Method Pause()
+ Local i:Timage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,MASKEDIMAGE|DYNAMICIMAGE|FILTEREDIMAGE)
+
+ GrabImage(i,0,0)
+ MidHandleImage(i)
+ SetColor(255,255,255)
+
+ FlushKeys()
+
+ Local a:Int[]=[0,0,0,0,0,0,0,0]
+ Local ac:Int[]=[7,6,5,4,3,2,1,0]
+
+ While Not KeyHit(GameConfig.kpause)
+ Cls
+
+ Local al:Double=0.3
+
+ For Local f:Int=0 Until a.length
+ SetAlpha(al)
+ SetRotation(a[f])
+ SetScale(al*2,al*2)
+ DrawImage(i,GraphicsWidth()/2,GraphicsHeight()/2)
+ If ac[f]>0
+ ac[f]:-1
+ Else
+ If f Mod 2
+ a[f]:+1
+ Else
+ a[f]:-1
+ EndIf
+ EndIf
+ al:+0.1
+ Next
+
+ SetRotation(0)
+ SetScale(1,1)
+ GameGFX.large.Centre("PAUSED",GraphicsHeight()/2-16)
+
+ Flip
+ Wend
+
+ SetAlpha(1)
+ SetRotation(0)
+ SetScale(1,1)
+
+ FlushKeys
+ TBufferedKey.Flush()
+ End Method
+
+ Method Play:Int()
+ Local playing:Int=True
+
+ Cls
+
+ bdrop.Draw()
+
+ GameGFX.large.Draw("SCORE",0,0,255,255,0)
+ GameGFX.large.Draw(Number.Format(score),0,20)
+
+ GameGFX.large.Draw("LEVEL",0,100,255,255,0)
+ GameGFX.large.Draw(level,0,120)
+
+ GameGFX.large.Draw("HISCORE",0,200,255,255,0)
+ If score>GameConfig.hiscore
+ GameConfig.hiscore=score
+ EndIf
+ GameGFX.large.Draw(Number.Format(GameConfig.hiscore),0,220)
+
+ nextblock.Draw()
+
+ block.Draw()
+
+ If Not gm.overflow
+ If KeyHit(KEY_ESCAPE)
+ playing=False
+ EndIf
+
+ If Not gm.BlockInteract()
+ timer:-1
+
+ If timer<=0
+ SetTimer()
+ block.y:+1
+
+ If block.Collides(gm)
+ block.y:-1
+ block.AddToMap(gm)
+ count:+1
+ total:+1
+ If count>10
+ LevelUp()
+ EndIf
+
+ kdrop.ForceRelease()
+
+ If Not gm.overflow
+ score:+level*2
+ CreateNext((total Mod 17)=0) ' 17
+ Else
+ FlushKeys()
+ TBufferedKey.Flush()
+ EndIf
+ EndIf
+ EndIf
+
+ If kleft.Poll()
+ block.x:-1
+ If block.Collides(gm)
+ block.x:+1
+ EndIf
+ EndIf
+
+ If kright.Poll()
+ block.x:+1
+ If block.Collides(gm)
+ block.x:-1
+ EndIf
+ EndIf
+
+ If krotright.Poll()
+ block.RotateRight()
+ If block.Collides(gm)
+ block.x:-1
+ If block.Collides(gm)
+ block.x:+1
+ block.RotateLeft()
+ EndIf
+ EndIf
+ EndIf
+
+ If krotleft.Poll()
+ block.RotateLeft()
+ If block.Collides(gm)
+ block.x:+1
+ If block.Collides(gm)
+ block.x:-1
+ block.RotateRight()
+ EndIf
+ EndIf
+ EndIf
+
+ If kdrop.Poll()
+ timer=0
+ 'drop=True
+ EndIf
+ Else
+ TBufferedKey.Idle()
+ EndIf
+
+ score:+gm.Draw()*level*20
+ Else
+ gm.Draw()
+
+ SetAlpha(alpha)
+ SetColor(255,255,255)
+ DrawImage(GameGFX.gameover,GraphicsWidth()/2,GraphicsHeight()/2)
+ SetAlpha(1)
+ alpha:+alphainc
+ If (alpha<=0.7 And alphainc<0) Or (alpha>=1.0 And alphainc>0)
+ alpha=Max(0,Min(1,alpha))
+ alphainc=-alphainc
+ EndIf
+
+ If KeyHit(KEY_ENTER) Or KeyHit(KEY_ESCAPE)
+ playing=False
+ EndIf
+ EndIf
+
+ Particles.Draw()
+ ExplosionParticles.Draw()
+ TextParticles.Draw()
+
+ If KeyHit(GameConfig.kpause) And Not gm.overflow
+ Pause()
+ EndIf
+
+ Sound.Process()
+
+ If fade
+ If fade.Fade()
+ fade.Draw()
+ Else
+ fade=Null
+ EndIf
+ EndIf
+
+ Flip
+
+ Return playing
+ End Method
+End Type
+