Page 1 of 1

S.P.I.D.L.E

Posted: Wed Jul 10, 2024 6:02 pm
by munfraid
Ok, here comes my little test project. ;)
Please read the comment on top of the code.

update: fixed some small bugs and added an ending ;)

Code: Select all

EnableExplicit

; #############################################################
;
; Welcome to SPIDLE
; 
; This is a simple idle game such as cookie clicker. 
; Click to add lines of code until you can buy upgrades. 
;
; The game is pretty much untested and probably has issues.
; It was just written to test new mobile ui in SpiderBasic 3. 
;
; It's recommended to use the cool new webview feature
; in the ide. Makes coding for mobile so much nicer! 
; Otherwise don't forget to resize your browser window 
; before running. 
;
;
; uncomment this line to see Spidle in Android style:
;MobileStyle(#PB_Mobile_Android) 
;
; #############################################################


Enumeration
  #up1b
  #up2b
  #up3b
  #up4b  
  #up5b  
  #up6b  
  #up7b  
  #up8b  
  #up1o
  #up1p
  #up2o
  #up2p
  #up3o
  #up3p
  #up4o
  #up4p
  #up5o
  #up5p
  #up6o
  #up6p
  #up7o
  #up7p
  #up8o
  #up8p
  #Info
  #InfoDialog
  #InfoDialogClose
  #WinDialog
  #TabHome 
  #TabBar
  #Laptop
  #CodeButton
  #loC
  #lpS
  #bank
  #bank2
  #upgrades
  #achievements
EndEnumeration

Enumeration images
  #IMG_Laptop
EndEnumeration

Global lines.d = 0
Global linesPerClick.d = 1
Global linesPerSecond.d = 0
Global linesBank.d = 0
Global multiplier.f = 1

;{ upgrades
Structure upgrade
  name.s
  action.s
  price.i
  loc.i
  multiply.f
  owned.i
  pID.i
  oID.i
  bID.i
EndStructure
Global NewList upgrades.upgrade()
AddElement(upgrades())
upgrades()\name = "CODE MONKEY"
upgrades()\action = "+1 line of code per second."
upgrades()\price = 15
upgrades()\loc = 1
upgrades()\pID = #up1p
upgrades()\oID = #up1o
upgrades()\bID = #up1b
AddElement(upgrades())
upgrades()\name = "PRO CODER"
upgrades()\action = "+10 lines of code per second."
upgrades()\price = 100
upgrades()\loc = 100
upgrades()\pID = #up2p
upgrades()\oID = #up2o
upgrades()\bID = #up2b
AddElement(upgrades())
upgrades()\name = "BETTER PIZZA"
upgrades()\action = "+10% output"
upgrades()\price = 2500
upgrades()\multiply = 0.1
upgrades()\pID = #up3p
upgrades()\oID = #up3o
upgrades()\bID = #up3b
AddElement(upgrades())
upgrades()\name = "TIPS FROM PETER"
upgrades()\action = "+500 lines of code per second."
upgrades()\price = 10000
upgrades()\loc = 500
upgrades()\pID = #up4p
upgrades()\oID = #up4o
upgrades()\bID = #up4b
AddElement(upgrades())
upgrades()\name = "READ THE FABULOUS MANUAL"
upgrades()\action = "+1000 lines of code per second."
upgrades()\price = 250000
upgrades()\loc = 1000
upgrades()\pID = #up5p
upgrades()\oID = #up5o
upgrades()\bID = #up5b
AddElement(upgrades())
upgrades()\name = "AI CODING SUPPORT"
upgrades()\action = "+10000 lines of code per second."
upgrades()\price = 10000000
upgrades()\loc = 10000
upgrades()\pID = #up6p
upgrades()\oID = #up6o
upgrades()\bID = #up6b
AddElement(upgrades())
upgrades()\name = "DOUBLE IMPACT"
upgrades()\action = "x2 output from each coder!"
upgrades()\price = 100000000
upgrades()\multiply = 2
upgrades()\pID = #up7p
upgrades()\oID = #up7o
upgrades()\bID = #up7b
AddElement(upgrades())
upgrades()\name = "RIGHT SAID FRED"
upgrades()\action = "x4 output with SB4!"
upgrades()\price = 1000000000
upgrades()\multiply = 4
upgrades()\pID = #up8p
upgrades()\oID = #up8o
upgrades()\bID = #up8b
;}

;{ achievements
Structure achievement
  name.s
  lines.d
  earned.i
EndStructure
Global NewList achievements.achievement()
AddElement(achievements())
achievements()\name = "Code 42 lines"
achievements()\lines = 42
AddElement(achievements())
achievements()\name = "Code 100 lines"
achievements()\lines = 100
AddElement(achievements())
achievements()\name = "Code 1000 lines"
achievements()\lines = 1000
AddElement(achievements())
achievements()\name = "Kaprekar!"
achievements()\lines = 6174
AddElement(achievements())
achievements()\name = "Code 100 000 lines"
achievements()\lines = 100000
AddElement(achievements())
achievements()\name = "Code 1 000 000 lines"
achievements()\lines = 1000000
AddElement(achievements())
achievements()\name = "Code 10 000 000 lines"
achievements()\lines = 10000000
AddElement(achievements())
achievements()\name = "Code 100 000 000 lines"
achievements()\lines = 100000000
AddElement(achievements())
achievements()\name = "Code 1 000 000 000 lines"
achievements()\lines = 1000000000
;}


;- IMAGES

ExamineDesktops()

;{ Laptop
If CreateImage(#IMG_Laptop, DesktopWidth(0)*0.9, DesktopWidth(0)*0.85, #PB_Ignore, #White)
  Define font = LoadFont(0, "Arial", DesktopWidth(0)*0.7)
  StartDrawing(ImageOutput(#IMG_Laptop))
  DrawingFont(FontID(0))
  DrawText(DesktopWidth(0)*0.45-TextWidth("💻")*0.5,0,"💻")
  StopDrawing()
EndIf
;}


;- DIALOGS

;{ Info
If ContainerMobile(#InfoDialog, #PB_Mobile_Dialog, "padding:12px")
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:12px")
  TextMobile(#PB_Any, "SpiderBasic 3 rocks!", #PB_Mobile_Center)
  CloseMobileContainer()
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:12px")
  ButtonMobile(#InfoDialogClose, "OK", #PB_Mobile_Center)
  CloseMobileContainer()
  
  CloseMobileContainer()
EndIf
; Trillionaire
If ContainerMobile(#WinDialog, #PB_Mobile_Dialog, "padding:12px")
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:16px")
  TextMobile(#PB_Any, "TRILLIONAIRE!", #PB_Mobile_Center)
  HtmlMobile("<br\>")
  TextMobile(#PB_Any, "You are now the richest person on earth. "+
                      "What will you do with all the money?", #PB_Mobile_Center)
  HtmlMobile("<br\>")
  TextMobile(#PB_Any, "Thanks for playing. Have a nice day!", #PB_Mobile_Center)
  CloseMobileContainer()
  
  CloseMobileContainer()
EndIf
;}


;- PAGES

;{ Home
If ContainerMobile(#PB_Any, #PB_Mobile_Template, "background-color:#ffffff;", "Home")
  
  ContainerMobile(#Laptop, #PB_Mobile_Row, "padding-top:30px" )
  ImageMobile(#Laptop, ImageID(#IMG_Laptop), #PB_Mobile_Center)
  CloseMobileContainer()
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row)
  ButtonMobile(#CodeButton, "Click to Code")
  CloseMobileContainer() 
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding-top:40px")
  TextMobile(#bank, "Cash: " + Str(linesBank)+ " €", #PB_Mobile_Center)
  CloseMobileContainer()
    
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:20px")
  TextMobile(#LoC, "Lines of Code: " + Str(lines) , #PB_Mobile_Center)
  CloseMobileContainer()
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding-bottom:100px")
  TextMobile(#LpS, "Lines per second: " + Str(linesPerSecond) , #PB_Mobile_Center)
  CloseMobileContainer()
  
  CloseMobileContainer()  
EndIf
;}

;{ Upgrades
If ContainerMobile(#PB_Any, #PB_Mobile_Template, "background-color:#ffffff;", "Upgrades")
      
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:20px" )
  TextMobile(#bank2, "Cash: "+Str(linesBank)+" €")    
  CloseMobileContainer()
  
  ResetList(upgrades())
  While NextElement(upgrades())
    ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:20px" )    
    TextMobile(upgrades()\oID, Str(upgrades()\owned), #PB_Mobile_Left)
    TextMobile(#PB_Any, upgrades()\name, #PB_Mobile_Center)
    HtmlMobile("<br\>")
    TextMobile(#PB_Any, upgrades()\action)
    HtmlMobile("<br\>")
    TextMobile(upgrades()\pID, "Cost: " + FormatNumber(upgrades()\price,0,",",".")+" €")
    ButtonMobile(upgrades()\bID, "Buy", #PB_Mobile_Right)
    CloseMobileContainer() 
  Wend
  
  CloseMobileContainer()  
  
EndIf
;}

;{ Achievements
If ContainerMobile(#PB_Any, #PB_Mobile_Template, "", "Achievements")
  
  ContainerMobile(#PB_Any, #PB_Mobile_Row, "padding:20px" )
  TextMobile(#PB_Any, "You got 1 from " + Str(ListSize(achievements()))+ " achievements.", #PB_Mobile_Center)    
  CloseMobileContainer()
   
  ListMobile(#achievements, #PB_Mobile_InSet)
  CloseMobileContainer()
  
  CloseMobileContainer()  
EndIf
;}


;- MAIN Container
;{
If ContainerMobile(#PB_Any, #PB_Mobile_Page, "", "")
  
  ToolBarMobile(#PB_Any)
  TextMobile(#TabHome, "S · P · I · D · L · E", #PB_Mobile_Center)
  ButtonMobile(#Info, "md-info", #PB_Mobile_Icon | #PB_Mobile_Right)
  CloseMobileContainer()
  
  TabBarMobile(#TabBar)
  AddTabBarMobileItem(#TabBar, "Home", "md-home", "md-home", "Home")
  AddTabBarMobileItem(#TabBar, "Upgrades", "md-caret-up-circle", "md-caret-up-circle", "Upgrades")
  AddTabBarMobileItem(#TabBar, "Achievements", "md-badge-check", "md-badge-check", "Achievements")
  CloseMobileContainer()
  
  CloseMobileContainer()
EndIf
;}


Procedure Update()
  If linesBank > 1000000000000
    RemoveTimer(0)
    ShowMobile(#WinDialog, #True)
    ProcedureReturn 0  
  EndIf
  SetMobileText(#loC, "Lines of code: " + FormatNumber(lines.d, 0, ",", "."))
  SetMobileText(#lpS, "Lines per second: " + FormatNumber(linesPerSecond.d, 0, ",", "."))
  SetMobileText(#bank, "Cash: " + FormatNumber(linesBank.d, 0, ",", ".") + " €")
  SetMobileText(#bank2, "Cash: " + FormatNumber(linesBank.d, 0, ",", ".") + " €")
  ResetList(upgrades())
  While NextElement(upgrades())
    DisableMobile(upgrades()\bID, #True)
    If linesBank > upgrades()\price-1
      DisableMobile(upgrades()\bID, #False)
      SetMobileAttribute(#TabBar, "badge", "+", 1)
    EndIf
  Wend
  ResetList(achievements())
  While NextElement(achievements())
    If achievements()\earned = 0
      If lines > achievements()\lines
        achievements()\earned = 1
        AddListMobileItem(#achievements, achievements()\name, #PB_Mobile_LongDivider)
        SetMobileAttribute(#TabBar, "badge", "+", 2)
      EndIf
    EndIf
  Wend
EndProcedure


AddTimer(0, 1000)
Procedure TimerEvents()
  lines + linesPerSecond
  linesBank + linesPerSecond*0.25
  Update()
EndProcedure
BindEvent(#PB_Event_Timer, @TimerEvents())


Procedure MobileEvents()
  Protected clicked = EventMobile()
  
  Select clicked
    Case #CodeButton
      lines + linesPerClick
      linesBank + linesPerClick*0.25
      Update()
      
    Case #up1B To #up8b
      SelectElement(upgrades(),clicked)
      linesBank - upgrades()\price
      linesPerSecond + upgrades()\loc
      multiplier + upgrades()\multiply
      linesPerSecond * multiplier
      SetMobileAttribute(#TabBar, "badge", "", 1)
      upgrades()\price * 1.15
      upgrades()\owned + 1 
      SetMobileText(upgrades()\pID, "Cost: " + Str(upgrades()\price) + " €")
      SetMobileText(upgrades()\oID, Str(upgrades()\owned))
      Update()
      
    Case #TabBar
      If GetMobileState(#TabBar) = 2
        SetMobileAttribute(#TabBar, "badge", "", 2)
      EndIf
      
    Case #Info
      ShowMobile(#InfoDialog, #True)
      
    Case #InfoDialogClose
      ShowMobile(#InfoDialog, #False)
    
  EndSelect
EndProcedure
BindEvent(#PB_Event_Mobile, @MobileEvents())
Thanks again to Fred for this great update! The new mobile ui ist awesome and with the new webview feature it's fun to code!

Re: S.P.I.D.L.E

Posted: Wed May 14, 2025 9:48 am
by Fred
Just seen this nice code, so created a new topic for it as it was buried into another one :)

Re: S.P.I.D.L.E

Posted: Wed May 14, 2025 3:24 pm
by Peter
munfraid wrote: Wed Jul 10, 2024 6:02 pm

Code: Select all

AddElement(upgrades())
upgrades()\name = "TIPS FROM PETER"
upgrades()\action = "+500 lines of code per second."
:lol: 👍

Re: S.P.I.D.L.E

Posted: Thu May 15, 2025 8:35 am
by Fred
Peter wrote: Wed May 14, 2025 3:24 pm
munfraid wrote: Wed Jul 10, 2024 6:02 pm

Code: Select all

AddElement(upgrades())
upgrades()\name = "TIPS FROM PETER"
upgrades()\action = "+500 lines of code per second."
:lol: 👍
:lol: . This small game remember me cookie clicker which is really fun to play :D

Re: S.P.I.D.L.E

Posted: Thu May 15, 2025 11:14 am
by Mindphazer
I am now officially the Richest Person on Earth :mrgreen:
Image

Re: S.P.I.D.L.E

Posted: Thu May 15, 2025 2:05 pm
by Quin
As someone who's absolutely addicted to idle games, this is super cool.
I plan to some day build a large idle game in SpiderBasic, but time just hasn't allowed for it.
Nice project, works here!

Re: S.P.I.D.L.E

Posted: Thu May 15, 2025 2:52 pm
by Fred
which idle games do you like the most ?

Re: S.P.I.D.L.E

Posted: Thu May 15, 2025 3:43 pm
by munfraid
Thanks Fred and everyone, it's nice to see SPIDLE getting some attention. :D

Yes, it's inspired by Cookie Clicker, for me the best idle game by far. I also like Spaceplan and Fill the Oceans. Other nice ones are Mr.Mine, Idle Wizzard or Idle Cave Miner.
Quin wrote: Thu May 15, 2025 2:05 pm I plan to some day build a large idle game in SpiderBasic, but time just hasn't allowed for it.
Same here, I'm just afraid it's as time consuming as playing them... :)