' Hardwire ' ' Copyright 2005 Ian Cowburn ' ' $Id$ ' Strict Import "types.bmx" Import "particle.bmx" Import "sounds.bmx" Import "gametypes.bmx" Type TGame Field level:Int Field score:Int Field gm:TGameMap Field timer:Int Field alpha:Double Field alphainc:Double Field count:Int Field block:TPiece Field nextblock:TPiece Field drop:Int Method New() score=0 gm=New TGameMap level=1 Particles.Clear() alpha=0.7 alphainc=0.01 count=0 nextblock=TPiece.Create() drop=False CreateNext() 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() block=nextblock block.y=-4 block.x=Pit.WIDTH/2 nextblock=TPiece.Create() 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,al) DrawImage(i,GraphicsWidth()/2,GraphicsHeight()/2) If ac[f]>0 ac[f]:-1 Else a[f]:+1 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 End Method Method Play:Int() Local playing:Int=True Cls GameGFX.large.DrawColoured("SCORE",0,0,255,255,0) GameGFX.large.Draw(score,0,20) GameGFX.large.DrawColoured("LEVEL",0,100,255,255,0) GameGFX.large.Draw(level,0,120) GameGFX.large.DrawColoured("NEXT",Pit.X(Pit.WIDTH+2),Pit.Y(-1),255,255,0) nextblock.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 If count>10 LevelUp() EndIf If Not gm.overflow CreateNext() EndIf EndIf EndIf If KeyHit(GameConfig.kleft) block.x:-1 If block.Collides(gm) block.x:+1 EndIf EndIf If KeyHit(GameConfig.kright) block.x:+1 If block.Collides(gm) block.x:-1 EndIf EndIf If KeyHit(GameConfig.krotright) block.RotateRight() If block.Collides(gm) block.RotateLeft() EndIf EndIf If KeyHit(GameConfig.krotleft) block.RotateLeft() If block.Collides(gm) block.RotateRight() EndIf EndIf If KeyDown(GameConfig.kdrop) timer=0 'drop=True EndIf EndIf block.Draw() score:+gm.Draw()*level*10 Else gm.Draw() SetAlpha(alpha) SetColor(255,255,255) DrawImage(GameGFX.gameover,GraphicsWidth()/2,GraphicsHeight()/2) SetAlpha(1) alpha:+alphainc If alpha<=0.7 Or alpha>=1.0 alpha=Max(0,Min(1,alpha)) alphainc=-alphainc EndIf If KeyHit(KEY_ENTER) Or KeyHit(KEY_ESCAPE) playing=False EndIf EndIf Particles.Draw() If KeyHit(GameConfig.kpause) And Not gm.overflow Pause() EndIf Flip Return playing End Method End Type