diff options
Diffstat (limited to 'game.bmx')
-rw-r--r-- | game.bmx | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/game.bmx b/game.bmx new file mode 100644 index 0000000..cc5a8b9 --- /dev/null +++ b/game.bmx @@ -0,0 +1,171 @@ +' Particle Pinch +' +' Copyright 2005 Ian Cowburn +' +' $Id$ +' +Strict +Import noddybox.vector +Import noddybox.bitmapfont +Import "types.bmx" +Import "level.bmx" + +Const LEVEL_NOTOVER:Int= 0 +Const LEVEL_WON:Int= 1 +Const LEVEL_LOST:Int= 2 + +Type TGame + + Field level:TLevel + Field mass:TList + Field point:TList + Field timer:Int + Field num:Int + Field lost:Int + Field captured:Int + Field done:Int + Field frame:Int + Field placed:Int + Field txtoff:Int[] + Field playing:Int + Field col:Int + Field coli:Int + + Function Create:TGame(level:TLevel) + Local o:TGame=New TGame + + o.level=level + o.mass=CreateList() + o.point=CreateList() + o.level.CreatePlayfield(o.mass,o.point) + o.timer=o.level.timer + o.num=o.point.Count() + o.done=LEVEL_NOTOVER + o.frame=0 + o.placed=0 + o.txtoff=[GameGFX.font.TextWidth("PARTICLES"),GameGFX.font.TextWidth("CAPTURED"),GameGFX.font.TextWidth("LOST"),GameGFX.font.TextWidth("TIMER")] + o.playing=False + o.col=0 + o.coli=1 + Return o + End Function + + Method Intro() + Local y:Int=GraphicsHeight()/4 + Local yi:Int=25 + col:+coli + + If col=255 Or col=128 + coli=-coli + EndIf + + SetScale(2,2) + + GameGFX.font.CentreColoured(level.name,y,col,col,255-col) + y:+yi + + GameGFX.font.CentreColoured("Need "+level.winpercent+"% to clear",GraphicsHeight()/2,col/2,col,col) + y:+yi + + GameGFX.font.CentreColoured("You can place "+level.maxmass+" masses",GraphicsHeight()/2,col/2,col,col) + y:+yi + + If level.invmass + GameGFX.font.CentreColoured("PLACED MASSES ARE INVERTED!",y,col,col/2,col/2) + y:+yi + EndIf + + SetScale(1,1) + End Method + + Method Play:Int() + captured=0 + lost=0 + + For Local m:TMass=EachIn mass + For Local s:TPoint=EachIn point + s.Attract(m) + Next + Next + + TParticleMachine.Process() + + For Local m:TMass=EachIn mass + m.MoveAndDraw() + Next + + For Local s:TPoint=EachIn point + s.MoveAndDraw() + + If s.dead + captured:+1 + ElseIf s.lost + lost:+1 + EndIf + Next + + frame:+1 + + If frame=60 And timer>0 + timer:-1 + EndIf + + Local percent:Int=Int(Float(captured)/Float(num)*100.0) + + If (timer=0 Or num=0) And done=LEVEL_NOTOVER + If percent>=level.winpercent + done=LEVEL_WON + Else + done=LEVEL_LOST + EndIf + EndIf + + GameGFX.font.Draw("PARTICLES",0,0) + GameGFX.font.DrawColoured(num-captured-lost,txtoff[0]+10,0,255,255,0) + GameGFX.font.Draw("CAPTURED",200,0) + GameGFX.font.DrawColoured(percent+"%",txtoff[1]+210,0,255,0,255) + GameGFX.font.Draw("LOST",400,0) + GameGFX.font.DrawColoured((100-percent)+"%",txtoff[2]+410,0,255,0,0) + + GameGFX.font.Draw("TIMER",600,0) + + If timer>10 + GameGFX.font.Draw(timer,txtoff[3]+610,0) + Else + GameGFX.font.DrawColoured(timer,txtoff[3]+610,0,255,0,0) + EndIf + + Select done + Case LEVEL_NOTOVER + If playing + If placed<level.maxmass And mass.Count()<MAX_GRAV + If MouseHit(1) + Local m:TMass=New TMass + m.friend=False + m.inverse=level.invmass + m.x=MouseX() + m.y=MouseY() + m.img=GameGFX.mass + mass.AddLast(m) + EndIf + EndIf + Else + Intro() + If MouseHit(1) + playing=True + EndIf + EndIf + Case LEVEL_WON + SetScale(2,2) + GameGFX.font.CentreColoured("LEVEL COMPLETED!",GraphicsHeight()/2,255,255,0) + SetScale(1,1) + Case LEVEL_LOST + SetScale(2,2) + GameGFX.font.CentreColoured("LEVEL FAILED!",GraphicsHeight()/2,255,64,64) + SetScale(1,1) + EndSelect + + Return done + End Method + +End Type
\ No newline at end of file |