a small demo of a game base to an adventure game

Advanced game related topics
Lonely_Star77
User
User
Posts: 26
Joined: Sat Feb 20, 2021 3:39 pm

a small demo of a game base to an adventure game

Post by Lonely_Star77 »

hello :)

i've been working today on a small demo of a game base or game engine for an adventure game - i don't use graphics or sound just text...

you move around with the key arrows and exit with escape key...

code criticism and code review are welcomed

p.s. - i hope to add some sort of a open-direction(that you can pass through) and a closed direction (that you cannot pass through)

Code: Select all

EnableExplicit

#Window_Main = 0
#Screen_Width = 800
#Screen_Height = 600



Structure location
  Array compass.s(3)
  location.s
  Array directions.s(3)
  Array way_map.i(3)
EndStructure

Dim places.location(6)
Define.s r
Define.i i, ii


Procedure cprint(row.i, text.s)
  DrawText((#Screen_Width - TextWidth(text)) / 2, row , text, #White)
EndProcedure

Restore compass
For i = 0 To 3
  Read.s r
  places(0)\compass(i) = r
Next

Restore locations
For i = 0 To 6
  Read.s r
  places(i)\location = r
Next

Restore directions 
For i = 0 To 6
  For ii = 0 To 3
    Read.s r
    places(i)\directions(ii) = r
  Next
Next

InitKeyboard()
InitSprite()

OpenWindow(#Window_Main, 0, 0, #Screen_Width, #Screen_Height, "TEST", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window_Main), 0, 0, #Screen_Width, #Screen_Height, #True, 0, 0)

Procedure main(Array places.location(1))
  Define k.s
  Define.i x, z
  Repeat  
    ClearScreen(#Black)
    
    If x < 0 : x = 0 :EndIf
    If x > 6 :  x = 6 :EndIf
      If z > 3 : z = 0 :EndIf
        If z < 0 : z = 3 :EndIf
    
    
    
    If StartDrawing(ScreenOutput())
      cprint(20, places(0)\compass(z))
      cprint(40, places(x)\location)
      cprint(100, places(x)\directions(z))
      StopDrawing()
  EndIf
  
  
    ExamineKeyboard()
        
    If KeyboardReleased(#PB_Key_Up)
      x = x + 1
    EndIf
    
    If KeyboardReleased(#PB_Key_Down)
      x = x - 1
    EndIf
    
    If KeyboardReleased(#PB_Key_Right)
      z = z + 1
    EndIf
    
    If KeyboardReleased(#PB_Key_Left)
      z = z - 1
    EndIf
    
    
  ExamineKeyboard()
  
  FlipBuffers()
  
  Delay(3)
  
  Until KeyboardPushed(#PB_Key_Escape)
EndProcedure

main(places())

DataSection
  compass:
  Data.s "NORTH", "EAST", "SOUTH", "WEST"
  locations:
  Data.s "CELL ROOM", "CORADOOR", "HALLWAY", "CHAMBER", "ENTRANCE HALL", "GATEWAY", "OUTSIDE"
  directions:
  Data.s "a wall with bar windows"
  Data.s "a bed with a chair and a table"
  Data.s "a cell door"
  Data.s "a brick wall"
  
  Data.s "a cell door"
  Data.s "a long wall"
  Data.s "a nerrow path with stairs"
  Data.s "a high wall of bricks"
  
  Data.s "a narrow path with stairs"
  Data.s "a wall with mirrors"
  Data.s "an open door with light from it"
  Data.s "a wall with lots of pictures on it"
  
  Data.s "an open door"
  Data.s "a large chamber with windows"
  Data.s "a long path"
  Data.s "a brick wall"
  
  Data.s "a long path"
  Data.s "a large entarnce hall full of sheles with books"
  Data.s "a gate is seen far in the next room"
  Data.s "a brick wall with windows"
  
  Data.s "entery to a hall"
  Data.s "locked doors"
  Data.s "a gate to the outside"
  Data.s "a long tunnle with a locked door"
  
  Data.s "a gate to enter a castle"
  Data.s "green fileds in bright sun light"
  Data.s "a road to a far distenced village"
  Data.s "a forest in the distence"
  
EndDataSection
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: a small demo of a game base to an adventure game

Post by Tenaja »

Neat! Thanks for sharing.
Lonely_Star77
User
User
Posts: 26
Joined: Sat Feb 20, 2021 3:39 pm

Re: a small demo of a game base to an adventure game

Post by Lonely_Star77 »

hello :D

well i added a direction map to the engine so now if a direction is closed or blocked you cannot pass if it's open you can pass on

no need of down arrow key anymore just arrow key up/right/left will do

Code: Select all

EnableExplicit

#Window_Main = 0
#Screen_Width = 800
#Screen_Height = 600



Structure location
  Array compass.s(3)
  location.s
  Array directions.s(3)
  Array way_map.i(3)
EndStructure

Dim places.location(6)
Define.s r
Define.i i, ii

places(0)\way_map(0) = -1
places(0)\way_map(1) = -1
places(0)\way_map(2) = 1
places(0)\way_map(3) = -1

places(1)\way_map(0) = 0
places(1)\way_map(1) = -1
places(1)\way_map(2) = 2
places(1)\way_map(3) = -1

places(2)\way_map(0) = 1
places(2)\way_map(1) = -1
places(2)\way_map(2) = 3
places(2)\way_map(3) = -1

places(3)\way_map(0) = 2
places(3)\way_map(1) = -1
places(3)\way_map(2) = 4
places(3)\way_map(3) = -1

places(4)\way_map(0) = 3
places(4)\way_map(1) = -1
places(4)\way_map(2) = 5
places(4)\way_map(3) = -1

places(5)\way_map(0) = 4
places(5)\way_map(1) = -1
places(5)\way_map(2) = 6 
places(5)\way_map(3) = -1

places(6)\way_map(0) = 5
places(6)\way_map(1) = -1
places(6)\way_map(2) = -1
places(6)\way_map(3) = -1

Procedure cprint(row.i, text.s)
  DrawText((#Screen_Width - TextWidth(text)) / 2, row , text, #White)
EndProcedure

Restore compass
For i = 0 To 3
  Read.s r
  places(0)\compass(i) = r
Next

Restore locations
For i = 0 To 6
  Read.s r
  places(i)\location = r
Next

Restore directions 
For i = 0 To 6
  For ii = 0 To 3
    Read.s r
    places(i)\directions(ii) = r
  Next
Next

InitKeyboard()
InitSprite()

OpenWindow(#Window_Main, 0, 0, #Screen_Width, #Screen_Height, "TEST", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window_Main), 0, 0, #Screen_Width, #Screen_Height, #True, 0, 0)

Procedure main(Array places.location(1))
  Define k.s
  Define.i x, z
  Repeat  
    ClearScreen(#Black)
    
    If x < 0 : x = 0 :EndIf
    If x > 6 :  x = 6 :EndIf
      If z > 3 : z = 0 :EndIf
        If z < 0 : z = 3 :EndIf
    
    
    
    If StartDrawing(ScreenOutput())
      cprint(20, places(0)\compass(z))
      cprint(40, places(x)\location)
      cprint(100, places(x)\directions(z))
      StopDrawing()
  EndIf
  
  
    ExamineKeyboard()
        
    If KeyboardReleased(#PB_Key_Up)
      ;       x = x + 1
      If places(x)\way_map(z) <> -1
        x = places(x)\way_map(z)
        EndIf
    EndIf
    
;     If KeyboardReleased(#PB_Key_Down)
;       x = x - 1
;     EndIf
    
    If KeyboardReleased(#PB_Key_Right)
      z = z + 1
    EndIf
    
    If KeyboardReleased(#PB_Key_Left)
      z = z - 1
    EndIf
    
    
  ExamineKeyboard()
  
  FlipBuffers()
  
  Delay(3)
  
  Until KeyboardPushed(#PB_Key_Escape)
EndProcedure

main(places())

DataSection
  compass:
  Data.s "NORTH", "EAST", "SOUTH", "WEST"
  locations:
  Data.s "CELL ROOM", "CORADOOR", "HALLWAY", "CHAMBER", "ENTRANCE HALL", "GATEWAY", "OUTSIDE"
  directions:
  Data.s "a wall with bar windows"
  Data.s "a bed with a chair and a table"
  Data.s "a cell door"
  Data.s "a brick wall"
  
  Data.s "a cell door"
  Data.s "a long wall"
  Data.s "a nerrow path with stairs"
  Data.s "a high wall of bricks"
  
  Data.s "a narrow path with stairs"
  Data.s "a wall with mirrors"
  Data.s "an open door with light from it"
  Data.s "a wall with lots of pictures on it"
  
  Data.s "an open door"
  Data.s "a large chamber with windows"
  Data.s "a long path"
  Data.s "a brick wall"
  
  Data.s "a long path"
  Data.s "a large entarnce hall full of sheles with books"
  Data.s "a gate is seen far in the next room"
  Data.s "a brick wall with windows"
  
  Data.s "entery to a hall"
  Data.s "locked doors"
  Data.s "a gate to the outside"
  Data.s "a long tunnle with a locked door"
  
  Data.s "a gate to enter a castle"
  Data.s "green fileds in bright sun light"
  Data.s "a road to a far distenced village"
  Data.s "a forest in the distence"
  
EndDataSection
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: a small demo of a game base to an adventure game

Post by #NULL »

You are not processing the window events. You should process all available (and not just one) window event once per frame) if you are using a windowed screen.
https://www.purebasic.com/german/docume ... event.html
https://www.purebasic.com/german/docume ... event.html
Lonely_Star77
User
User
Posts: 26
Joined: Sat Feb 20, 2021 3:39 pm

Re: a small demo of a game base to an adventure game

Post by Lonely_Star77 »

hello @#NULL

do you mean something like that?

Code: Select all

EnableExplicit

#Window_Main = 0
#Screen_Width = 800
#Screen_Height = 600



Structure location
  Array compass.s(3)
  location.s
  Array directions.s(3)
  Array way_map.i(3)
EndStructure

Dim places.location(6)
Define.s r
Define.i i, ii

places(0)\way_map(0) = -1
places(0)\way_map(1) = -1
places(0)\way_map(2) = 1
places(0)\way_map(3) = -1

places(1)\way_map(0) = 0
places(1)\way_map(1) = -1
places(1)\way_map(2) = 2
places(1)\way_map(3) = -1

places(2)\way_map(0) = 1
places(2)\way_map(1) = -1
places(2)\way_map(2) = 3
places(2)\way_map(3) = -1

places(3)\way_map(0) = 2
places(3)\way_map(1) = -1
places(3)\way_map(2) = 4
places(3)\way_map(3) = -1

places(4)\way_map(0) = 3
places(4)\way_map(1) = -1
places(4)\way_map(2) = 5
places(4)\way_map(3) = -1

places(5)\way_map(0) = 4
places(5)\way_map(1) = -1
places(5)\way_map(2) = 6 
places(5)\way_map(3) = -1

places(6)\way_map(0) = 5
places(6)\way_map(1) = -1
places(6)\way_map(2) = -1
places(6)\way_map(3) = -1

Procedure cprint(row.i, text.s)
  DrawText((#Screen_Width - TextWidth(text)) / 2, row , text, #White)
EndProcedure

Restore compass
For i = 0 To 3
  Read.s r
  places(0)\compass(i) = r
Next

Restore locations
For i = 0 To 6
  Read.s r
  places(i)\location = r
Next

Restore directions 
For i = 0 To 6
  For ii = 0 To 3
    Read.s r
    places(i)\directions(ii) = r
  Next
Next

InitKeyboard()
InitSprite()

OpenWindow(#Window_Main, 0, 0, #Screen_Width, #Screen_Height, "TEST", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window_Main), 0, 0, #Screen_Width, #Screen_Height, #True, 0, 0)

Procedure main(Array places.location(1))
  Define k.s
  Define.i x, z
  Repeat
    Repeat
    Define Event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0    
    
    ClearScreen(#Black)
    
    If x < 0 : x = 0 :EndIf
    If x > 6 :  x = 6 :EndIf
      If z > 3 : z = 0 :EndIf
        If z < 0 : z = 3 :EndIf
    
    
    
    If StartDrawing(ScreenOutput())
      cprint(20, places(0)\compass(z))
      cprint(40, places(x)\location)
      cprint(100, places(x)\directions(z))
      StopDrawing()
  EndIf
  
  
    ExamineKeyboard()
        
    If KeyboardReleased(#PB_Key_Up)
      ;       x = x + 1
      If places(x)\way_map(z) <> -1
        x = places(x)\way_map(z)
        EndIf
    EndIf
    
;     If KeyboardReleased(#PB_Key_Down)
;       x = x - 1
;     EndIf
    
    If KeyboardReleased(#PB_Key_Right)
      z = z + 1
    EndIf
    
    If KeyboardReleased(#PB_Key_Left)
      z = z - 1
    EndIf
    
    
  ExamineKeyboard()
  
  FlipBuffers()
  
  Delay(3)
  
  Until KeyboardPushed(#PB_Key_Escape)
EndProcedure

main(places())

DataSection
  compass:
  Data.s "NORTH", "EAST", "SOUTH", "WEST"
  locations:
  Data.s "CELL ROOM", "CORADOOR", "HALLWAY", "CHAMBER", "ENTRANCE HALL", "GATEWAY", "OUTSIDE"
  directions:
  Data.s "a wall with bar windows"
  Data.s "a bed with a chair and a table"
  Data.s "a cell door"
  Data.s "a brick wall"
  
  Data.s "a cell door"
  Data.s "a long wall"
  Data.s "a nerrow path with stairs"
  Data.s "a high wall of bricks"
  
  Data.s "a narrow path with stairs"
  Data.s "a wall with mirrors"
  Data.s "an open door with light from it"
  Data.s "a wall with lots of pictures on it"
  
  Data.s "an open door"
  Data.s "a large chamber with windows"
  Data.s "a long path"
  Data.s "a brick wall"
  
  Data.s "a long path"
  Data.s "a large entarnce hall full of sheles with books"
  Data.s "a gate is seen far in the next room"
  Data.s "a brick wall with windows"
  
  Data.s "entery to a hall"
  Data.s "locked doors"
  Data.s "a gate to the outside"
  Data.s "a long tunnle with a locked door"
  
  Data.s "a gate to enter a castle"
  Data.s "green fileds in bright sun light"
  Data.s "a road to a far distenced village"
  Data.s "a forest in the distence"
  
EndDataSection
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: a small demo of a game base to an adventure game

Post by #NULL »

Yes, that's right. Now I can see something on linux. :)
Post Reply