diff --git a/data/menu.data b/data/menu.data deleted file mode 100644 index 200eac5..0000000 --- a/data/menu.data +++ /dev/null @@ -1,8 +0,0 @@ -MAIN_MENU {ESCape} - BUTTON: {Escape now!} -> RUNNING_GAME - BUTTON: {End game} -> RLY_QUIT - -RLY_QUIT {You want to leave?} - BUTTON: {Yes} -> EXIT - BUTTON: {No} -> MAIN_MENU - diff --git a/escape.pbp b/escape.pbp index 97ebb54..1045f1a 100644 --- a/escape.pbp +++ b/escape.pbp @@ -1,6 +1,6 @@ - +
@@ -8,42 +8,43 @@
- + - +
- + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
- + + - +
diff --git a/src/Draw.pbi b/src/Draw.pbi index 74a16f6..05d440c 100644 --- a/src/Draw.pbi +++ b/src/Draw.pbi @@ -32,4 +32,4 @@ EndProcedure Procedure DrawRunningGame() Box(0, 0, 200, 200, RGB(0, 255, 0)) -EndProcedure \ No newline at end of file +EndProcedure diff --git a/src/Events.pbi b/src/Events.pbi index c13a460..f8eb235 100644 --- a/src/Events.pbi +++ b/src/Events.pbi @@ -1,8 +1,6 @@ ; In this file, we handle alle the events Procedure HandleEventMenu() - Define ActiveMenu_Index.i = ListIndex(*ActiveMenu\Entries()) - If KeyboardReleased(#PB_Key_Up) Menu_GotoCurrent() *ActiveMenu\Entries()\Selected = #False @@ -29,10 +27,16 @@ Procedure HandleEventMenu() *ActiveMenu\Entries()\Selected = #True EndIf + ; We go to the target game state If KeyboardReleased(#PB_Key_Return) - Debug "Return!" + Menu_GotoCurrent() + CurrentState.s = *ActiveMenu\Entries()\TargetState + *ActiveMenu.GameMenu = Menus(CurrentState) EndIf + + ;KeyboardPushed(#PB_Key_Escape) Or EndProcedure Procedure HandleEventRunningGame() + Debug "Game starts!!!" EndProcedure \ No newline at end of file diff --git a/src/Functions.pbi b/src/Functions.pbi index ecff12c..3b79caf 100644 --- a/src/Functions.pbi +++ b/src/Functions.pbi @@ -1 +1,31 @@ -; This file holds all the functions If it gets too big, ; we can split it in categories ; ***************************************************************************** ; * Tileset Procedure InitTileset() CatchSprite(#Tile01, ?Gfx_Tileset) ;ClipSprite(0, 0, 0, 16, 16) ; test the sprite ;DisplaySprite(0, 20, 20) EndProcedure ; ***************************************************************************** ; ***************************************************************************** ; * Menu Procedure Menu_GotoCurrent() If *ActiveMenu\Entries()\Selected <> #True FirstElement(*ActiveMenu\Entries()); ForEach *ActiveMenu\Entries() If *ActiveMenu\Entries()\Selected = #True Break EndIf Next EndIf EndProcedure ; ***************************************************************************** \ No newline at end of file +; This file holds all the functions If it gets too big, +; we can split it in categories + +; ***************************************************************************** +; * Tileset + +Procedure InitTileset() + CatchSprite(#Tile01, ?Gfx_Tileset) + ;ClipSprite(0, 0, 0, 16, 16) + + ; test the sprite + ;DisplaySprite(0, 20, 20) +EndProcedure + +; ***************************************************************************** + + +; ***************************************************************************** +; * Menu + +Procedure Menu_GotoCurrent() + If *ActiveMenu\Entries()\Selected <> #True + FirstElement(*ActiveMenu\Entries()); + + ForEach *ActiveMenu\Entries() + If *ActiveMenu\Entries()\Selected = #True + Break + EndIf + Next + EndIf +EndProcedure diff --git a/src/Globals.pbi b/src/Globals.pbi index 247bda4..458135b 100644 --- a/src/Globals.pbi +++ b/src/Globals.pbi @@ -1,7 +1,7 @@  ; Global variables Global Fullscreen = 0 -Global Title.s = "Pongr - Build " + Str(#PB_Editor_BuildCount) +Global Title.s = "ESCape - Build " + Str(#PB_Editor_BuildCount) Global Screen.ScreenDimension\width = 800 Screen.ScreenDimension\height = 600 @@ -22,4 +22,4 @@ Enumeration 500 #Tile04 #Tile05 #Tile06 -EndEnumeration \ No newline at end of file +EndEnumeration diff --git a/src/Main.pb b/src/Main.pb index 875f1bc..422f25f 100644 --- a/src/Main.pb +++ b/src/Main.pb @@ -4,80 +4,81 @@ EnableExplicit -XIncludeFile "Structs.pbi" -XIncludeFile "Globals.pbi" -XIncludeFile "Draw.pbi" -XIncludeFile "Functions.pbi" -XIncludeFile "Events.pbi" - -; Initialize all the variables and stuff. I think we refactor this -; into a separate file if it gets messy. -GameStates("MAIN_MENU")\DrawFun = @DrawMenu() -GameStates("MAIN_MENU")\HandleEventFun = @HandleEventMenu() - -GameStates("OPTION_MENU")\DrawFun = @DrawMenu() -GameStates("OPTION_MENU")\HandleEventFun = @HandleEventMenu() - -GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame() -GameStates("RUNNING_GAME")\HandleEventFun = @HandleEventRunningGame() - -; Read the complete game menus from the data/menu.data file. -; TODO: IncludeBinary looks interesting! -If ReadFile(0, "../data/menu.data") - CreateRegularExpression(0, "^([A-Z_-]+) {(.*)}") ; Menu title - CreateRegularExpression(1, "^ BUTTON: {(.+)} -> (.+)") ; A button - CreateRegularExpression(2, "^ OPTION: (.*)") ; A option field (TODO: Thats not exactly right) - - While Eof(0) = 0 - Dim Matches$(0) - Define Line.s = ReadString(0) - - ; We found a new menu - If MatchRegularExpression(0, Line) - Define i - For i=0 To ExtractRegularExpression(0, Line, Matches$())-1 - Debug Matches$(i) ; FIXME: Thats not what we want ... - Next - EndIf - Wend - - FreeRegularExpression(0) - FreeRegularExpression(1) - FreeRegularExpression(2) - CloseFile(0) -EndIf - -Menus("MAIN_MENU")\Title = "ESCape" - -Define Item.GameMenuItem -Item.GameMenuItem\Label = "Escape now!" -Item.GameMenuItem\Selected = #True -Item.GameMenuItem\TargetState = GameStates("RUNNING_GAME") -AddElement(Menus("MAIN_MENU")\Entries()) -menus("MAIN_MENU")\Entries() = Item - -Define Item.GameMenuItem -Item.GameMenuItem\Label = "End game" -Item.GameMenuItem\Selected = #False -Item.GameMenuItem\TargetState = GameStates("RLY_QUIT") -AddElement(Menus("MAIN_MENU")\Entries()) -menus("MAIN_MENU")\Entries() = Item - -*ActiveMenu.GameMenu = @Menus(CurrentState) - ; Initialize subsystems If InitSprite() = 0 Or InitKeyboard() = 0 MessageRequester("Error", "Sorry, can't keep up.", 0) End EndIf -InitTileset() + +XIncludeFile "Structs.pbi" +XIncludeFile "Globals.pbi" +XIncludeFile "Draw.pbi" +XIncludeFile "Functions.pbi" +XIncludeFile "Events.pbi" + + + + + +; Initialize all the variables and stuff. I think we refactor this +; into a separate file if it gets messy. +GameStates("MAIN_MENU")\DrawFun = @DrawMenu() +GameStates("MAIN_MENU")\HandleEventFun = @HandleEventMenu() +GameStates("RLY_QUIT")\DrawFun = @DrawMenu() +GameStates("RLY_QUIT")\HandleEventFun = @HandleEventMenu() + +GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame() +GameStates("RUNNING_GAME")\HandleEventFun = @HandleEventRunningGame() + + + +; Initialize the menus +Menus("MAIN_MENU")\Title = "ESCape" + +Define Item.GameMenuItem +Item.GameMenuItem\Label = "Escape now!" +Item.GameMenuItem\Selected = #True +Item.GameMenuItem\TargetState = "RUNNING_GAME" +AddElement(Menus("MAIN_MENU")\Entries()) +menus("MAIN_MENU")\Entries() = Item + +Define Item.GameMenuItem +Item.GameMenuItem\Label = "End game" +Item.GameMenuItem\Selected = #False +Item.GameMenuItem\TargetState = "RLY_QUIT" +AddElement(Menus("MAIN_MENU")\Entries()) +menus("MAIN_MENU")\Entries() = Item + + +Menus("RLY_QUIT")\Title = "Really quit?" + +Define Item.GameMenuItem +Item.GameMenuItem\Label = "Yes, let me go!" +Item.GameMenuItem\Selected = #True +Item.GameMenuItem\TargetState = "QUIT" +AddElement(Menus("RLY_QUIT")\Entries()) +menus("RLY_QUIT")\Entries() = Item + +Define Item.GameMenuItem +Item.GameMenuItem\Label = "No way!" +Item.GameMenuItem\Selected = #False +Item.GameMenuItem\TargetState = "MAIN_MENU" +AddElement(Menus("RLY_QUIT")\Entries()) +menus("RLY_QUIT")\Entries() = Item + + +*ActiveMenu.GameMenu = @Menus(CurrentState) + + ; Start the main loop which will create the window, wait for events and draw things ; on the screen. To escape from this loop, press ESC or close the window. If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCentered) OpenWindowedScreen(WindowID(0), 0, 0, Screen\Width, Screen\Height, 0, 0, 0) + InitTileset() + Repeat ; Event loop Repeat @@ -97,6 +98,8 @@ If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCent EndIf EndIf + Debug CurrentState + ; Handle the events for the current state GameStates(CurrentState)\HandleEventFun() @@ -109,11 +112,13 @@ If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCent EndIf Delay(1) - Until KeyboardPushed(#PB_Key_Escape) + Until CurrentState = "QUIT" EndIf End + + DataSection Gfx_Tileset: - IncludeBinary "../data/gfx/tileset01.bmp" \ No newline at end of file + IncludeBinary "../data/gfx/tileset01.bmp" diff --git a/src/Structs.pbi b/src/Structs.pbi index 9602bfd..0968576 100644 --- a/src/Structs.pbi +++ b/src/Structs.pbi @@ -17,7 +17,7 @@ EndStructure Structure GameMenuItem Label.s - TargetState.GameState + TargetState.s Selected.b EndStructure