a small demo to a base of a game

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

a small demo to a base of a game

Post by Lonely_Star77 »

hello...

i coded today some simple game first version... it's called "homeless - surviving the streets"

here is the code:

Code: Select all

; EnableExplicit

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

Dim food.s(0)
Dim work.s(0)
Dim phone.s(0)
Dim shelter.s(0)
Dim drugs.s(0)
Define r.s, i.i, health.i = 100, money.i = 120, days.i, message.s, isdone.b = #False

Procedure sappend(Array arr.s(1), temp.s, notFirstValue)     
  If notFirstValue
    i = ArraySize(arr()) + 1 
    ReDim arr(i)
  EndIf     
  arr(i) = temp
EndProcedure

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

Restore food
For i = 0 To 4
  Read.s r
  sappend(food(), r, i)
Next

Restore work
For i = 0 To 3
  Read.s r
  sappend(work(), r , i)
Next

Restore phone
For i = 0 To 4
  Read.s r
  sappend(phone(), r, i)
Next

Restore shelter
For i = 0 To 3
  Read.s r
  sappend(shelter(), r, i)
Next

Restore drugs
For i = 0 To 2
  Read.s r
  sappend(drugs(), r, i)
Next

; For i = 0 To 4
;   Debug phone(i)
; Next 



InitSprite()
InitKeyboard()

OpenWindow(#Window_Main, 0, 0, #Screen_Width, #Screen_Height, "homeless - game", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window_Main), 0, 0, #Screen_Width, #Screen_Height, #True, 0, 0)

Repeat
  Repeat
    Define Event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0
  ClearScreen(#Black)
  
  If StartDrawing(ScreenOutput())
    cprint(20, "HOMELESS - SURVIVING THE STREETS")
    cprint(40, "you are homeless on the streets.. choose what to do")
    cprint(60, "press key 1 to beg for food or money...")
    cprint(80, "press key 2 to try and find work...")
    cprint(100, "press key 3 to phone someone and ask for help...")
    cprint(120, "press key 4 to try and find some shelter for the night...")
    cprint(140, "press key 5 to buy cheep drugs and alcohol to forget your troubles...")
    cprint(160, "YOUR STATUS: health is " + Str(health) + "% money is " + Str(money) + " dollars on the streets: " + Str(days) + " days")
    cprint(200, message)
    StopDrawing()
  EndIf
  
  ExamineKeyboard()
   
  
    If KeyboardReleased(#PB_Key_1)
      message = food(Random(4,0))
      days + 1
      health - 5
      money - 10
    ElseIf KeyboardReleased(#PB_Key_2)
      message = work(Random(3,0))
      days + 1
      health - 5
      money - 10
    ElseIf KeyboardReleased(#PB_Key_3)
      message = phone(Random(4,0))
      days + 1
      health - 5
      money - 10
    ElseIf KeyboardReleased(#PB_Key_4)
      message = shelter(Random(3,0))
      days + 1
      health - 5
      money - 10
    ElseIf KeyboardReleased(#PB_Key_5)
      message = drugs(Random(2,0))
      days + 1
      health - 5
      money - 10
    EndIf
    
    If health < 1 : message = "GAME OVER YOU DIED - RIP" : EndIf
    If money < 0 : money = 0 : EndIf
    If health < 0 : Delay(2000) : End : EndIf
  FlipBuffers()
   
  Delay(3)
Until KeyboardPushed(#PB_Key_Escape) ;Or isdone = #True

DataSection
  food:
Data.s "YOU BEG FOR MONEY OR FOOD ALL DAY BUT EVERYONE PASSES YOU BY AND DON'T GIVE YOU NOTHING"
Data.s "SOME KIND FOLKS GIVE YOU SOME FOOD AND MONEY TO HELP YOU"
Data.s "A NICE LADY BUYS YOU LUNCH AT A RESTURANT AND GIVE YOU 40 DOLLAR - YOU TELL HER YOUR SAD STORY"
Data.s "NO ONE GIVES YOU NOTHING AT THE EVENNG A GANG OF BULLIES BEAT YOU UP AND RUB YOU OF WHAT YOU GOT LEFT"
Data.s "YOU ARE SO HUNGRY YOU EAT FROM THE TRASH AND GET FOOD POISON"

 work:
Data.s "YOU LOOK FOR A JOB BUT NO ONE IS INTERESTED"
Data.s "YOU FIND A TEMPORARY WORK BUT IT'S A SCAM AND YOU DON'T GET PAID AT THE END OF THE DAY ALL YOUR HATRD WORK WAS FOR NOTHING"
Data.s "YOU FIND WORK AT A LOCAL RESTURANT As A DISH WASHER YOU GET FOOD For FREE For A While UNTILL YOU ARE FIYERD"
Data.s "YOU FIND WORK BUT GET LAYED OFF REAL QUICK"

 phone:
Data.s "YOU PHONE YOUR GRANDMA AND TELL HER ABOUT YOUR SITUATION - YOU BOTH CRY AND YOU ARE AGAIN ALONE"
Data.s "YOU PHONE YOUR BROTHER BUT NO ONE ANSWERS"
Data.s "YOU PHONE YOUR SISTER BUT SHE SAYS SHE CAN'T HELP"
Data.s "YOU PHONE YOUR PARENTS AND THEY COME TO PICK YOU UP - AFTER A MONTH YOU HAVE A BIG ARGUMENT AND YOUR ON THE STREET AGAIN"
Data.s "YOU PHONE A HOT LINE THEY SEND A VAN TO PICK YOU UP YOU ARE PUT IN A TEMP HOUSE BUT SOON YOUR BACK ON THE STREETS"

 shelter:
Data.s "YOU FIND A QUITE PLACE TO SLEEP FOR THE NIGHT"
Data.s "YOU GO To A SHELTHER For THE HOMELESS - WHEN THE MORNING COMES YOU FIND YOU WHERE RUBBED FROM ALL YOU HAD"
Data.s "YOU TRY TO SLEEP UNDER A BRIDGE IT'S FREEZING COLD YOU FREEZE AND ALMOST DIE"
Data.s "YOU TRY YOUR LUCK A SHELTHER BY MORNING ALL IT GOOD AND YOUR READY TO SURVIVE ANOTHER DAY"

 drugs:
Data.s "YOU BUY CHEEP ALCOHOL AND FOR 24 HOURS YOU FORGET YOUR MISSRABLE LIFE AND ALL YOUR TROUBLES"
Data.s "YOU BY SOME CHEEP DRUGS AND SMOKE THEM - YOU GET SICK AND ALMOST DIE"
Data.s "YOU BUY CHEEP ALCOHOL ND GET SICK AND PASS OUT ON THE STREETS - YOU WAKE UP IN A HOSPITAL - AFTER 2 DAYS YOUR BACK TO THE STREETS"

EndDataSection