diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-05-27 23:24:02 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-05-27 23:24:02 +0000 |
commit | 26c98ba56e72beaf8a99eafbedd2b0c64ac13954 (patch) | |
tree | 6460c30f185bfdf0647055a9a32af111b8f87894 /hardwire.bmx | |
parent | 0129dc56ba73e43f148b779d9ff549f286e66f1d (diff) |
Diffstat (limited to 'hardwire.bmx')
-rw-r--r-- | hardwire.bmx | 770 |
1 files changed, 396 insertions, 374 deletions
diff --git a/hardwire.bmx b/hardwire.bmx index f1f8997..577552f 100644 --- a/hardwire.bmx +++ b/hardwire.bmx @@ -1,374 +1,396 @@ -' Hardwire
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-Framework brl.basic
-Import brl.max2d
-Import brl.glmax2d
-?Win32
-Import brl.d3d7max2d
-?
-
-Import noddybox.bitmapfont
-Import noddybox.keysyms
-Import noddybox.gfxmenu
-
-Import "types.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
-HideMouse
-
-SetBlend(ALPHABLEND)
-SetAlpha(1.0)
-
-
-' ===================================
-' Globals
-' ===================================
-'
-GameGFX.Init() ' MUST be first
-
-Lookup.Init()
-GameConfig.Load()
-TWire.Init()
-Particles.Init()
-TextParticles.Init()
-ExplosionParticles.Init()
-Sound.Init()
-
-Global bdrop:TMenuBdrop=New TMenuBdrop
-Global quit:Int=False
-Global last_score:Int=0
-
-
-' ===================================
-' Main
-' ===================================
-'
-Menu()
-
-While Not quit
- Local game:TGame=New TGame
- game.SetInitLevel(GameConfig.start_level)
-
- While game.Play()
- Wend
-
- 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()
- Const MENU_PLAY:Int=1
- Const MENU_QUIT:Int=2
- Const MENU_RULES:Int=3
- Const MENU_KEYS:Int=4
- Const MENU_LEFT:Int=5
- Const MENU_RIGHT:Int=6
-
- Local fade:TFadeScreen=TFadeScreen.FadeIn()
- Local done:Int=False
- 'Local menu:TGfxMenu=TGfxMenu.Create(255,0,0,255,255,255,25,bdrop,1)
- Local menu:TGfxMenu=TGfxMenu.Create(255,0,0,255,255,255,15,bdrop,1)
- Local sel:Int
-
- Local defkey:Int=0
-
- Local x1:Int=GraphicsWidth()/3-ImageWidth(GameGFX.play_button)/2
- Local x2:Int=GraphicsWidth()/3*2-ImageWidth(GameGFX.play_button)/2
-
- menu.Add(x1,150,GameGFX.play_button,MENU_PLAY)
- menu.Add(x2,150,GameGFX.rules_button,MENU_RULES)
- menu.Add(x1,250,GameGFX.keys_button,MENU_KEYS)
- menu.Add(x2,250,GameGFX.quit_button,MENU_QUIT)
- menu.Add(x1,350,GameGFX.left_button,MENU_LEFT)
- menu.Add(x2+ImageWidth(GameGFX.play_button)-ImageWidth(GameGFX.right_button),350,GameGFX.right_button,MENU_RIGHT)
-
- Local tx1:Int=(GraphicsWidth()-GameGFX.large.TextWidth("START LEVEL 1"))/2
- Local tx2:Int=tx1+GameGFX.large.TextWidth("START LEVEL ")
-
- Local col:Int=128
- Local coli=1
-
- TextParticles.Clear()
-
- While Not done
- Cls
- SetColor(col,col,255)
- DrawImage(GameGFX.title,0,0)
- SetColor(255,255,255)
-
-?debug
- If KeyHit(KEY_D)
- DebugCode()
- EndIf
-?
-
- col:+coli
-
- If col=128 Or col=255
- coli=-coli
- EndIf
-
- sel=menu.Render(defkey>0)
-
- If defkey>0
-
- If defkey=7
- GameGFX.large.Centre("PRESS A KEY TO GO BACK TO THE MENU",150)
- Else
- GameGFX.large.Centre("DEFINE KEYS",150)
- GameGFX.large.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)
- Local c5:Int=128+128*(defkey=5)
- Local c6:Int=128+128*(defkey=6)
-
- GameGFX.large.Draw("Left",250,180,c1,c1,0)
- GameGFX.large.Draw("Right",250,210,c2,c2,0)
- GameGFX.large.Draw("Rotate Right",250,240,c3,c3,0)
- GameGFX.large.Draw("Rotate Left",250,270,c4,c4,0)
- GameGFX.large.Draw("Drop",250,300,c5,c5,0)
- GameGFX.large.Draw("Pause",250,330,c6,c6,0)
- GameGFX.large.Draw(KeySym(GameConfig.kleft),500,180,c1,c1,0)
- GameGFX.large.Draw(KeySym(GameConfig.kright),500,210,c2,c2,0)
- GameGFX.large.Draw(KeySym(GameConfig.krotright),500,240,c3,c3,0)
- GameGFX.large.Draw(KeySym(GameConfig.krotleft),500,270,c4,c4,0)
- GameGFX.large.Draw(KeySym(GameConfig.kdrop),500,300,c5,c5,0)
- GameGFX.large.Draw(KeySym(GameConfig.kpause),500,330,c6,c6,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.krotright=k
- Case 4
- GameConfig.krotleft=k
- Case 5
- GameConfig.kdrop=k
- Case 6
- GameConfig.kpause=k
- End Select
-
- defkey:+1
-
- If defkey=7
- GameConfig.Save()
- defkey=0
- FlushKeys()
- EndIf
- EndIf
- Else
- If KeyHit(KEY_ESCAPE)
- done=True
- quit=True
- EndIf
-
- TextParticles.Draw()
-
- GameGFX.large.Draw("START LEVEL ",tx1,356)
- GameGFX.large.Draw(GameConfig.start_level,tx2,356,255,255,0)
-
- GameGFX.large.CentreOn("LAST SCORE",200,500)
- GameGFX.large.CentreOn("HIGH SCORE",600,500)
- GameGFX.large.CentreOn(last_score,200,520,255,col,0)
- GameGFX.large.CentreOn(GameConfig.hiscore,600,520,255,col,0)
- EndIf
-
- Select sel
- Case MENU_PLAY
- done=True
- FlushKeys()
- Case MENU_RULES
- FlushKeys()
- Local help:THelp=New THelp
- TFadeScreen.DoFadeOut()
- help.Show()
- TFadeScreen.DoFadeOut()
- fade=TFadeScreen.FadeIn()
- Case MENU_KEYS
- FlushKeys()
- defkey=1
- Case MENU_QUIT
- done=True
- quit=True
- Case MENU_LEFT
- GameConfig.start_level=Max(1,GameConfig.start_level-1)
- GameConfig.Save()
- Case MENU_RIGHT
- GameConfig.start_level=Min(10,GameConfig.start_level+1)
- GameConfig.Save()
- End Select
-
- Rem
- SetScale(2,2)
- GameGFX.font.Centre("HARDWIRE",0,255,255,0)
-
- SetScale(1,1)
- GameGFX.font.Centre("Copyright (c) 2005 Ian C",20,255,0,0)
- EndRem
-
- SetColor(255,255,255)
- DrawImage(GameGFX.pointer,MouseX(),MouseY())
-
- If fade
- If fade.Fade()
- fade.Draw()
- Else
- fade=Null
- EndIf
- EndIf
-
- Flip
- Wend
-
- TextParticles.Clear()
-
- TFadeScreen.DoFadeOut()
-End Function
-
-
-' ===================================
-' Debug
-' ===================================
-'
-?debug
-Function DebugCreate:TPiece(t:Int)
- Local p:TPiece=TPiece.CreateSpecific(t)
- p.x=8
- p.y=-3
- Return p
-End Function
-
-Function DebugCode()
- Local done:Int=False
- Local gm:TGameMap=New TGameMap
- Local t:Int=0
- Local p:TPiece=DebugCreate(t)
-
- While Not done
- Cls
-
- If gm.overflow
- GameGFX.large.Centre("OVERFLOW!",0)
- EndIf
-
- gm.Draw()
-
- p.Draw()
-
- Local k:Int=-1
-
- For Local f:Int=0 To 255
- If KeyHit(f)
- k=f
- Continue
- EndIf
- Next
-
- Select k
- Case KEY_ESCAPE
- done=True
-
- Case KEY_0,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9
- t=k-KEY_0
- p=DebugCreate(t)
-
- Case KEY_LEFT
- p.x:-1
-
- Case KEY_RIGHT
- p.x:+1
-
- Case KEY_DOWN
- p.y:+1
-
- Case KEY_UP
- p.y:-1
-
- Case KEY_SPACE
- p.RotateRight()
-
- Case KEY_ENTER
- p.AddToMap(gm)
- p=DebugCreate(t)
- End Select
-
- Particles.Draw()
- ExplosionParticles.Draw()
- TextParticles.Draw()
- Sound.Process()
- Flip
- Wend
-End Function
-?
-
+' Hardwire +' +' Copyright (C) 2005 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 noddybox.gfxmenu + +Import "types.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 +HideMouse + +SetBlend(ALPHABLEND) +SetAlpha(1.0) + + +' =================================== +' Globals +' =================================== +' +GameGFX.Init() ' MUST be first + +Lookup.Init() +GameConfig.Load() +TWire.Init() +Particles.Init() +TextParticles.Init() +ExplosionParticles.Init() +Sound.Init() + +Global bdrop:TMenuBdrop=New TMenuBdrop +Global quit:Int=False +Global last_score:Int=0 + + +' =================================== +' Main +' =================================== +' +Menu() + +While Not quit + Local game:TGame=New TGame + game.SetInitLevel(GameConfig.start_level) + + While game.Play() + Wend + + 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() + Const MENU_PLAY:Int=1 + Const MENU_QUIT:Int=2 + Const MENU_RULES:Int=3 + Const MENU_KEYS:Int=4 + Const MENU_LEFT:Int=5 + Const MENU_RIGHT:Int=6 + + Local fade:TFadeScreen=TFadeScreen.FadeIn() + Local done:Int=False + 'Local menu:TGfxMenu=TGfxMenu.Create(255,0,0,255,255,255,25,bdrop,1) + Local menu:TGfxMenu=TGfxMenu.Create(255,0,0,255,255,255,15,bdrop,1) + Local sel:Int + + Local defkey:Int=0 + + Local x1:Int=GraphicsWidth()/3-ImageWidth(GameGFX.play_button)/2 + Local x2:Int=GraphicsWidth()/3*2-ImageWidth(GameGFX.play_button)/2 + + menu.Add(x1,150,GameGFX.play_button,MENU_PLAY) + menu.Add(x2,150,GameGFX.rules_button,MENU_RULES) + menu.Add(x1,250,GameGFX.keys_button,MENU_KEYS) + menu.Add(x2,250,GameGFX.quit_button,MENU_QUIT) + menu.Add(x1,350,GameGFX.left_button,MENU_LEFT) + menu.Add(x2+ImageWidth(GameGFX.play_button)-ImageWidth(GameGFX.right_button),350,GameGFX.right_button,MENU_RIGHT) + + Local tx1:Int=(GraphicsWidth()-GameGFX.large.TextWidth("START LEVEL 1"))/2 + Local tx2:Int=tx1+GameGFX.large.TextWidth("START LEVEL ") + + Local col:Int=128 + Local coli=1 + + TextParticles.Clear() + + While Not done + Cls + + SetColor(col,col,255) + DrawImage(GameGFX.title,0,0) + SetColor(255,255,255) + +?debug + If KeyHit(KEY_D) + DebugCode() + EndIf +? + + col:+coli + + If col=128 Or col=255 + coli=-coli + EndIf + + sel=menu.Render(defkey>0) + + If defkey>0 + + If defkey=7 + GameGFX.large.Centre("PRESS A KEY TO GO BACK TO THE MENU",150) + Else + GameGFX.large.Centre("DEFINE KEYS",150) + GameGFX.large.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) + Local c5:Int=128+128*(defkey=5) + Local c6:Int=128+128*(defkey=6) + + GameGFX.large.Draw("Left",250,180,c1,c1,0) + GameGFX.large.Draw("Right",250,210,c2,c2,0) + GameGFX.large.Draw("Rotate Right",250,240,c3,c3,0) + GameGFX.large.Draw("Rotate Left",250,270,c4,c4,0) + GameGFX.large.Draw("Drop",250,300,c5,c5,0) + GameGFX.large.Draw("Pause",250,330,c6,c6,0) + GameGFX.large.Draw(KeySym(GameConfig.kleft),500,180,c1,c1,0) + GameGFX.large.Draw(KeySym(GameConfig.kright),500,210,c2,c2,0) + GameGFX.large.Draw(KeySym(GameConfig.krotright),500,240,c3,c3,0) + GameGFX.large.Draw(KeySym(GameConfig.krotleft),500,270,c4,c4,0) + GameGFX.large.Draw(KeySym(GameConfig.kdrop),500,300,c5,c5,0) + GameGFX.large.Draw(KeySym(GameConfig.kpause),500,330,c6,c6,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.krotright=k + Case 4 + GameConfig.krotleft=k + Case 5 + GameConfig.kdrop=k + Case 6 + GameConfig.kpause=k + End Select + + defkey:+1 + + If defkey=7 + GameConfig.Save() + defkey=0 + FlushKeys() + EndIf + EndIf + Else + If KeyHit(KEY_ESCAPE) + done=True + quit=True + EndIf + + TextParticles.Draw() + + GameGFX.large.Draw("START LEVEL ",tx1,356) + GameGFX.large.Draw(GameConfig.start_level,tx2,356,255,255,0) + + GameGFX.large.CentreOn("LAST SCORE",200,500) + GameGFX.large.CentreOn("HIGH SCORE",600,500) + + GameGFX.large.CentreOn(Number.Format(last_score),200,520,255,col,0) + GameGFX.large.CentreOn(Number.Format(GameConfig.hiscore),600,520,255,col,0) + EndIf + + Select sel + Case MENU_PLAY + done=True + FlushKeys() + Case MENU_RULES + FlushKeys() + Local help:THelp=New THelp + TFadeScreen.DoFadeOut() + help.Show() + TFadeScreen.DoFadeOut() + fade=TFadeScreen.FadeIn() + Case MENU_KEYS + FlushKeys() + defkey=1 + Case MENU_QUIT + done=True + quit=True + Case MENU_LEFT + GameConfig.start_level=Max(1,GameConfig.start_level-1) + GameConfig.Save() + Case MENU_RIGHT + GameConfig.start_level=Min(10,GameConfig.start_level+1) + GameConfig.Save() + End Select + + Rem + SetScale(2,2) + GameGFX.font.Centre("HARDWIRE",0,255,255,0) + + SetScale(1,1) + GameGFX.font.Centre("Copyright (c) 2005 Ian C",20,255,0,0) + EndRem + + SetColor(255,255,255) + DrawImage(GameGFX.pointer,MouseX(),MouseY()) + + If fade + If fade.Fade() + fade.Draw() + Else + fade=Null + EndIf + EndIf + + Flip + Wend + + TextParticles.Clear() + + TFadeScreen.DoFadeOut() +End Function + + +' =================================== +' Debug +' =================================== +' +?debug +Function DebugCreate:TPiece(t:Int) + Local p:TPiece=TPiece.CreateSpecific(t) + p.x=8 + p.y=-3 + Return p +End Function + +Function DebugCode() + Local done:Int=False + Local gm:TGameMap=New TGameMap + Local t:Int=0 + Local p:TPiece=DebugCreate(t) + + While Not done + Cls + + If gm.overflow + GameGFX.large.Centre("OVERFLOW!",0) + EndIf + + gm.Draw() + + GameGFX.small.CentreOn(Number.Format(MilliSecs()),200,590) + GameGFX.small.CentreOn(Number.Format(MilliSecs()*2),600,590) + GameGFX.small.Centre(Number.Format(MilliSecs()*100),590) + + p.Draw() + + Local k:Int=-1 + + For Local f:Int=0 To 255 + If KeyHit(f) + k=f + Continue + EndIf + Next + + Select k + Case KEY_ESCAPE + done=True + + Case KEY_0,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9 + t=k-KEY_0 + p=DebugCreate(t) + + Case KEY_LEFT + p.x:-1 + + Case KEY_RIGHT + p.x:+1 + + Case KEY_DOWN + p.y:+1 + + Case KEY_UP + p.y:-1 + + Case KEY_SPACE + p.RotateRight() + + Case KEY_ENTER + p.AddToMap(gm) + p=DebugCreate(t) + End Select + + Particles.Draw() + ExplosionParticles.Draw() + TextParticles.Draw() + Sound.Process() + Flip + Wend +End Function +? + |