Post by Mark Dunham on Sept 15, 2018 20:58:08 GMT -5
This is a framework I built to start building any game that I think I want to make I am open to optimizing it as much as possible. I am working on how to add gravity and firing projectiles. Please feel free to add to this and help enhance for all to use.
'Game Framework
'Author: Mark Dunham A.K.A Taren
'Date: 02.27.2018
'#####################################################################
'### Global Variables ###
'#####################################################################
[Start]
'Don't Show the main window
nomainwin
'Create the graphic window
gosub [Graphic.Window]
'Display splash screen
'gosub [Splash.Screen]
'Load Sprites
gosub [Load.Sprites]
'Initialize Game Variables
'Set the game speed
GameSpeed = 60
Level = 1
[Start.Game]
'Disable the timer
timer 0
'Set the focus to the MainWindow
#FrameWork, "setfocus"
'Set the focus to the game window
timer GameSpeed, [Main.Loop]
wait
[Main.Loop]
'Check for Keyboard Input
gosub [Check.VirtualKeys]
'Update the status bar
gosub [Update.Status.Bar]
'Check for Collisions
gosub [Check.Collisions]
'Display Sprites
#FrameWork, "drawsprites"
wait
'#####################################################################
'### Display the Main WIndow ###
'#####################################################################
[Graphic.Window]
'Prepare the graphic window
WindowWidth = 1024
WindowHeight = 768
UpperLeftX = int((DisplayWidth - WindowWidth)/2)
UpperLeftY = int((DisplayHeight - WindowHeight)/2)
'Create a status bar
graphicbox #FrameWork.gbx, 0, 0, WindowWidth, 20
'Create the graphics window
open "Framework" for graphics_nf_nsb as #FrameWork
#FrameWork, "trapclose [FrameWork.Quit]"
#FrameWork, "when characterInput [Check.Input]"
'Setup the status bar
#FrameWork.gbx, "disable"
#FrameWork.gbx, "font arial bold 9 16"
#FrameWork.gbx, "down; fill black; color white; backcolor black"
return
'[Splash.Screen]
'return
'#####################################################################
'### Load Sprites ###
'#####################################################################
[Load.Sprites]
'Load Sprites Here
return
'#####################################################################
'### Update Status Bar ###
'#####################################################################
[Update.Status.Bar]
UI$ = space$(20); "Level: "; Level
#FrameWork.gbx, "Place 10 14"
#FrameWork.gbx, "|"; UI$
return
'#####################################################################
'### Check for keyboard and VirtualKey Input ###
'#####################################################################
[Check.Input]
'Keyboad Character Presses
if len(Inkey$) = 2 then key = asc(right$(Inkey$,1)) else key = 0
char$ = Inkey$
if char$ = "a" or char$ = "A" then
Level = Level + 1
end if
Inkey$ = ""
wait
[Check.VirtualKeys]
'Check Virtual Keys
' The value 32769 means that the key is down at the time of check.
' The value 32768 means that the key was pressed before we check.
'Check to see if you want to quit
if getKey(_VK_ESCAPE) and 32769 then
'Player wants to quit
goto [FrameWork.Quit]
end if
return
'#####################################################################
'### Quit the Framework ###
'#####################################################################
[FrameWork.Quit]
'Quit the framework and unload bitmaps
'Disable the timer
timer 0
'Make sure the user wants to quit
confirm "Are you sure you want to quit?"; answer$
if answer$ = "yes" then
close #FrameWork
end
end if
'If user is not quitting go back to the [Main.Loop]
timer GameSpeed, [Main.Loop]
return
'#####################################################################
'### Check For Collisions ###
'#####################################################################
[Check.Collisions]
return
'#####################################################################
'### Functions section ###
'#####################################################################
function getKey(key)
' Function to return the key value currently pressed
CallDLL #user32, "GetAsyncKeyState", _
key as Long, _
getKey as Long
end function
'The program is done running
end