summaryrefslogtreecommitdiff
path: root/global.bmx
diff options
context:
space:
mode:
Diffstat (limited to 'global.bmx')
-rw-r--r--global.bmx274
1 files changed, 274 insertions, 0 deletions
diff --git a/global.bmx b/global.bmx
new file mode 100644
index 0000000..f2c92c0
--- /dev/null
+++ b/global.bmx
@@ -0,0 +1,274 @@
+' Missile Lock
+'
+' Copyright (C) 2006 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 brl.pngloader
+
+Import noddybox.bitmapfont
+Import noddybox.gfxmenu
+
+
+' Included binaries
+'
+Incbin "GFX/font.bmf"
+
+Incbin "GFX/title.png"
+Incbin "GFX/ship.png"
+Incbin "GFX/missile.png"
+Incbin "GFX/exhaust.png"
+Incbin "GFX/flame.png"
+
+Const HERTZ:Int=70
+
+Type Lookup
+ Global si:Double[]
+ Global co:Double[]
+
+ Function Init()
+ si=New Double[3600]
+ co=New Double[3600]
+
+ For Local a:Double=0 To 3599
+ si[a]=Sin(a/10.0)
+ co[a]=Cos(a/10.0)
+ Next
+ End Function
+End Type
+
+
+Type GFX
+ Global font:TBitmapFont
+
+ Global title:TImage
+
+ Global ship:TImage
+ Global missile:TImage
+ Global exhaust:TImage
+ Global flame:TImage
+
+ Function SafeLoadImage:TImage(p:String, mode:Int)
+ Local i:TImage=LoadImage(p,mode)
+ Assert i,"Failed to load " + p
+ Return i
+ End Function
+
+ Function SafeLoadAnimImage:TImage(p:String, w:Int, h:Int, f:Int, c:Int, mode:Int)
+ Local i:TImage=LoadAnimImage(p,w,h,f,c,mode)
+ Assert i,"Failed to load " + p
+ Return i
+ End Function
+
+ Function Init()
+ font=TBitmapFont.Load("incbin::GFX/font.bmf",0)
+
+ Assert font,"Failed to load incbin::GFX/font.bmf"
+
+ title=SafeLoadImage("incbin::GFX/title.png",0)
+
+ ship=SafeLoadImage("incbin::GFX/ship.png",0)
+ flame=SafeLoadImage("incbin::GFX/flame.png",0)
+ MidHandleImage(ship)
+ MidHandleImage(flame)
+
+ missile=SafeLoadImage("incbin::GFX/missile.png",0)
+ exhaust=SafeLoadImage("incbin::GFX/exhaust.png",FILTEREDIMAGE)
+ SetImageHandle(missile,3,7)
+ SetImageHandle(exhaust,3,3)
+ End Function
+End Type
+
+Type GameConfig
+ Global kleft:Int
+ Global kright:Int
+ Global kpause:Int
+ Global kfire:Int
+ Global hiscore:Int
+
+ Function Load()
+ Local s:TStream=ReadStream("mlock.config")
+
+ If s=Null
+ kleft=KEY_LEFT
+ kright=KEY_RIGHT
+ kfire=KEY_SPACE
+ kpause=KEY_P
+ hiscore=0
+ Return
+ EndIf
+
+ s=LittleEndianStream(s)
+
+ kleft=s.ReadInt()
+ kright=s.ReadInt()
+ kfire=s.ReadInt()
+ kpause=s.ReadInt()
+ hiscore=s.ReadInt()
+
+ s.Close()
+ End Function
+
+ Function Save()
+ Local s:TStream=WriteStream("mlock.config")
+
+ If s=Null
+ Return
+ EndIf
+
+ s=LittleEndianStream(s)
+
+ s.WriteInt(kleft)
+ s.WriteInt(kright)
+ s.WriteInt(kfire)
+ s.WriteInt(kpause)
+ s.WriteInt(hiscore)
+
+ s.Close()
+ End Function
+EndType
+
+Type TEasyLink
+ Field l:TLink
+
+ Function Create:TEasyLink(l:TList)
+ Local o:TEasyLink=New TEasyLink
+ o.l=l.FirstLink()
+ Return o
+ End Function
+
+ Method Value:Object()
+ If l
+ Return l.Value()
+ Else
+ Return Null
+ EndIf
+ End Method
+
+ Method MoveNext()
+ If l
+ l=l.NextLink()
+ EndIf
+ End Method
+
+ Method Remove()
+ Local ol:TLink=l
+ MoveNext()
+ ol.Remove()
+ End Method
+End Type
+
+
+Type Scroller
+ Global msg:String
+ Global msgp:Int
+ Global msgx:Int
+ Global msgy:Int
+
+ Function Init()
+ msg=" "
+ msg=" "
+ msg:+"TAKE THE LAST REMAINING STAR-FIGHTER AND USE SKILL AND JUDGEMENT TO AVOID THE DEADLY MISSILES THE EVIL ALIENS ARE FIRING AT YOU WHILE "
+ msg:+"DESTROYING THEIR ADVANCING FLEET... "
+ msg:+"SHOW HEART YOUNG PILOT, THE EARTH IS DEPENDING UPON YOU!"
+
+ msgx=-400
+ msgp=0
+ msgy=560-300
+ End Function
+
+ Function Draw()
+ GFX.font.Draw(msg[..70],msgx,msgy)
+
+ msgx:-2
+ If msgx<-(GFX.font.TextWidth(msg[0..1])+400)
+ msgx:+GFX.font.TextWidth(msg[0..1])
+ msg=msg[1..]+msg[0..1]
+ EndIf
+ End Function
+End Type
+
+Type TFadeScreen
+ Field a:Double
+ Field ai:Double
+
+ Function Create:TFadeScreen(a:Double, ai:Double)
+ Local o:TFadeScreen=New TFadeScreen
+ o.a=a
+ o.ai=ai
+ Return o
+ End Function
+
+ Function FadeOut:TFadeScreen()
+ Return Create(0,0.05)
+ End Function
+
+ Function FadeIn:TFadeScreen()
+ Return Create(1,-0.05)
+ End Function
+
+ Function DoFadeOut()
+ Local fade:TFadeScreen=TFadeScreen.FadeOut()
+ Local pm:TPixmap=GrabPixmap(0,0,GraphicsWidth(),GraphicsHeight())
+
+ While fade.Fade()
+ Cls
+ DrawPixmap(pm,0,0)
+ fade.Draw()
+ Flip
+ Wend
+ End Function
+
+ Method Fade:Int()
+ a:+ai
+ Return a>0 And a<1
+ End Method
+
+ Method Draw()
+ Local r:Int,g:Int,b:Int
+ Local x:Float,y:Float
+ Local oa:Double=GetAlpha()
+ GetColor(r,g,b)
+ GetOrigin(x,y)
+ SetAlpha(a)
+ SetColor(0,0,0)
+ DrawRect(-x,-y,GraphicsWidth(),GraphicsHeight())
+ SetColor(r,g,b)
+ SetAlpha(oa)
+ End Method
+End Type
+
+
+Type Number
+ Function Format:String(num:Int)
+ Local c:Int=0
+ Local ret:String=""
+ Local a:String=String.FromInt(num)
+
+ For Local f:Int=a.length-1 To 0 Step -1
+ If ret.length And (c Mod 3)=0
+ ret=","+ret
+ EndIf
+ ret=a[f..f+1]+ret
+ c:+1
+ Next
+ Return ret
+ End Function
+End Type