From 6de8d28ffb5da5c4ac7260b467dd5afc85286fde Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 18 Apr 2006 18:39:41 +0000 Subject: Initial Import --- .cvsignore | 4 + GFX/exhaust.png | Bin 0 -> 171 bytes GFX/flame.png | Bin 0 -> 172 bytes GFX/font.bmf | Bin 0 -> 92500 bytes GFX/missile.png | Bin 0 -> 192 bytes GFX/ship.png | Bin 0 -> 221 bytes GFX/sprites.bms | Bin 0 -> 2911 bytes GFX/title.png | Bin 0 -> 15749 bytes gametypes.bmx | 86 +++++++++++++++++ global.bmx | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ missile_lock.bmx | 238 +++++++++++++++++++++++++++++++++++++++++++++++ particle.bmx | 130 ++++++++++++++++++++++++++ 12 files changed, 732 insertions(+) create mode 100644 .cvsignore create mode 100644 GFX/exhaust.png create mode 100644 GFX/flame.png create mode 100644 GFX/font.bmf create mode 100644 GFX/missile.png create mode 100644 GFX/ship.png create mode 100644 GFX/sprites.bms create mode 100644 GFX/title.png create mode 100644 gametypes.bmx create mode 100644 global.bmx create mode 100644 missile_lock.bmx create mode 100644 particle.bmx diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..63482b4 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,4 @@ +*.exe +.bmx +mlock.config +mlock.hiscore diff --git a/GFX/exhaust.png b/GFX/exhaust.png new file mode 100644 index 0000000..ebc91aa Binary files /dev/null and b/GFX/exhaust.png differ diff --git a/GFX/flame.png b/GFX/flame.png new file mode 100644 index 0000000..1e5a662 Binary files /dev/null and b/GFX/flame.png differ diff --git a/GFX/font.bmf b/GFX/font.bmf new file mode 100644 index 0000000..8f98ae8 Binary files /dev/null and b/GFX/font.bmf differ diff --git a/GFX/missile.png b/GFX/missile.png new file mode 100644 index 0000000..85ea639 Binary files /dev/null and b/GFX/missile.png differ diff --git a/GFX/ship.png b/GFX/ship.png new file mode 100644 index 0000000..86e682e Binary files /dev/null and b/GFX/ship.png differ diff --git a/GFX/sprites.bms b/GFX/sprites.bms new file mode 100644 index 0000000..a16c28f Binary files /dev/null and b/GFX/sprites.bms differ diff --git a/GFX/title.png b/GFX/title.png new file mode 100644 index 0000000..fd87f81 Binary files /dev/null and b/GFX/title.png differ diff --git a/gametypes.bmx b/gametypes.bmx new file mode 100644 index 0000000..afd9997 --- /dev/null +++ b/gametypes.bmx @@ -0,0 +1,86 @@ +' 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 "global.bmx" + +Type GameState + Global score:Int=0 + Global x:Double=0 + Global y:Double=0 + Global ang:Int=0 + Global shields:Int=0 + + Function Reset() + score=0 + x=0 + y=0 + ang=0 + shields=3 + End Function + + Function Display() + Local s:String="SHIELDS " + + For Local f:Int=1 To shields + s:+"~~" + Next + + GFX.font.Draw("SCORE",-400,-300) + GFX.font.Draw(Number.Format(score),-400,-284,255,255,0) + + GFX.font.Draw(s,-80,-300) + + GFX.font.DrawRight("HISCORE",399,-300) + GFX.font.DrawRight(Number.Format(GameConfig.hiscore),399,-284,255,255,0) + End Function +End Type + + +Type BackdropStar + Field x:Double + Field y:Double + Field r:Int + Field g:Int + Field b:Int + + Method New() + x=Rand(-400,400) + y=Rand(-400,400) + r=Rand(128,255) + g=Rand(128,255) + b=Rand(128,255) + End Method +End Type + + +Type Backdrop + Global s:BackdropStar[] + + Function Init() + s=New BackdropStar[400] + + For Local f:Int=0 To 399 + s[f]=New BackdropStar + Next + End Function +End Type 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 diff --git a/missile_lock.bmx b/missile_lock.bmx new file mode 100644 index 0000000..21ba804 --- /dev/null +++ b/missile_lock.bmx @@ -0,0 +1,238 @@ +' 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 +Framework brl.basic +Import brl.max2d +Import brl.glmax2d +?Win32 +Import brl.d3d7max2d +? + +Import noddybox.bitmapfont +Import noddybox.keysyms + +Import "global.bmx" +Import "gametypes.bmx" +'Import "game.bmx" +Import "particle.bmx" +'Import "help.bmx" + +' =================================== +' Initialise +' =================================== +' +SeedRnd(MilliSecs()) + +?Win32 +If Switch("--directx") + SetGraphicsDriver D3D7Max2DDriver() +Else + SetGraphicsDriver GLMax2DDriver() +EndIf +? + +Graphics 800,600,32,HERTZ +SetOrigin(400,300) +HideMouse + +SetBlend(ALPHABLEND) +SetAlpha(1.0) + + +' =================================== +' Globals +' =================================== +' +GFX.Init() ' MUST be first + +Lookup.Init() +GameConfig.Load() +Scroller.Init() +Particles.Init() + +GameState.Reset() + +Global quit:Int=False + + +' =================================== +' Main +' =================================== +' +Menu() + +While Not quit + GameState.Reset() + + TFadeScreen.DoFadeOut() + + GameConfig.Save() + 'last_score=game.score + + Menu() +Wend + +EndGraphics +End + + +' =================================== +' Argument Routines +' =================================== +' +Function Switch:Int(s:String) + For Local a:String=EachIn AppArgs + If a=s + Return True + EndIf + Next + + Return False +End Function + + +' =================================== +' Menu Routines +' =================================== +' +Function Menu() + Local fade:TFadeScreen=TFadeScreen.FadeIn() + Local done:Int=False + Local defkey:Int=0 + + Particles.Clear() + + While Not done + Cls + + If Rand(100)>30 + Particles.AddScaledImage(GFX.exhaust,Rand(-400,400),Rand(-400,400),0.3) + End If + + GameState.ang=(GameState.ang+2) Mod 3600 + + SetOrigin(400,300) + Particles.Draw() + GameState.Display() + Scroller.Draw() + + SetOrigin(0,0) + SetColor(255,255,255) + DrawImage(GFX.title,0,0) + + If defkey>0 + + If defkey=5 + GFX.font.Centre("PRESS A KEY TO GO BACK TO THE MENU",380) + Else + GFX.font.Centre("DEFINE KEYS",350) + GFX.font.Centre("PRESS ESCAPE TO CANCEL",380) + EndIf + + Local c1:Int=128+128*(defkey=1) + Local c2:Int=128+128*(defkey=2) + Local c3:Int=128+128*(defkey=3) + Local c4:Int=128+128*(defkey=4) + + GFX.font.Draw("LEFT",250,200,c1,c1,c1) + GFX.font.Draw("RIGHT",250,220,c2,c2,c2) + GFX.font.Draw("FIRE",250,240,c3,c3,c3) + GFX.font.Draw("PAUSE",250,260,c4,c4,c4) + GFX.font.Draw(KeySym(GameConfig.kleft),500,200,c1,c1,0) + GFX.font.Draw(KeySym(GameConfig.kright),500,220,c2,c2,0) + GFX.font.Draw(KeySym(GameConfig.kfire),500,240,c3,c3,0) + GFX.font.Draw(KeySym(GameConfig.kpause),500,260,c4,c4,0) + + Local k:Int=-1 + + For Local f:Int=0 To 255 + If KeyHit(f) + k=f + Continue + EndIf + Next + + If k=KEY_ESCAPE + GameConfig.Load() + defkey=0 + FlushKeys() + ElseIf k<>-1 + Select defkey + Case 1 + GameConfig.kleft=k + Case 2 + GameConfig.kright=k + Case 3 + GameConfig.kfire=k + Case 4 + GameConfig.kpause=k + End Select + + defkey:+1 + + If defkey=6 + GameConfig.Save() + defkey=0 + FlushKeys() + EndIf + EndIf + Else + If KeyHit(KEY_ESCAPE) + done=True + quit=True + EndIf + + If KeyHit(KEY_SPACE) + done=True + EndIf + + If KeyHit(KEY_R) + defkey=1 + FlushKeys() + EndIf + + GFX.font.Centre("COPYRIGHT (C) NODDYBOX 2006",200) + + GFX.font.Centre("PRESS FIRE TO PLAY",300) + + GFX.font.Centre("PRESS R TO REDEFINE KEYS",380) + GFX.font.Centre("PRESS ESCAPE TO QUIT",400) + EndIf + + If fade + If fade.Fade() + fade.Draw() + Else + fade=Null + EndIf + EndIf + + Flip + Wend + + Particles.Clear() + TFadeScreen.DoFadeOut() + SetOrigin(400,300) +End Function + + diff --git a/particle.bmx b/particle.bmx new file mode 100644 index 0000000..79c7f8c --- /dev/null +++ b/particle.bmx @@ -0,0 +1,130 @@ +' 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 noddybox.algorithm +Import "global.bmx" +Import "gametypes.bmx" + +Type TParticle + Field life:Int + Field i:TImage + Field x:Double + Field y:Double + Field a:Double + Field dx:Double + Field dy:Double + Field ai:Double + Field s:Double + Field si:Double + + Function Image:TParticle(i:TImage, x:Int, y:Int) + Local o:TParticle=New TParticle + o.life=120 + o.x=x + o.y=y + o.a=1 + o.ai=-0.01 + o.dx=0 + o.dy=0 + o.s=1 + o.si=0 + o.i=i + Return o + End Function + + Function ScaleImage:TParticle(i:TImage, x:Int, y:Int,si:Double) + Local o:TParticle=New TParticle + o.life=120 + o.x=x + o.y=y + o.a=1 + o.ai=-0.01 + o.dx=0 + o.dy=0 + o.s=1 + o.si=si + o.i=i + Return o + End Function + + Method Update:Int() + Local p:TAlgoPointD=DoRotateD(x,y,3599-GameState.ang) + p.x:-GameState.x + p.y:+GameState.y + SetAlpha(a) + SetScale(s,s) + DrawImage(i,p.x,p.y) + x:+dx + y:+dy + life:-1 + a:+ai + s:+si + Return life>0 + End Method +End Type + +Type Particles + Global plist:TList + + Function Init() + plist=CreateList() + End Function + + Function Clear() + plist.Clear() + End Function + + Function AddImage(i:TImage, x:Int, y:Int) + If plist.Count()<1000 + plist.AddLast(TParticle.Image(i,x,y)) + EndIf + End Function + + Function AddScaledImage(i:TImage, x:Int, y:Int, si:Double=0.1) + If plist.Count()<1000 + plist.AddLast(TParticle.ScaleImage(i,x,y,si)) + EndIf + End Function + + Function Draw() + Local r:Double=GetRotation() + + SetRotation(-GameState.ang/10.0) + + SetColor(255,255,255) + Local l:TEasyLink=TEasyLink.Create(plist) + + While l.Value() + Local p:TParticle=TParticle(l.Value()) + + If (p.Update()) + l.MoveNext() + Else + l.Remove() + EndIf + Wend + SetAlpha(1) + SetScale(1,1) + SetRotation(r) + End Function +End Type -- cgit v1.2.3