News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

A Simple Game Frame Work

Started by kevin, February 02, 2007, 05:00:57 PM

Previous topic - Next topic

kevin



PlayBASIC Code: [Select]
; PROJECT : Project1
; AUTHOR : Kevin Picone
; CREATED : 3/02/2007
; ---------------------------------------------------------------------



; Upon startup we see the main settings of the program

Setfps 75
LoadFont "Arial",1,32,0




; Use the AUto counter to define some meaningful constants we can use.
; This allow us to change the order, values of the following flags in
; the future without breaking the program,
; Set AC to Zero
Acset =0
; define some constants
constant MenuOption_NoAction =ac(1)
constant MenuOption_PlayGame =ac(1)
constant MenuOption_Menu =ac(1)
constant MenuOption_EndProgram =ac(1)



; Start Game on the menu
Option=MenuOption_Menu


; ===========================================================
Repeat ; MAIN LP of the APP
; ===========================================================

; Choose what section, the proram shoudl run
select Option

; option ='s the menu tag, then we call the MENU
case MenuOption_Menu
option=Menu()

; if option ='s the play Game tad, we call the game
case MenuOption_PlayGame
option=PlayGame()

endselect


Until Option=MenuOption_EndProgram ; user seelect to exit program



; delete media, save settigns etc etc

end



; --------------------------------------------------------------------------
; --------------------------------------------------------------------------
; --------------------------------------------------------------------------
; --------------------------MENU SECTION ------------------------------------
; --------------------------------------------------------------------------
; --------------------------------------------------------------------------
; --------------------------------------------------------------------------



Function Menu()

Option=MenuOption_Nothing

repeat

Cls 0

y=getscreenheight()/3
x=getscreenwidth()/2

centerText x,y, ">> MY COOL GAME MENU<<"
centertext x,y+70,"P = Play Game"
centertext x,y+100,"Q = Quit Program"
; dectect what optins the user has selected and


; Check if the user selected a menu option
Key$=lower$(inkey$())
select Key$
case "p" : Option=MenuOption_PlayGame
case "q" : Option=MenuOption_EndProgram
Endselect

sync
until Option<>MenuOption_Nothing

Flushkeys

EndFunction Option




; --------------------------------------------------------------------------
; --------------------------------------------------------------------------
; --------------------------------------------------------------------------
; -------------------------GAME SECTION -------------------------------------
; --------------------------------------------------------------------------
; --------------------------------------------------------------------------
; --------------------------------------------------------------------------


Constant Alive=true
Constant Dead=false


Function PlayGame()

ShowMessageTime=timer()+2000

AlienStatus=Alive
AlienRadius=20
AlienX#= AlienRAdius
AlienY#=100
ALienSpeed#=5



PlayerStatus =Alive
PlayerSpeed =5
PlayerWidth =30
PlayerHeight =10
PlayerY =getScreenHeight()-PlayerHeight*3
PlayerX =getScreenWidth()/2
PlayerScore =0



repeat
Cls 0

ALienX#=AlienX#+AlienSpeed#
if (AlienX#-AlienRadius)<0
; Flip it's speed (direction)
AlienSpeed#=-AlienSpeed#
AlienX#=AlienRadius
Login required to view complete source code