Count Me In

Posted by (twitter: @xMrPhil)
December 5th, 2008 3:02 pm

I’ve decided to enter again.  This will be Ludum Dare number 4 for me.  This time I’m planning to use BlitzMax and Jake Birkett’s Grey Alien BlitzMax Game Framework.  Here is the basic setup code I’ll be using (if you follow the “Start Here” document this should be your result, except I added a try-catch around everything for unhandled exceptions):

SuperStrict

?Win32
Import “../include/fullaccess.cpp”
Import “-ladvapi32”
?

‘Import various Mac OS API calls made in C.

?MacOS
Import “../include/GAGMacLib.m”
?

Include “../include/commoncode.bmx”
Include “../include/commontypes.bmx”

Try

ccCreateMutex(“BasicSetup”)

AppTitle = “BasicSetup”

ScreenWidth = 800
ScreenHeight = 600

Game = New TGame
Game.SetSubPathWrapper(“Grey Alien Games/Basic Setup”)
Game.Init()
Game.DebugDisplayX = 5
Game.DebugDisplayY = 95
Game.SetEscapeSound(“ButtonClick”)

Global images:TImageBank = New TImageBank
images.SetPath(Game.ImagePath)
Global sounds:TSoundBank = New TSoundBank
sounds.SetPath(Game.SoundPath)

‘Instance both types that we created
Global TitleScreen: TTitleScreen = New TTitleScreen
Global GameScreen: TGameScreen= New TGameScreen

Game.GraphicsCreate() ‘Create a graphics context
HideMouse ‘hide the mouse
LoadData() ‘load data using a function we will define
ccFlushAll() ‘flush keys and mouse

Local LoopExit:Int = 0 ‘boolean for exiting the main loop
Game.FixedRateLogic.Init()
Game.NoTimingTicks = 3 ‘only applied if Game.NoTiming=1

Repeat
‘do the logic separately from the drawing
If Game.MainLogicLoop() = -1 Then ShutDown()
‘draw the screen and flip it to show it
Game.ScreenDraw()
Until LoopExit = 1
ShutDown()

Function Shutdown()
Tgame.MakeGoodExit()
ShowMouse() ‘just in case it was hidden.
‘Exit the program
End
End Function

‘Instance both types that we created

Function LoadData()
AutoMidHandle True
ccClsVSync()’Ensure clear screen when loading

LoadSounds()
LoadImages()
TitleScreen.Load() ‘Call load method of TitleScreen
TitleScreen.Start() ‘Call start method of TitleScreen
‘Now loading is complete, let the main loop handle the drawing
Game.CurrentTScreen = TitleScreen

?Win32 ‘Has the app been suspended while loading? If so, deal with it.
If GetForegroundWindow()<>Game.WindowHandle
Game.SuspendedEvent = 1
EndIf
?
End Function

Function LoadSounds()
sounds.Load(“ButtonClick”) ‘load the sound “buttonclick”
End Function

Function LoadImages()
Game.mouse.Load(“pointer”) ‘load mouse pointer image
images.Load(“Paused”) ‘Load “paused” graphic
‘Create Paused sprite
Game.SpritePausedCreate(Images.Find(“Paused”))
End Function

Type TTitleScreen Extends TScreen
Field x#,y#

Method Load()
‘this is a TScreen method
ImageLoad(“title.jpg”,FILTEREDIMAGE)
MidHandleImage(Image)
‘this gets midhandled automatically
HeaderLoad(“logolarge”,screenwidth/2,100)
Menu = TMenu.Create(“ButtonMO”, “ButtonClick”,0,0,10)
‘Add a new Button
‘Allow Space and Enter to trigger it
Menu.AddNew(“playgame”, “playgameMO”).OKButton = 1
Menu.AddNew(“exitgame”,”exitgameMO”)
Menu.Centre() ‘Center the Menu
‘Move the Y position of the menu
Menu.SetY(Menu.Y+50)
End Method

Method Start()
Super.Start() ‘Call Start method of base type TScreen
Game.GameFade.Init(FADE_SPEED,0) ‘fade in
Game.Mouse.On()
Game.FixedRateLogic.Init()
End Method

Method Logic()
‘Call the logic method of the base type
Super.Logic()
‘If the start button is clicked, fade to the next screen
‘and set that next screen to the GameScreen
If Menu.FindButton(“playgame”).Clicked Then
Game.GameFade.Init(FADE_SPEED,1,Game.MusicChannel, True)
Game.DestinationTScreen = GameScreen
EndIf

‘If the exit button is clicked, fade the screen and exit
If Menu.FindButton(“exitgame”).Clicked Then
Game.GameFade.Init(FADE_SPEED,1,Game.MusicChannel, True)
Game.DestinationTScreen = Game.ExitScreen
EndIf
End Method

Method Draw()
SetBlend SOLIDBLEND
‘Image is a field of the base type TScreen
DrawImage(Image,screenwidth/2+x,screenheight/2+y)
SetBlend ALPHABLEND
Header.Draw() ‘Draw the logo that we loaded earlier
Menu.Draw() ‘Draw the Menu
End Method
End Type

Type TGameScreen Extends TScreen

Method Load()
ImageLoad(“bg1.jpg”)
HeaderLoad(“logosmall”,210,35)
End Method

Method Start()
Super.Start()
Game.GameFade.Init(FADE_SPEED,0) ‘initiate fading
Game.Mouse.Off() ‘Turn the mouse off
Game.FixedRateLogic.Init()
End Method

Method Logic()
Super.Logic() ‘handles menu core logic
End Method

Method Draw()
Cls
SetBlend ALPHABLEND
DrawImage(image,0,0)
Header.Draw() ‘Draw the header
SetColor 255,255,255
‘Draw instructional text
ccDrawTextCentre(“Press <esc> to Exit”,560,1)
End Method

Method SetEscDestination() ‘over ride base type method
‘if esc is pressed, go to the TitleScreen
Game.DestinationTScreen = TitleScreen
End Method
End Type

Catch ex:Object

Print “Unhandled exception:”
Print ex.ToString()

End Try

Tags:


Leave a Reply

You must be logged in to post a comment.

[cache: storing page]