' Particle Pinch ' ' Copyright 2005 Ian Cowburn ' ' $Id$ ' Strict Import noddybox.vector Import noddybox.bitmapfont Import "types.bmx" Import "level.bmx" Type TGame Const LEVEL_NOTOVER:Int= 0 Const LEVEL_WON:Int= 1 Const LEVEL_LOST:Int= 2 Const LEVEL_FINISHED:Int= 3 Const LEVEL_CANCELLED:Int= 4 Field level:TLevel Field ship:TShip 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 Field final_percent:Int Field pass_time:Int Function Create:TGame(level:TLevel) Local o:TGame=New TGame o.level=level o.mass=CreateList() o.point=CreateList() o.ship=o.level.CreatePlayfield(o.mass,o.point) o.mass.AddLast(o.ship) 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("TIMER"),GameGFX.font.TextWidth("WAVES")] o.playing=False o.col=0 o.coli=5 o.final_percent=0 o.pass_time=0 TParticleMachine.Clear() FlushKeys() Return o End Function Method LabelMass(m:TMass) Local x:Int=m.x Local y:Int=m.y Local tx:Int Local lx:Int Local ty:Int Local ly:Int Local s:String Local l:Int If m.inverse s="-"+Int(m.mass)+" NEWTONS" Else s=Int(m.mass)+" NEWTONS" EndIf If m.friend s="COLLECTOR: " + s Else s="MASS: " + s EndIf l=GameGFX.smallfont.TextWidth(s) ly=y ty=Max(0,Min(GraphicsHeight()-GameGFX.smallfont.MaxHeight(),y-3)) If x1 GameGFX.font.Centre("You can fire "+level.maxwave+" Gravity Waves of " + w + " Newtons",y,col/2,col,col) ElseIf level.maxwave=1 GameGFX.font.Centre("You can fire 1 Gravity Wave of " + w + " Newtons",y,col/2,col,col) EndIf y:+yi If level.wrap GameGFX.font.Centre("THE UNIVERSE IS WARPED!",y,col,col/2,col/2) y:+yi EndIf y:+yi GameGFX.font.Centre("Press Space",y) y:+yi SetScale(1,1) End Method Method Play:Int() captured=0 lost=0 If playing If done=LEVEL_NOTOVER If KeyDown(GameConfig.kleft) ship.RotateLeft() EndIf If KeyDown(GameConfig.kright) ship.RotateRight() EndIf If KeyDown(GameConfig.kthrust) ship.Thrust() EndIf If KeyDown(GameConfig.kreverse) ship.Reverse() EndIf If KeyHit(GameConfig.kblast) And placed0 frame=0 timer:-1 EndIf EndIf Local percent:Int If done<>LEVEL_NOTOVER percent=final_percent Else percent:Int=Int(Double(captured)/Double(num)*100.0) If percent>=level.winpercent And pass_time=0 pass_time=timer EndIf Local lostpercent:Int=Int(Double(lost)/Double(num)*100.0) If lostpercent>(101-level.winpercent) done=LEVEL_LOST FlushKeys() final_percent=percent EndIf EndIf If (timer=0 Or num=captured+lost) And done=LEVEL_NOTOVER final_percent=percent If percent>=level.winpercent done=LEVEL_WON Else done=LEVEL_LOST EndIf FlushKeys() EndIf GameGFX.font.Draw("PARTICLES",0,0) GameGFX.font.Draw(num-captured-lost,txtoff[0]+10,0,255,255,0) GameGFX.font.Draw("CAPTURED",200,0) If percent10 GameGFX.font.Draw(timer,txtoff[2]+610,0) Else GameGFX.font.Draw(timer,txtoff[2]+610,0,255,0,0) EndIf Select done Case LEVEL_NOTOVER If playing Rem If placed