an attempt to create a Tamagotchi cat program

Game development specific discussions.
ron77
Posts: 212
Joined: Feb 21, 2019 19:24

Re: an attempt to create a Tamagotchi cat program

Post by ron77 »

i'm sorry to hear that @BasicCoder2 i wish i knew hot to help but i don't you can though comment the lines of code where the fbsounds library is used or called...

hello everybody i added a new feature to the cat program... now it saves the cat data about name and counters in a text file when the program is terminated and then when you start again the program it continues right where it was left off... the only way to change your cat name is to let it die and start off with a new cat...

here is the code:

file "cat_obj.bi"

Code: Select all

#INCLUDE ONCE "fbsound_dynamic.bi"
#INCLUDE "vbcompat.bi"
DIM SHARED AS long hWave
DIM SHARED AS STRING k
CONST file AS STRING = "cat_log.txt"
'DIM SHARED isOut AS boolean = FALSE
'DIM SHARED text1 AS STRING
'DIM SHARED text2 AS STRING
'DIM SHARED AS INTEGER hunger
'hunger = INT(RND*101)
'ENUM poses
'   poses1
'   poses2
'   poses3
'END ENUM

TYPE cat
   PRIVATE:
   AS string cat_name
   PUBLIC:
   AS STRING text1, text2, text3, text4, text5, text6
   isOut AS boolean
   AS INTEGER hunger, pet_count, nap_count
   DECLARE PROPERTY cat_name1() AS STRING
   DECLARE PROPERTY cat_name1(BYVAL cat_name AS STRING)
   DECLARE SUB pet_cat()
   DECLARE SUB CP(row AS INTEGER, s AS STRING)
   DECLARE SUB display_screen(index AS INTEGER)
   DECLARE SUB make_sound(f AS STRING, t AS integer)
   DECLARE SUB animation(f AS STRING, t AS INTEGER)
   DECLARE SUB cat_hunger()
   DECLARE SUB nap_time(inx AS INTEGER)
   DECLARE SUB cat_napping()
   DECLARE SUB write_file(filename AS STRING)
   DECLARE SUB read_file(filename AS STRING)
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   
END TYPE

CONSTRUCTOR cat
   this.isOut = FALSE
   this.hunger = INT(RND*101)
   THIS.text1 = ""
   this.text2 = ""
   this.text3 = ""
   this.text4 = ""
   this.text5 = ""
   this.pet_count = INT(RND*201)
   this.nap_count = INT(RND*151)
   
END CONSTRUCTOR

DESTRUCTOR cat

END DESTRUCTOR

PROPERTY cat.cat_name1() AS String
   RETURN this.cat_name
END PROPERTY

PROPERTY cat.cat_name1(BYVAL cat_name AS STRING)
   this.cat_name = cat_name
END PROPERTY

SUB cat.write_file(filename AS STRING)
   DIM f AS LONG = FREEFILE()
   OPEN filename FOR OUTPUT AS #f
   write #f, cat_name1
   write #f, this.hunger
   write #f, THIS.pet_count
   write #f, this.nap_count
   write #f, this.isOut
   CLOSE #f
END SUB

SUB cat.read_file(filename AS STRING)
   DIM h AS LONG = FREEFILE()
   DIM fline AS STRING
   OPEN filename FOR INPUT AS #h
   'WHILE NOT (EOF)
      'LINE INPUT #h, fline
      INPUT #h, fline
      cat_name1 = fline
      INPUT #h, this.hunger
      INPUT #h, THIS.pet_count
      INPUT #h, this.nap_count
      INPUT #h, this.isOut
      CLOSE #h
   'WEND
END SUB



SUB cat.nap_time(inx AS INTEGER)
   SELECT CASE inx
      CASE 0:
         CLS
         CP 4, "------------"
         CP 5, "          / "
         CP 6, "         /  "
         CP 7, "        /   "
         CP 8, "       /    "
         CP 9, "      /     "
         CP 10, "     /      "
         CP 11, "    /       "
         CP 12, "   /        "
         CP 13, "  /         "
         CP 13, " /          "
         CP 14, "------------"
         CP 35, text5
         CP 15, "cat " & cat_name1
      CASE 1:
         CLS
         CP 4, "%%%%%%%%%%%%"
         CP 5, "          % "
         CP 6, "         %  "
         CP 7, "        %   "
         CP 8, "       %    "
         CP 9, "      %     "
         CP 10, "     %      "
         CP 11, "    %       "
         CP 12, "   %        "
         CP 13, "  %         "
         CP 13, " %          "
         CP 14, "%%%%%%%%%%%%"
         CP 35, text5
         CP 15, "cat " & cat_name1
      CASE 2:
         CLS
         CP 4, "zzzzzzzzzzzz"
         CP 5, "          z "
         CP 6, "         z  "
         CP 7, "        z   "
         CP 8, "       z    "
         CP 9, "      z     "
         CP 10, "     z      "
         CP 11, "    z       "
         CP 12, "   z        "
         CP 13, "  z         "
         CP 13, " z          "
         CP 14, "zzzzzzzzzzzz"
         CP 35, text5
         CP 15, "cat " & cat_name1
   END SELECT
END SUB



SUB cat.pet_cat()
   'this.text3 = "cat pet time is: " & this.pet_count
   THIS.pet_count -= 1
   
   IF THIS.pet_count <= 50 THEN
      this.text4 = "the cat need some petting press key 'p' to pet cat!"
   'ELSEIF this.pet_count <= 25 THEN
   '   this.isOut = TRUE
   ELSE
      this.text4 = ""
      
   ENDIF
   IF k = CHR(112) THEN 
      THIS.pet_count = INT(RND*101)
      this.text4 = ""
   ENDIF
   
END SUB

SUB cat.CP(row AS INTEGER, s AS STRING)
   LOCATE row, (100 - LEN(s)) / 2 : PRINT s
END SUB

SUB cat.display_screen(index AS integer)
   
   SELECT CASE index
      CASE 0:
         CLS
   CP 15, "cat " & cat_name1
   CP 4, "^                        ^"
   CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
   CP 6, "<| (( <|> ))  ||   ((  <|>  )) |>"
   CP 7, "_                              _"
   CP 8, "_                            _"
   CP 9, "_    >(::| * |::)<     _"
   CP 10, "        -------          "
   CP 11, "(  -----  )"
   CP 12, "\\---//"
   CP 13, "%%%"
   CP 34, text1
   CP 35, text2
   CP 32, text4
   CP 33, text3
   CP 31, text6
      CASE 1:
         CLS
   CP 15, "cat " & cat_name1
   CP 4, "^                        ^"
   CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
   CP 6, "<| (( <I> ))  ||   ((  <I>  )) |>"
   CP 7, "_                              _"
   CP 8, "_                            _"
   CP 9, "_    >(::| * |::)<     _"
   CP 10, "                          "
   CP 11, "(  OOOO  )"
   CP 12, "\\   //"
   CP 13, "%%%"
   CP 34, text1
   CP 35, text2
   CP 32, text4
   CP 33, text3
   CP 31, text6
      CASE 2:
         cls
   CP 15, "cat " & cat_name1
   CP 4, "^                        ^"
   CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
   CP 6, "<| (( <dOb> ))  ||   ((  <dOb>  )) |>"
   CP 7, "_                              _"
   CP 8, "_                            _"
   CP 9, "_    >(::| & |::)<     _"
   CP 10, "                          "
   CP 11, "(  ~~~~~  )"
   CP 12, "\\ ~~~ //"
   CP 13, "%%%"
   CP 34, text1
   CP 35, text2
   CP 32, text4
   CP 33, text3
   CP 31, text6
   END SELECT
END SUB

'SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
'   start:
'   DIM i AS INTEGER = 0
'   make_sound(f, t)
'	hunger = INT(RND*101)
'   DO
'      IF i >= 3 THEN i = 0
'      DISPLAY_SCREEN(i)
'      SLEEP 500
'      i += 1
'      cat_hunger(hunger)
'         
'      ENDIF
'   LOOP UNTIL INKEY <> ""
'   fbs_Destroy_Wave(@hWave)
'   SLEEP 1000
'   GOTO start
'END SUB
SUB cat.cat_napping()
   'this.text2 = this.text2 & " cat napping counter is: " & this.nap_count
   'this.nap_count -= 1
   DIM x AS INTEGER = 0
   DIM xx AS INTEGER = 50
   'IF this.nap_count <= 50 THEN
          DO
             nap_time(x)
             this.text5 = "NAP TIME!"
             x += 1
             xx -= 1
             SLEEP 250
             IF x >= 3 THEN x = 0
          LOOP UNTIL xx <= 0
          
   'ENDIF
   'this.nap_count = INT(RND*151)
END SUB
SUB cat.cat_hunger()
   'start:
   'hunger = INT(RND*101)
   'DO
   
      'this.hunger -= 1
      'this.text2 = this.text2 & "cat hunger is: " & hunger
      IF this.hunger < 25 THEN
         this.text1 = "cat is hungry! press key 'f' to feed it"
      ELSE
         this.text1 = ""
      'IF this.hunger >= 25 THEN
      ENDIF
      IF this.hunger <= 0 THEN
         'text2 = "cat is hungry! press any key to feed it"
         
         isOut = TRUE
         
      ENDIF
      IF k = CHR(102) THEN
         this.hunger = INT(RND*101)
      ENDIF
   
   'LOOP
   'GOTO start
   
END SUB



SUB cat.make_sound(f AS STRING, t AS INTEGER)
   'DIM AS Integer hWave
	fbs_Load_WAVFile(f , @hWave)
	fbs_Play_Wave(hWave , t)
	'SLEEP
  'While Inkey <> "":WEND
'	fbs_Destroy_Wave(@hWave)
END SUB

SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
   
   DO
      
      IF this.isOut = TRUE OR NOT FILEEXISTS(file) THEN 
      DIM catname AS STRING
      INPUT "enter cat name or enter 'quit' to exit: ", catname
      IF catname = "quit" THEN
         write_file(file)
         END
      ENDIF
      cat_name1 = catname
      this.hunger = INT(RND*101)
	   this.pet_count = INT(RND*201)
      'write_file(file)
      ELSE 
         read_file(file)
      'ELSE
         
      ENDIF
   this.isOut = FALSE
   DIM i AS INTEGER = 0
   make_sound(f, t)
	
	DIM x AS INTEGER = 0
   DIM xx AS INTEGER = 50
   DO
      k = INKEY
      IF THIS.nap_count > 50 THEN
      IF i >= 3 THEN i = 0
      DISPLAY_SCREEN(i)
      SLEEP 500
      i += 1
      cat_hunger()
         pet_cat()
         IF this.isOut = TRUE THEN EXIT DO
       this.text2 = " cat hunger is: " & this.hunger & " cat napping counter is: " & this.nap_count & _
       " cat pet time is: " & this.pet_count
       THIS.nap_count -= 1
       this.hunger -= 1
       IF k = CHR(27) THEN
          write_file(file)
          end
       ENDIF
      ELSEIF this.nap_count <= 50 THEN
          cat_napping()
          this.nap_count = INT(RND*151)
   ENDIF  
     
   LOOP
   fbs_Destroy_Wave(@hWave)
   IF THIS.isOut = TRUE THEN
   CLS
   write_file(file)
   this.text1 = "CAT DIED FROM HUNGER - YOU DIDN'T FEED IT ON TIME!"
   this.text4 = "PRESS ANY KEY TO START OVER WITH A NEW CAT!"
   CP 31, THIS.text1
   CP 34, this.text4
   SLEEP 
   'this.isOut = FALSE
   this.text1 = ""
   this.text4 = ""
   ENDIF
   loop UNTIL INKEY() = CHR(27)
  
END SUB


IF fbs_Init()=false then
  print "error: FBS_INIT() " & FBS_Get_PlugError()
  beep : sleep : end 1
end IF

'DIM SHARED AS long hWave
'DIM SHARED isOut AS boolean = FALSE
DIM SHARED fiori AS cat
main bas file - same as usual...

ron77 :)
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: an attempt to create a Tamagotchi cat program

Post by grindstone »

@BasicCoder2: I had the same issue. After copying the whole content of the fbsound-1.1 folder (including the subfolders) into the tamagotchi program folder it worked. No clue which of the files are really required.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: an attempt to create a Tamagotchi cat program

Post by MrSwiss »

@BasicCoder2,

just put this file (all in one) into the \tests\ folder of yoshi's extracted zip folder.
Compile and Run (path's should be propperly set)

@ron77,

have a look at the code changes in structure (indentation) and also removal of all "SHARED" stuff.
Cleaned all commented lines out.
Removed bug (only in FBC 64) also. (this is not based on your last changes!!!)
Required some changes to the cat Type's procedures, too.

Code: Select all

#INCLUDE ONCE "../inc/fbsound_dynamic.bi"

Const As Short scr_w = 800, scr_h = 600 ' screen constants

TYPE cat
    PRIVATE:
    AS string cat_name
    PUBLIC:
    AS STRING text1, text2, text3, text4, text5, text6
    isOut AS boolean
    AS INTEGER hunger, pet_count, nap_count
    DECLARE PROPERTY cat_name1() AS STRING
    DECLARE PROPERTY cat_name1(BYVAL cat_name AS STRING)
    DECLARE SUB pet_cat(key As String)
    DECLARE SUB CP(row AS INTEGER, s AS STRING)
    DECLARE SUB display_screen(index AS INTEGER)
    DECLARE SUB makeye_sound(f AS STRING, hWave As Integer, t AS integer)
    DECLARE SUB animation(f AS STRING, t AS INTEGER)
    DECLARE SUB cat_hunger(key As string)
    DECLARE SUB nap_time(inx AS INTEGER)
    DECLARE SUB cat_napping()
    DECLARE CONSTRUCTOR()
    DECLARE DESTRUCTOR()
End TYPE

CONSTRUCTOR cat
    this.isOut = FALSE
    this.hunger = INT(RND*101)
    THIS.text1 = ""
    this.text2 = ""
    this.text3 = ""
    this.text4 = ""
    this.text5 = ""
    this.pet_count = INT(RND*201)
    this.nap_count = INT(RND*151)
End CONSTRUCTOR

DESTRUCTOR cat
END DESTRUCTOR

PROPERTY cat.cat_name1() AS String
    Return this.cat_name
END PROPERTY

PROPERTY cat.cat_name1(BYVAL cat_name AS STRING)
    this.cat_name = cat_name
END PROPERTY


SUB cat.nap_time(inx AS INTEGER)
    Select CASE As Const inx
        Case 0
            CLS
            CP  4, "------------"
            CP  5, "          / "
            CP  6, "         /  "
            CP  7, "        /   "
            CP  8, "       /    "
            CP  9, "      /     "
            CP 10, "     /      "
            CP 11, "    /       "
            CP 12, "   /        "
            CP 13, "  /         "
            CP 13, " /          "
            CP 14, "------------"
            CP 35, text5
            CP 15, "cat " & cat_name1
        Case 1
            CLS
            CP  4, "%%%%%%%%%%%%"
            CP  5, "          % "
            CP  6, "         %  "
            CP  7, "        %   "
            CP  8, "       %    "
            CP  9, "      %     "
            CP 10, "     %      "
            CP 11, "    %       "
            CP 12, "   %        "
            CP 13, "  %         "
            CP 13, " %          "
            CP 14, "%%%%%%%%%%%%"
            CP 35, text5
            CP 15, "cat " & cat_name1
      CASE 2
            CLS
            CP  4, "zzzzzzzzzzzz"
            CP  5, "          z "
            CP  6, "         z  "
            CP  7, "        z   "
            CP  8, "       z    "
            CP  9, "      z     "
            CP 10, "     z      "
            CP 11, "    z       "
            CP 12, "   z        "
            CP 13, "  z         "
            CP 13, " z          "
            CP 14, "zzzzzzzzzzzz"
            CP 35, text5
            CP 15, "cat " & cat_name1
   END SELECT
END Sub

Sub cat.pet_cat(key As String)
   THIS.pet_count -= 1
   
   IF THIS.pet_count <= 50 THEN
      this.text4 = "the cat need some petting press keyey 'p' to pet cat!"
   ELSE
      this.text4 = ""
   ENDIF
   IF key = CHR(112) THEN
      THIS.pet_count = INT(RND*101)
      this.text4 = ""
   ENDIF
   
END SUB

SUB cat.CP(row AS INTEGER, s AS STRING)
   LOCATE row, scr_w \ 16 - (LEN(s) \ 2)
   PRINT s
END SUB

SUB cat.display_screen(index AS integer)
   
   SELECT CASE As Const index
       CASE 0
           Cls
           CP 15, "cat " & cat_name1
           CP  4, "^                        ^"
           CP  5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
           CP  6, "<| (( <|> ))  ||   ((  <|>  )) |>"
           CP  7, "_                              _"
           CP  8, "_                            _"
           CP  9, "_    >(::| * |::)<     _"
           CP 10, "        -------          "
           CP 11, "(  -----  )"
           CP 12, "\\---//"
           CP 13, "%%%"
           CP 34, text1
           CP 35, text2
           CP 32, text4
           CP 33, text3
           CP 31, text6
       CASE 1
           Cls
           CP 15, "cat " & cat_name1
           CP  4, "^                        ^"
           CP  5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
           CP  6, "<| (( <I> ))  ||   ((  <I>  )) |>"
           CP  7, "_                              _"
           CP  8, "_                            _"
           CP  9, "_    >(::| * |::)<     _"
           CP 10, "                          "
           CP 11, "(  OOOO  )"
           CP 12, "\\   //"
           CP 13, "%%%"
           CP 34, text1
           CP 35, text2
           CP 32, text4
           CP 33, text3
           CP 31, text6
       CASE 2
           Cls
           CP 15, "cat " & cat_name1
           CP  4, "^                        ^"
           CP  5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
           CP  6, "<| (( <dOb> ))  ||   ((  <dOb>  )) |>"
           CP  7, "_                              _"
           CP  8, "_                            _"
           CP  9, "_    >(::| & |::)<     _"
           CP 10, "                          "
           CP 11, "(  ~~~~~  )"
           CP 12, "\\ ~~~ //"
           CP 13, "%%%"
           CP 34, text1
           CP 35, text2
           CP 32, text4
           CP 33, text3
           CP 31, text6
   END SELECT
END SUB

Sub cat.cat_napping()
    Dim x AS INTEGER = 0
    Dim xx AS INTEGER = 50
    Do
        nap_time(x)
        this.text5 = "NAP TIME!"
        x += 1
        xx -= 1
        Sleep 250
        If x >= 3 THEN x = 0
    Loop UNTIL xx <= 0
End Sub

SUB cat.cat_hunger(key As String)
    IF this.hunger < 25 THEN
        this.text1 = "cat is hungry! press keyey 'f' to feed it"
    ELSE
        this.text1 = ""
    ENDIF
    IF this.hunger <= 0 Then isOut = TRUE
    IF key = CHR(102) Then this.hunger = INT(RND*101)
End Sub

SUB cat.makeye_sound(f AS STRING, hWave As Integer, t AS INTEGER)
    fbs_Load_WAVFile(f, @hWave)
    fbs_Play_Wave(hWave, t)
End SUB

SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
    Var key = "", hWave = 0
    
    With This   ' saves a lot of "This" typing !!!
        Do
            Dim catname AS STRING
            Input "enter cat name: ", catname
            cat_name1 = catname
         
            .isOut = FALSE
            Dim i AS INTEGER = 0
            makeye_sound(f, hWave, t)
            .hunger = INT(RND*101)
            .pet_count = INT(RND*201)
            Dim x AS INTEGER = 0
            Dim xx AS INTEGER = 50
            Do
                key = INkey
                If .nap_count > 50 THEN
                    If i >= 3 THEN i = 0
                    DISPLAY_SCREEN(i)
                    Sleep 500
                    i += 1
                    cat_hunger(key)
                    pet_cat(key)
                    If .isOut = TRUE THEN EXIT DO
                    .text2 = " cat hunger is: " & this.hunger & _
                                 " cat napping counter is: " & this.nap_count & _
                                 " cat pet time is: " & this.pet_count
                    .nap_count -= 1
                    .hunger -= 1
                    If key = CHR(27) THEN end
                ElseIf .nap_count <= 50 THEN
                    cat_napping()
                    .nap_count = INT(RND*151)
                EndIf
            Loop
            fbs_Destroy_Wave(@hWave)
            If .isOut = TRUE THEN
                Cls
                .text1 = "CAT DIED FROM HUNGER - YOU DIDN'T FEED IT ON TIME!"
                .text4 = "PRESS ANY keyEY TO START OVER WITH A NEW CAT!"
                CP 31, .text1
                CP 34, .text4
                Sleep
                .isOut = FALSE
                .text1 = ""
                .text4 = ""
            EndIf
       loop UNTIL Key = CHR(27)
    End With
End SUB

' ===== MAIN =====
IF Not fbs_Init() then
  print "error: FBS_INIT() " & FBS_Get_PlugError()
  beep : sleep : end 1
end If

DIM As cat  fiori

ScreenRes scr_w, scr_h
Width scr_w \ 8, scr_h \ 16
fiori.animation("../data/atem.wav", 1)
' ===== end MAIN =====
' ----- EOF -----
Since I don't have the .wav file, I've used one that yoshi provided.
ron77
Posts: 212
Joined: Feb 21, 2019 19:24

Re: an attempt to create a Tamagotchi cat program

Post by ron77 »

thank you a lot @MrSwiss!!! your code examples thought me important things i was not aware of!

here is my code update (i did on it format->auto-indent in FBIDE so the code indent got a little messed up) this time it's a full program single file!

file "main.bas"

Code: Select all

#INCLUDE ONCE "fbsound_dynamic.bi"
#INCLUDE "vbcompat.bi"

CONST AS SHORT scr_w = 800, scr_h = 600 ' screen constants

'DIM SHARED AS long hWave
'DIM SHARED AS STRING k
CONST file AS STRING = "cat_log.txt"
'DIM SHARED isOut AS boolean = FALSE
'DIM SHARED text1 AS STRING
'DIM SHARED text2 AS STRING
'DIM SHARED AS INTEGER hunger
'hunger = INT(RND*101)
ENUM age
   kitten
   young
   adult
   old
END ENUM

TYPE cat
   PRIVATE:
   AS STRING cat_name
   PUBLIC:
   AS STRING text1, text2, text3, text4, text5, text6, cat_age
   isOut AS boolean
   AS INTEGER hunger, pet_count, nap_count
   DECLARE PROPERTY cat_name1() AS STRING
   DECLARE PROPERTY cat_name1(BYVAL cat_name AS STRING)
   DECLARE SUB settings(i AS age)
   DECLARE SUB pet_cat(key AS STRING)
   DECLARE SUB CP(row AS INTEGER, s AS STRING)
   DECLARE SUB display_screen(index AS INTEGER)
   DECLARE SUB make_sound(f AS STRING, hWave AS INTEGER,t AS INTEGER)
   DECLARE SUB animation(f AS STRING, t AS INTEGER)
   DECLARE SUB cat_hunger(key AS STRING)
   DECLARE SUB nap_time(inx AS INTEGER)
   DECLARE SUB cat_napping()
   DECLARE SUB write_file(filename AS STRING)
   DECLARE SUB read_file(filename AS STRING)
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   
END TYPE

CONSTRUCTOR cat
this.isOut = FALSE
'this.hunger = INT(RND*101)
THIS.text1 = ""
this.text2 = ""
this.text3 = ""
this.text4 = ""
this.text5 = ""
'this.pet_count = INT(RND*201)
'this.nap_count = INT(RND*151)

END CONSTRUCTOR

DESTRUCTOR cat

END DESTRUCTOR

PROPERTY cat.cat_name1() AS STRING
RETURN this.cat_name
END PROPERTY

PROPERTY cat.cat_name1(BYVAL cat_name AS STRING)
this.cat_name = cat_name
END PROPERTY

SUB cat.write_file(filename AS STRING)
   DIM f AS LONG = FREEFILE()
   OPEN filename FOR OUTPUT AS #f
   WRITE #f, cat_name1
   WRITE #f, this.hunger
   WRITE #f, THIS.pet_count
   WRITE #f, this.nap_count
   WRITE #f, this.isOut
   WRITE #f, this.cat_age
   CLOSE #f
END SUB

SUB cat.read_file(filename AS STRING)
   DIM h AS LONG = FREEFILE()
   DIM fline AS STRING
   OPEN filename FOR INPUT AS #h
   'WHILE NOT (EOF)
   'LINE INPUT #h, fline
   INPUT #h, fline
   cat_name1 = fline
   INPUT #h, this.hunger
   INPUT #h, THIS.pet_count
   INPUT #h, this.nap_count
   INPUT #h, this.isOut
   INPUT #h, this.cat_age
   CLOSE #h
   'WEND
END SUB



SUB cat.nap_time(inx AS INTEGER)
   SELECT CASE inx
   CASE 0:
   CLS
   CP 4, "------------"
   CP 5, "          / "
   CP 6, "         /  "
   CP 7, "        /   "
   CP 8, "       /    "
   CP 9, "      /     "
   CP 10, "     /      "
   CP 11, "    /       "
   CP 12, "   /        "
   CP 13, "  /         "
   CP 13, " /          "
   CP 14, "------------"
   CP 35, text5
   CP 15, this.cat_age & " " & cat_name1
CASE 1:
CLS
CP 4, "%%%%%%%%%%%%"
CP 5, "          % "
CP 6, "         %  "
CP 7, "        %   "
CP 8, "       %    "
CP 9, "      %     "
CP 10, "     %      "
CP 11, "    %       "
CP 12, "   %        "
CP 13, "  %         "
CP 13, " %          "
CP 14, "%%%%%%%%%%%%"
CP 35, text5
CP 15, this.cat_age & " " & cat_name1
CASE 2:
CLS
CP 4, "zzzzzzzzzzzz"
CP 5, "          z "
CP 6, "         z  "
CP 7, "        z   "
CP 8, "       z    "
CP 9, "      z     "
CP 10, "     z      "
CP 11, "    z       "
CP 12, "   z        "
CP 13, "  z         "
CP 13, " z          "
CP 14, "zzzzzzzzzzzz"
CP 35, text5
CP 15, this.cat_age & " " & cat_name1
END SELECT
END SUB

SUB cat.settings(i AS age)
   SELECT CASE i
   CASE 0:
   this.hunger = INT(RND*101)
   this.pet_count = INT(RND*201)
   this.nap_count = INT(RND*151)
   this.cat_age = "kitten"
CASE 1:
this.hunger = INT(RND*201)
this.pet_count = INT(RND*301)
this.nap_count = INT(RND*250)
this.cat_age = "young cat"
CASE 2:
this.hunger = INT(RND*351)
this.pet_count = INT(RND*451)
this.nap_count = INT(RND*401)
this.cat_age = "adult cat"
CASE 3:
this.hunger = INT(RND*301)
this.pet_count = INT(RND*401)
this.nap_count = INT(RND*161)
this.cat_age = "old cat"   
END SELECT
END SUB




SUB cat.pet_cat(key AS STRING)
   'this.text3 = "cat pet time is: " & this.pet_count
   THIS.pet_count -= 1
   
   IF THIS.pet_count <= 50 THEN
      this.text4 = "the cat need some petting press key 'p' to pet cat!"
      'ELSEIF this.pet_count <= 25 THEN
      '   this.isOut = TRUE
   ELSE
      this.text4 = ""
      
      ENDIF
      IF key = CHR(112) THEN 
         THIS.pet_count += 1000
         this.text4 = ""
         ENDIF
         
      END SUB
      
      SUB cat.CP(row AS INTEGER, s AS STRING)
         LOCATE row, (100 - LEN(s)) / 2 : PRINT s
      END SUB
      
      SUB cat.display_screen(index AS INTEGER)
         
         SELECT CASE index
         CASE 0:
         CLS
         CP 15, this.cat_age & " " &cat_name1
         CP 4, "^                        ^"
         CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
         CP 6, "<| (( <|> ))  ||   ((  <|>  )) |>"
         CP 7, "_                              _"
         CP 8, "_                            _"
         CP 9, "_    >(::| * |::)<     _"
         CP 10, "        -------          "
         CP 11, "(  -----  )"
         CP 12, "\\---//"
         CP 13, "%%%"
         CP 34, text1
         CP 35, text2
         CP 32, text4
         CP 33, text3
         CP 31, text6
      CASE 1:
      CLS
      CP 15, this.cat_age & " " &cat_name1
      CP 4, "^                        ^"
      CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
      CP 6, "<| (( <I> ))  ||   ((  <I>  )) |>"
      CP 7, "_                              _"
      CP 8, "_                            _"
      CP 9, "_    >(::| * |::)<     _"
      CP 10, "                          "
      CP 11, "(  OOOO  )"
      CP 12, "\\   //"
      CP 13, "%%%"
      CP 34, text1
      CP 35, text2
      CP 32, text4
      CP 33, text3
      CP 31, text6
   CASE 2:
   CLS
   CP 15, this.cat_age &" "& cat_name1
   CP 4, "^                        ^"
   CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
   CP 6, "<| (( <dOb> ))  ||   ((  <dOb>  )) |>"
   CP 7, "_                              _"
   CP 8, "_                            _"
   CP 9, "_    >(::| & |::)<     _"
   CP 10, "                          "
   CP 11, "(  ~~~~~  )"
   CP 12, "\\ ~~~ //"
   CP 13, "%%%"
   CP 34, text1
   CP 35, text2
   CP 32, text4
   CP 33, text3
   CP 31, text6
END SELECT
END SUB

'SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
'   start:
'   DIM i AS INTEGER = 0
'   make_sound(f, t)
'	hunger = INT(RND*101)
'   DO
'      IF i >= 3 THEN i = 0
'      DISPLAY_SCREEN(i)
'      SLEEP 500
'      i += 1
'      cat_hunger(hunger)
'         
'      ENDIF
'   LOOP UNTIL INKEY <> ""
'   fbs_Destroy_Wave(@hWave)
'   SLEEP 1000
'   GOTO start
'END SUB
SUB cat.cat_napping()
   'this.text2 = this.text2 & " cat napping counter is: " & this.nap_count
   'this.nap_count -= 1
   DIM x AS INTEGER = 0
   DIM xx AS INTEGER = 50
   'IF this.nap_count <= 50 THEN
   DO
      nap_time(x)
      this.text5 = "NAP TIME!"
      x += 1
      xx -= 1
      SLEEP 250
      IF x >= 3 THEN x = 0
   LOOP UNTIL xx <= 0
   
   'ENDIF
   'this.nap_count = INT(RND*151)
END SUB
SUB cat.cat_hunger(key AS STRING)
   'start:
   'hunger = INT(RND*101)
   'DO
   
   'this.hunger -= 1
   'this.text2 = this.text2 & "cat hunger is: " & hunger
   IF this.hunger < 25 THEN
      this.text1 = "cat is hungry! press key 'f' to feed it"
   ELSE
      this.text1 = ""
      'IF this.hunger >= 25 THEN
      ENDIF
      IF this.hunger <= 0 THEN
         'text2 = "cat is hungry! press any key to feed it"
         
         isOut = TRUE
         
         ENDIF
         IF key = CHR(102) THEN
            this.hunger += 1000
            ENDIF
            
            'LOOP
            'GOTO start
            
         END SUB
         
         
         
         SUB cat.make_sound(f AS STRING, hWave AS INTEGER, t AS INTEGER)
            'DIM AS Integer hWave
            fbs_Load_WAVFile(f , @hWave)
            fbs_Play_Wave(hWave , t)
            'SLEEP
            'While Inkey <> "":WEND
            '	fbs_Destroy_Wave(@hWave)
         END SUB
         
         SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
            VAR key = "" , hwave = 0
            DO
               WITH THIS
                  IF isOut = TRUE OR NOT FILEEXISTS(file) THEN 
                     DIM AS STRING catname, age1
                     INPUT "enter cat name or enter 'quit' to exit: ", catname
                     IF catname = "quit" THEN
                        write_file(file)
                        END
                        ENDIF
                        cat_name1 = catname
                        INPUT "select age of cat - 0 for kitten, 1 for young, 2 for adult, 3 for old: ", age1
                        'age1 = VAL(age1)
                        settings(VAL(age1))
                        'this.hunger = INT(RND*101)
                        'this.pet_count = INT(RND*201)
                        'write_file(file)
                     ELSE 
                        read_file(file)
                        'ELSE
                        
                        ENDIF
                        isOut = FALSE
                        DIM i AS INTEGER = 0
                        make_sound(f,hWave, t)
                        
                        DIM x AS INTEGER = 0
                        DIM xx AS INTEGER = 50
                        DO
                           key = INKEY
                           IF nap_count > 50 THEN
                              IF i >= 3 THEN i = 0
                              DISPLAY_SCREEN(i)
                              SLEEP 500
                              i += 1
                              cat_hunger(key)
                              pet_cat(key)
                              IF isOut = TRUE THEN EXIT DO
                              text2 = " cat hunger is: " & hunger & " cat napping counter is: " & nap_count & _
                              " cat pet time is: " & pet_count
                              nap_count -= 1
                              hunger -= 1
                              IF key = CHR(27) THEN
                                 write_file(file)
                                 END
                                 ENDIF
                              ELSEIF nap_count <= 50 THEN
                                 cat_napping()
                                 nap_count = INT(RND*151)
                                 ENDIF  
                                 
                              LOOP
                              fbs_Destroy_Wave(@hWave)
                              IF isOut = TRUE THEN
                                 CLS
                                 write_file(file)
                                 text1 = "CAT DIED FROM HUNGER - YOU DIDN'T FEED IT ON TIME!"
                                 text4 = "PRESS ANY KEY TO START OVER WITH A NEW CAT!"
                                 CP 31, text1
                                 CP 34, text4
                                 SLEEP 
                                 'this.isOut = FALSE
                                 text1 = ""
                                 text4 = ""
                                 ENDIF
                              END WITH
                           LOOP UNTIL INKEY() = CHR(27)
                           
                        END SUB
                        
                        
                        IF fbs_Init()=false THEN
                           PRINT "error: FBS_INIT() " & FBS_Get_PlugError()
                           BEEP : SLEEP : END 1
                        END IF
                        
                        SCREENRES scr_w, scr_h
                        WIDTH scr_w \ 8, scr_h \ 16
                        DIM SHARED fiori AS cat
                        fiori.animation("cat_sound.wav", 1)
i have a question how can you preform auto-format with auto indent to a code ??? all i know is FBIde option and it is very old... and makes errors...

ron77 :-/
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: an attempt to create a Tamagotchi cat program

Post by MrSwiss »

On Windows, I'm using FBEdit (far more advanced features than FBIDE).
Get it from the German FreeBASIC website ... ver. 1.0.7.6c
If I'm on Linux (occasionally only) I'm using Geany.

The trick to NOT mess up 'formated' code posted is, have the IDE transform Tab's into Spaces.
(Forum translates Tab to 3 * Space, which isn't used by many. Most use either 2 or 4 indentation.)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: an attempt to create a Tamagotchi cat program

Post by BasicCoder2 »

@MrSwiss
I placed ron77's code in the tests folder. The test examples already there work fine.
fbsound-1.0 > tests
What are those rar files and should they be unzipped somehow?
just put this file (all in one) into the \tests\ folder of yoshi's extracted zip folder.
Compile and Run (path's should be propperly set
May I ask where I can get yoshi's extracted zip folder?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: an attempt to create a Tamagotchi cat program

Post by MrSwiss »

@BasicCoder2,

Don't use the OLD version 1.0 (best, delete it first), then get the version 1.1 (from here).
There is even version 1.2 out now, but it seems to still have problems in Linux.
It is a .zip file ... Windows 10 can unzip that without external program.
The directory structure is created on your HDD/SSD locally (by unzipping the file).
Take it from there ... and use the code from my post only (not ron77's).
Reason: in my code "relative paths" have been set for *.bi and *.wav files.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: an attempt to create a Tamagotchi cat program

Post by BasicCoder2 »

@ron77
Your code worked but there were some compiler warnings,
Compiler output:
C:\FreeBasic\fbsound-1.1\tests\catMeowRon77.bas(345) warning 38(0): Suspicious logic operation, mixed boolean and non-boolean operands
C:\FreeBasic\fbsound-1.1\tests\catMeowRon77.bas(355) warning 5(0): Implicit conversion, at parameter 1 (i) of SETTINGS()
Last edited by BasicCoder2 on Feb 02, 2021 23:57, edited 1 time in total.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: an attempt to create a Tamagotchi cat program

Post by BasicCoder2 »

@MrSwiss
Take it from there ... and use the code from my post only (not ron77's).
Reason: in my code "relative paths" have been set for *.bi and *.wav files.
I assume you mean this,
#INCLUDE ONCE "../inc/fbsound_dynamic.bi"

Your code works thank you. Now to go over it to see what ron77 has done :)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: an attempt to create a Tamagotchi cat program

Post by MrSwiss »

BasicCoder2 wrote:I assume you mean this,
#INCLUDE ONCE "../inc/fbsound_dynamic.bi"
Yes, that's it, among some other changes made.

They where needed to remove all the unneccessary "SHARED" variables.
(one of them erroneously declared as LONG, instead of INTEGER)
ron77
Posts: 212
Joined: Feb 21, 2019 19:24

Re: an attempt to create a Tamagotchi cat program

Post by ron77 »

hello all :)

here is the updated code of my Tamagotchi cat program... i've added DATEDIFF command plus saving the date serial to the text file "cat_log.txt" so now if you neglect your cat and don't open the program within 7 days your cat dies of being neglected and you have to start with a new cat all over again... i also removed all the commented lines from the code to make it more clean...

here is the updated code:

file "main.bas"

Code: Select all

#INCLUDE ONCE "fbsound_dynamic.bi"
#INCLUDE "vbcompat.bi"

CONST AS SHORT scr_w = 800, scr_h = 600 ' screen constants
CONST file AS STRING = "cat_log.txt"

ENUM age
   kitten
   young
   adult
   old
END ENUM

TYPE cat
   PRIVATE:
   AS STRING cat_name
   PUBLIC:
   AS DOUBLE d1, d2
   AS STRING text1, text2, text3, text4, text5, text6, cat_age
   AS boolean isOut, isneglect
   AS INTEGER hunger, pet_count, nap_count
   DECLARE PROPERTY cat_name1() AS STRING
   DECLARE PROPERTY cat_name1(BYVAL cat_name AS STRING)
   DECLARE SUB time_diff()
   DECLARE SUB settings(i AS age)
   DECLARE SUB pet_cat(key AS STRING)
   DECLARE SUB CP(row AS INTEGER, s AS STRING)
   DECLARE SUB display_screen(index AS INTEGER)
   DECLARE SUB make_sound(f AS STRING, hWave AS INTEGER,t AS INTEGER)
   DECLARE SUB animation(f AS STRING, t AS INTEGER)
   DECLARE SUB cat_hunger(key AS STRING)
   DECLARE SUB nap_time(inx AS INTEGER)
   DECLARE SUB cat_napping()
   DECLARE SUB write_file(filename AS STRING)
   DECLARE SUB read_file(filename AS STRING)
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   
END TYPE

CONSTRUCTOR cat
this.isOut = FALSE
THIS.text1 = ""
this.text2 = ""
this.text3 = ""
this.text4 = ""
this.text5 = ""
END CONSTRUCTOR

DESTRUCTOR cat

END DESTRUCTOR

PROPERTY cat.cat_name1() AS STRING
RETURN this.cat_name
END PROPERTY

PROPERTY cat.cat_name1(BYVAL cat_name AS STRING)
this.cat_name = cat_name
END PROPERTY

SUB cat.write_file(filename AS STRING)
   this.d1 = NOW()
   
   DIM f AS LONG = FREEFILE()
   OPEN filename FOR OUTPUT AS #f
   WRITE #f, cat_name1
   WRITE #f, this.hunger
   WRITE #f, THIS.pet_count
   WRITE #f, this.nap_count
   WRITE #f, this.isOut
   WRITE #f, this.cat_age
   write #f, this.d1
   CLOSE #f
END SUB

SUB cat.read_file(filename AS STRING)
   DIM h AS LONG = FREEFILE()
   DIM fline AS STRING
   OPEN filename FOR INPUT AS #h
   INPUT #h, fline
   cat_name1 = fline
   INPUT #h, this.hunger
   INPUT #h, THIS.pet_count
   INPUT #h, this.nap_count
   INPUT #h, this.isOut
   INPUT #h, this.cat_age
   INPUT #h, this.d1
   CLOSE #h
   
END SUB

sub cat.time_diff()
   this.d2 = NOW()
   IF DATEDIFF("d", this.d1, this.d2) > 7 THEN
      this.isneglect = TRUE
   ENDIF
END sub


SUB cat.nap_time(inx AS INTEGER)
   SELECT CASE inx
   CASE 0:
   CLS
   CP 4, "------------"
   CP 5, "          / "
   CP 6, "         /  "
   CP 7, "        /   "
   CP 8, "       /    "
   CP 9, "      /     "
   CP 10, "     /      "
   CP 11, "    /       "
   CP 12, "   /        "
   CP 13, "  /         "
   CP 13, " /          "
   CP 14, "------------"
   CP 35, text5
   CP 15, this.cat_age & " " & cat_name1
CASE 1:
CLS
CP 4, "%%%%%%%%%%%%"
CP 5, "          % "
CP 6, "         %  "
CP 7, "        %   "
CP 8, "       %    "
CP 9, "      %     "
CP 10, "     %      "
CP 11, "    %       "
CP 12, "   %        "
CP 13, "  %         "
CP 13, " %          "
CP 14, "%%%%%%%%%%%%"
CP 35, text5
CP 15, this.cat_age & " " & cat_name1
CASE 2:
CLS
CP 4, "zzzzzzzzzzzz"
CP 5, "          z "
CP 6, "         z  "
CP 7, "        z   "
CP 8, "       z    "
CP 9, "      z     "
CP 10, "     z      "
CP 11, "    z       "
CP 12, "   z        "
CP 13, "  z         "
CP 13, " z          "
CP 14, "zzzzzzzzzzzz"
CP 35, text5
CP 15, this.cat_age & " " & cat_name1
END SELECT
END SUB

SUB cat.settings(i AS age)
   SELECT CASE i
   CASE 0:
   this.hunger = INT(RND*101)
   this.pet_count = INT(RND*201)
   this.nap_count = INT(RND*151)
   this.cat_age = "kitten"
CASE 1:
this.hunger = INT(RND*201)
this.pet_count = INT(RND*301)
this.nap_count = INT(RND*250)
this.cat_age = "young cat"
CASE 2:
this.hunger = INT(RND*351)
this.pet_count = INT(RND*451)
this.nap_count = INT(RND*401)
this.cat_age = "adult cat"
CASE 3:
this.hunger = INT(RND*301)
this.pet_count = INT(RND*401)
this.nap_count = INT(RND*161)
this.cat_age = "old cat"   
END SELECT
END SUB




SUB cat.pet_cat(key AS STRING)
   
   THIS.pet_count -= 1
   
   IF THIS.pet_count <= 50 THEN
      this.text4 = "the cat need some petting press key 'p' to pet cat!"
      
   ELSE
      this.text4 = ""
      
      ENDIF
      IF key = CHR(112) THEN 
         THIS.pet_count += 1000
         this.text4 = ""
         ENDIF
         
      END SUB
      
      SUB cat.CP(row AS INTEGER, s AS STRING)
         LOCATE row, (100 - LEN(s)) / 2 : PRINT s
      END SUB
      
      SUB cat.display_screen(index AS INTEGER)
         
         SELECT CASE index
         CASE 0:
         CLS
         CP 15, this.cat_age & " " &cat_name1
         CP 4, "^                        ^"
         CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
         CP 6, "<| (( <|> ))  ||   ((  <|>  )) |>"
         CP 7, "_                              _"
         CP 8, "_                            _"
         CP 9, "_    >(::| * |::)<     _"
         CP 10, "        -------          "
         CP 11, "(  -----  )"
         CP 12, "\\---//"
         CP 13, "%%%"
         CP 34, text1
         CP 35, text2
         CP 32, text4
         CP 33, text3
         CP 31, text6
      CASE 1:
      CLS
      CP 15, this.cat_age & " " &cat_name1
      CP 4, "^                        ^"
      CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
      CP 6, "<| (( <I> ))  ||   ((  <I>  )) |>"
      CP 7, "_                              _"
      CP 8, "_                            _"
      CP 9, "_    >(::| * |::)<     _"
      CP 10, "                          "
      CP 11, "(  OOOO  )"
      CP 12, "\\   //"
      CP 13, "%%%"
      CP 34, text1
      CP 35, text2
      CP 32, text4
      CP 33, text3
      CP 31, text6
   CASE 2:
   CLS
   CP 15, this.cat_age &" "& cat_name1
   CP 4, "^                        ^"
   CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
   CP 6, "<| (( <dOb> ))  ||   ((  <dOb>  )) |>"
   CP 7, "_                              _"
   CP 8, "_                            _"
   CP 9, "_    >(::| & |::)<     _"
   CP 10, "                          "
   CP 11, "(  ~~~~~  )"
   CP 12, "\\ ~~~ //"
   CP 13, "%%%"
   CP 34, text1
   CP 35, text2
   CP 32, text4
   CP 33, text3
   CP 31, text6
END SELECT
END SUB

SUB cat.cat_napping()
   
   DIM x AS INTEGER = 0
   DIM xx AS INTEGER = 50
   
   DO
      nap_time(x)
      this.text5 = "NAP TIME!"
      x += 1
      xx -= 1
      SLEEP 250
      IF x >= 3 THEN x = 0
   LOOP UNTIL xx <= 0
   
END SUB
SUB cat.cat_hunger(key AS STRING)
   
   IF this.hunger < 25 THEN
      this.text1 = "cat is hungry! press key 'f' to feed it"
   ELSE
      this.text1 = ""

   ENDIF
   IF this.hunger <= -450 THEN
     isOut = TRUE
   
   ENDIF
   IF key = CHR(102) THEN
      this.hunger += 1000
   ENDIF
END SUB
         
         
         
SUB cat.make_sound(f AS STRING, hWave AS INTEGER, t AS INTEGER)
   
   fbs_Load_WAVFile(f , @hWave)
   fbs_Play_Wave(hWave , t)
   
END SUB
         
SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
         VAR key = "" , hwave = 0
         DO
      WITH THIS
            IF isOut = TRUE OR NOT FILEEXISTS(file) OR isNeglect = TRUE THEN 
               DIM AS STRING catname, age1
               INPUT "enter cat name or enter 'quit' to exit: ", catname
               IF catname = "quit" THEN
                  write_file(file)
                  END
               ENDIF
               cat_name1 = catname
               INPUT "select age of cat - 0 for kitten, 1 for young, 2 for adult, 3 for old: ", age1
               settings(VAL(age1))
            
            ELSE 
               read_file(file)
            ENDIF
               isOut = FALSE
               isNeglect = FALSE 
            DIM i AS INTEGER = 0
            make_sound(f,hWave, t)
                        
            DIM x AS INTEGER = 0
            DIM xx AS INTEGER = 50
            DO
                  key = INKEY
               IF nap_count > 50 THEN
                  IF key = CHR(115) THEN
                     make_sound(f,hWave, t)
                  ENDIF
                  
                  IF i >= 3 THEN i = 0
                     DISPLAY_SCREEN(i)
                     SLEEP 500
                     i += 1
                     cat_hunger(key)
                     pet_cat(key)
                     time_diff()
                  IF isOut = TRUE OR isneglect = TRUE THEN EXIT DO
                     text2 = " cat hunger is: " & hunger & " cat napping counter is: " & nap_count & _
                     " cat pet time is: " & pet_count
                     nap_count -= 1
                     hunger -= 1
                  IF key = CHR(27) THEN
                     write_file(file)
                     END
                  ENDIF
               ELSEIF nap_count <= 50 THEN
                  cat_napping()
                  nap_count = INT(RND*151)
               ENDIF  
                                 
            LOOP
               fbs_Destroy_Wave(@hWave)
         IF isOut = TRUE OR isNeglect = TRUE THEN
            CLS
               
            text2 = "IT'S BEEN " & DATEDIFF("d", this.d1, this.d2) & " MINUTES SINCE YOU LAST OPEN THE PROGRAM"
            text1 = "CAT DIED FROM NEGLECT!!!"
            text4 = "PRESS ANY KEY TO START OVER WITH A NEW CAT!"
            CP 31, text1
            CP 34, text4
            CP 30, text2
            SLEEP 
            cls
            write_file(file)
         ENDIF
      END WITH
   LOOP UNTIL INKEY() = CHR(27)
                           
END SUB


IF fbs_Init()=false THEN
PRINT "error: FBS_INIT() " & FBS_Get_PlugError()
BEEP : SLEEP : END 1
END IF

SCREENRES scr_w, scr_h
WIDTH scr_w \ 8, scr_h \ 16
DIM SHARED fiori AS cat
fiori.animation("cat_sound.wav", 1)
i'm getting these warning from the compiler anyone have any idea what i'm doing wrong? or how do i fix it? AND can anyone give me any more ideas as to how to improve or what to add to my Tamagotchi cat program?

Code: Select all

cat_obj_2.bas(309) warning 38(0): Suspicious logic operation, mixed boolean and non-boolean operands
cat_obj_2.bas(309) warning 38(0): Suspicious logic operation, mixed boolean and non-boolean operands
cat_obj_2.bas(318) warning 5(0): Implicit conversion, at parameter 1 (i) of SETTINGS()
ron77 :)
Xusinboy Bekchanov
Posts: 783
Joined: Jul 26, 2018 18:28

Re: an attempt to create a Tamagotchi cat program

Post by Xusinboy Bekchanov »

ron77 wrote: i'm getting these warning from the compiler anyone have any idea what i'm doing wrong? or how do i fix it? AND can anyone give me any more ideas as to how to improve or what to add to my Tamagotchi cat program?

Code: Select all

cat_obj_2.bas(309) warning 38(0): Suspicious logic operation, mixed boolean and non-boolean operands
cat_obj_2.bas(309) warning 38(0): Suspicious logic operation, mixed boolean and non-boolean operands
cat_obj_2.bas(318) warning 5(0): Implicit conversion, at parameter 1 (i) of SETTINGS()
ron77 :)
This is how it compiles without warnings:

Code: Select all

#include once "fbsound_dynamic.bi"
#include "vbcompat.bi"

Const As Short scr_w = 800, scr_h = 600 ' screen constants
Const file As String = "cat_log.txt"

Enum age
	kitten
	young
	adult
	old
End Enum

Type cat
Private:
	As String cat_name
Public:
	As Double d1, d2
	As String text1, text2, text3, text4, text5, text6, cat_age
	As Boolean isOut, isneglect
	As Integer hunger, pet_count, nap_count
	Declare Property cat_name1() As String
	Declare Property cat_name1(ByVal cat_name As String)
	Declare Sub time_diff()
	Declare Sub settings(i As age)
	Declare Sub pet_cat(key As String)
	Declare Sub CP(row As Integer, s As String)
	Declare Sub display_screen(index As Integer)
	Declare Sub make_sound(f As String, hWave As Integer,t As Integer)
	Declare Sub animation(f As String, t As Integer)
	Declare Sub cat_hunger(key As String)
	Declare Sub nap_time(inx As Integer)
	Declare Sub cat_napping()
	Declare Sub write_file(filename As String)
	Declare Sub read_file(filename As String)
	Declare Constructor()
	Declare Destructor()
	
End Type

Constructor cat
	This.isOut = False
	This.text1 = ""
	This.text2 = ""
	This.text3 = ""
	This.text4 = ""
	This.text5 = ""
End Constructor

Destructor cat
	
End Destructor

Property cat.cat_name1() As String
	Return This.cat_name
End Property

Property cat.cat_name1(ByVal cat_name As String)
	This.cat_name = cat_name
End Property

Sub cat.write_file(filename As String)
	This.d1 = Now()
	
	Dim f As Long = FreeFile()
	Open filename For Output As #f
	Write #f, cat_name1
	Write #f, This.hunger
	Write #f, This.pet_count
	Write #f, This.nap_count
	Write #f, This.isOut
	Write #f, This.cat_age
	Write #f, This.d1
	Close #f
End Sub

Sub cat.read_file(filename As String)
	Dim h As Long = FreeFile()
	Dim fline As String
	Open filename For Input As #h
	Input #h, fline
	cat_name1 = fline
	Input #h, This.hunger
	Input #h, This.pet_count
	Input #h, This.nap_count
	Input #h, This.isOut
	Input #h, This.cat_age
	Input #h, This.d1
	Close #h
	
End Sub

Sub cat.time_diff()
	This.d2 = Now()
	If DateDiff("d", This.d1, This.d2) > 7 Then
		This.isneglect = True
	EndIf
End Sub


Sub cat.nap_time(inx As Integer)
	Select Case inx
	Case 0:
		Cls
		CP 4, "------------"
		CP 5, "          / "
		CP 6, "         /  "
		CP 7, "        /   "
		CP 8, "       /    "
		CP 9, "      /     "
		CP 10, "     /      "
		CP 11, "    /       "
		CP 12, "   /        "
		CP 13, "  /         "
		CP 13, " /          "
		CP 14, "------------"
		CP 35, text5
		CP 15, This.cat_age & " " & cat_name1
	Case 1:
		Cls
		CP 4, "%%%%%%%%%%%%"
		CP 5, "          % "
		CP 6, "         %  "
		CP 7, "        %   "
		CP 8, "       %    "
		CP 9, "      %     "
		CP 10, "     %      "
		CP 11, "    %       "
		CP 12, "   %        "
		CP 13, "  %         "
		CP 13, " %          "
		CP 14, "%%%%%%%%%%%%"
		CP 35, text5
		CP 15, This.cat_age & " " & cat_name1
	Case 2:
		Cls
		CP 4, "zzzzzzzzzzzz"
		CP 5, "          z "
		CP 6, "         z  "
		CP 7, "        z   "
		CP 8, "       z    "
		CP 9, "      z     "
		CP 10, "     z      "
		CP 11, "    z       "
		CP 12, "   z        "
		CP 13, "  z         "
		CP 13, " z          "
		CP 14, "zzzzzzzzzzzz"
		CP 35, text5
		CP 15, This.cat_age & " " & cat_name1
	End Select
End Sub

Sub cat.settings(i As age)
	Select Case i
	Case 0:
		This.hunger = Int(Rnd*101)
		This.pet_count = Int(Rnd*201)
		This.nap_count = Int(Rnd*151)
		This.cat_age = "kitten"
	Case 1:
		This.hunger = Int(Rnd*201)
		This.pet_count = Int(Rnd*301)
		This.nap_count = Int(Rnd*250)
		This.cat_age = "young cat"
	Case 2:
		This.hunger = Int(Rnd*351)
		This.pet_count = Int(Rnd*451)
		This.nap_count = Int(Rnd*401)
		This.cat_age = "adult cat"
	Case 3:
		This.hunger = Int(Rnd*301)
		This.pet_count = Int(Rnd*401)
		This.nap_count = Int(Rnd*161)
		This.cat_age = "old cat"
	End Select
End Sub




Sub cat.pet_cat(key As String)
	
	This.pet_count -= 1
	
	If This.pet_count <= 50 Then
		This.text4 = "the cat need some petting press key 'p' to pet cat!"
		
	Else
		This.text4 = ""
		
	EndIf
	If key = Chr(112) Then
		This.pet_count += 1000
		This.text4 = ""
	EndIf
	
End Sub

Sub cat.CP(row As Integer, s As String)
	Locate row, (100 - Len(s)) / 2 : Print s
End Sub

Sub cat.display_screen(index As Integer)
	
	Select Case index
	Case 0:
		Cls
		CP 15, This.cat_age & " " &cat_name1
		CP 4, "^                        ^"
		CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
		CP 6, "<| (( <|> ))  ||   ((  <|>  )) |>"
		CP 7, "_                              _"
		CP 8, "_                            _"
		CP 9, "_    >(::| * |::)<     _"
		CP 10, "        -------          "
		CP 11, "(  -----  )"
		CP 12, "\\---//"
		CP 13, "%%%"
		CP 34, text1
		CP 35, text2
		CP 32, text4
		CP 33, text3
		CP 31, text6
	Case 1:
		Cls
		CP 15, This.cat_age & " " &cat_name1
		CP 4, "^                        ^"
		CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
		CP 6, "<| (( <I> ))  ||   ((  <I>  )) |>"
		CP 7, "_                              _"
		CP 8, "_                            _"
		CP 9, "_    >(::| * |::)<     _"
		CP 10, "                          "
		CP 11, "(  OOOO  )"
		CP 12, "\\   //"
		CP 13, "%%%"
		CP 34, text1
		CP 35, text2
		CP 32, text4
		CP 33, text3
		CP 31, text6
	Case 2:
		Cls
		CP 15, This.cat_age &" "& cat_name1
		CP 4, "^                        ^"
		CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
		CP 6, "<| (( <dOb> ))  ||   ((  <dOb>  )) |>"
		CP 7, "_                              _"
		CP 8, "_                            _"
		CP 9, "_    >(::| & |::)<     _"
		CP 10, "                          "
		CP 11, "(  ~~~~~  )"
		CP 12, "\\ ~~~ //"
		CP 13, "%%%"
		CP 34, text1
		CP 35, text2
		CP 32, text4
		CP 33, text3
		CP 31, text6
	End Select
End Sub

Sub cat.cat_napping()
	
	Dim x As Integer = 0
	Dim xx As Integer = 50
	
	Do
		nap_time(x)
		This.text5 = "NAP TIME!"
		x += 1
		xx -= 1
		Sleep 250
		If x >= 3 Then x = 0
	Loop Until xx <= 0
	
End Sub
Sub cat.cat_hunger(key As String)
	
	If This.hunger < 25 Then
		This.text1 = "cat is hungry! press key 'f' to feed it"
	Else
		This.text1 = ""
		
	EndIf
	If This.hunger <= -450 Then
		isOut = True
		
	EndIf
	If key = Chr(102) Then
		This.hunger += 1000
	EndIf
End Sub



Sub cat.make_sound(f As String, hWave As Integer, t As Integer)
	
	fbs_Load_WAVFile(f , @hWave)
	fbs_Play_Wave(hWave , t)
	
End Sub

Sub CAT.ANIMATION(f As String, t As Integer)
	Dim As String key = ""
	Var hwave = 0
	Do
		With This
			If CInt(isOut = True) Or CInt(Not FileExists(file)) Or CInt(isNeglect = True) Then
				Dim As String catname, age1
				Input "enter cat name or enter 'quit' to exit: ", catname
				If catname = "quit" Then
					write_file(file)
					End
				EndIf
				cat_name1 = catname
				Input "select age of cat - 0 for kitten, 1 for young, 2 for adult, 3 for old: ", age1
				settings(Cast(Age, Val(age1)))
				
			Else
				read_file(file)
			EndIf
			isOut = False
			isNeglect = False
			Dim i As Integer = 0
			make_sound(f,hWave, t)
			
			Dim x As Integer = 0
			Dim xx As Integer = 50
			Do
				key = Inkey
				If nap_count > 50 Then
					If key = Chr(115) Then
						make_sound(f,hWave, t)
					EndIf
					
					If i >= 3 Then i = 0
					DISPLAY_SCREEN(i)
					Sleep 500
					i += 1
					cat_hunger(key)
					pet_cat(key)
					time_diff()
					If isOut = True Or isneglect = True Then Exit Do
					text2 = " cat hunger is: " & hunger & " cat napping counter is: " & nap_count & _
					" cat pet time is: " & pet_count
					nap_count -= 1
					hunger -= 1
					If key = Chr(27) Then
						write_file(file)
						End
					EndIf
				ElseIf nap_count <= 50 Then
					cat_napping()
					nap_count = Int(Rnd*151)
				EndIf
				
			Loop
			fbs_Destroy_Wave(@hWave)
			If isOut = True Or isNeglect = True Then
				Cls
				
				text2 = "IT'S BEEN " & DateDiff("d", This.d1, This.d2) & " MINUTES SINCE YOU LAST OPEN THE PROGRAM"
				text1 = "CAT DIED FROM NEGLECT!!!"
				text4 = "PRESS ANY KEY TO START OVER WITH A NEW CAT!"
				CP 31, text1
				CP 34, text4
				CP 30, text2
				Sleep
				Cls
				write_file(file)
			EndIf
		End With
	Loop Until Inkey() = Chr(27)
	
End Sub


If fbs_Init()=False Then
	Print "error: FBS_INIT() " & FBS_Get_PlugError()
	Beep : Sleep : End 1
End If

ScreenRes scr_w, scr_h
Width scr_w \ 8, scr_h \ 16
Dim Shared fiori As cat
fiori.animation("cat_sound.wav", 1)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: an attempt to create a Tamagotchi cat program

Post by MrSwiss »

@Xusinboy Bekchanov,

your method to get the warnings resolved is simply overkill.
  • instead of 3 * CInt(), 1 * CBool(FileExists())
    instead of complex casting, ValInt() does it (instead of Val())
Overdoing things is usually paid for in lost speed.
Xusinboy Bekchanov
Posts: 783
Joined: Jul 26, 2018 18:28

Re: an attempt to create a Tamagotchi cat program

Post by Xusinboy Bekchanov »

MrSwiss wrote:@Xusinboy Bekchanov,

your method to get the warnings resolved is simply overkill.
  • instead of 3 * CInt(), 1 * CBool(FileExists())
    instead of complex casting, ValInt() does it (instead of Val())
Overdoing things is usually payd for in lost speed.
Thanks for the right way.
ron77
Posts: 212
Joined: Feb 21, 2019 19:24

Re: an attempt to create a Tamagotchi cat program

Post by ron77 »

okay... thank you all...

i took this now a little bit to the next level... added graphical animation

Image

here is the updated code soon maybe i'll give a link to the repository :)

file "main.bas"

Code: Select all

#INCLUDE ONCE "fbsound_dynamic.bi"
#INCLUDE "vbcompat.bi"
#INCLUDE "fbgfx.bi"


CONST AS SHORT scr_w = 800, scr_h = 600 ' screen constants
CONST file AS STRING = "cat_log.txt"

ENUM age
   kitten
   young
   adult
   old
END ENUM

TYPE cat
   PRIVATE:
   AS STRING cat_name
   PUBLIC:
   AS FB.Image PTR imge(1 TO 10)
   AS DOUBLE d1, d2
   AS STRING text1, text2, text3, text4, text5, text6, cat_age
   AS boolean isOut, isneglect
   AS INTEGER hunger, pet_count, nap_count
   DECLARE PROPERTY cat_name1() AS STRING
   DECLARE PROPERTY cat_name1(BYVAL cat_name AS STRING)
   DECLARE SUB time_diff()
   DECLARE SUB settings(i AS age)
   DECLARE SUB pet_cat(key AS STRING)
   DECLARE SUB CP(row AS INTEGER, s AS STRING)
   DECLARE SUB display_screen(index AS INTEGER)
   DECLARE SUB make_sound(f AS STRING, hWave AS INTEGER,t AS INTEGER)
   DECLARE SUB animation(f AS STRING, t AS INTEGER)
   DECLARE SUB cat_hunger(key AS STRING)
   DECLARE SUB nap_time(inx AS INTEGER)
   DECLARE SUB cat_napping()
   DECLARE SUB write_file(filename AS STRING)
   DECLARE SUB read_file(filename AS STRING)
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   
END TYPE

CONSTRUCTOR cat
this.isOut = FALSE
THIS.text1 = ""
this.text2 = ""
this.text3 = ""
this.text4 = ""
this.text5 = ""
'this.imge(1) = imagecreate(800,600)
'this.imge(2) = imagecreate(800,600)
'this.imge(3) = imagecreate(800,600)
'this.imge(4) = imagecreate(800,600)
'this.imge(5) = imagecreate(800,600)
'this.imge(6) = imagecreate(800,600)
'this.imge(7) = imagecreate(800,600)
'this.imge(8) = imagecreate(800,600)
'this.imge(9) = imagecreate(800,600)
'this.imge(10) = imagecreate(800,600)
for i as integer = 1 to 10
  this.imge(i) = ImageCreate(800,600)
next i
END CONSTRUCTOR

DESTRUCTOR cat
IMAGEDESTROY(imge(1))
IMAGEDESTROY(imge(2))
IMAGEDESTROY(imge(3))
IMAGEDESTROY(imge(4))
IMAGEDESTROY(imge(5))
IMAGEDESTROY(imge(6))
IMAGEDESTROY(imge(7))
IMAGEDESTROY(imge(8))
IMAGEDESTROY(imge(9))
IMAGEDESTROY(imge(10))
END DESTRUCTOR

PROPERTY cat.cat_name1() AS STRING
RETURN this.cat_name
END PROPERTY

PROPERTY cat.cat_name1(BYVAL cat_name AS STRING)
this.cat_name = cat_name
END PROPERTY

SUB cat.write_file(filename AS STRING)
   this.d1 = NOW()
   
   DIM f AS LONG = FREEFILE()
   OPEN filename FOR OUTPUT AS #f
   WRITE #f, cat_name1
   WRITE #f, this.hunger
   WRITE #f, THIS.pet_count
   WRITE #f, this.nap_count
   WRITE #f, this.isOut
   WRITE #f, this.cat_age
   write #f, this.d1
   CLOSE #f
END SUB

SUB cat.read_file(filename AS STRING)
   DIM h AS LONG = FREEFILE()
   DIM fline AS STRING
   OPEN filename FOR INPUT AS #h
   INPUT #h, fline
   cat_name1 = fline
   INPUT #h, this.hunger
   INPUT #h, THIS.pet_count
   INPUT #h, this.nap_count
   INPUT #h, this.isOut
   INPUT #h, this.cat_age
   INPUT #h, this.d1
   CLOSE #h
   
END SUB

sub cat.time_diff()
   this.d2 = NOW()
   IF DATEDIFF("d", this.d1, this.d2) > 7 THEN
      this.isneglect = TRUE
   ENDIF
END sub


SUB cat.nap_time(inx AS INTEGER)
   SELECT CASE inx
   CASE 0:
   CLS
   CP 4, "------------"
   CP 5, "          / "
   CP 6, "         /  "
   CP 7, "        /   "
   CP 8, "       /    "
   CP 9, "      /     "
   CP 10, "     /      "
   CP 11, "    /       "
   CP 12, "   /        "
   CP 13, "  /         "
   CP 13, " /          "
   CP 14, "------------"
   CP 35, text5
   CP 15, this.cat_age & " " & cat_name1
CASE 1:
CLS
CP 4, "%%%%%%%%%%%%"
CP 5, "          % "
CP 6, "         %  "
CP 7, "        %   "
CP 8, "       %    "
CP 9, "      %     "
CP 10, "     %      "
CP 11, "    %       "
CP 12, "   %        "
CP 13, "  %         "
CP 13, " %          "
CP 14, "%%%%%%%%%%%%"
CP 35, text5
CP 15, this.cat_age & " " & cat_name1
CASE 2:
CLS
CP 4, "zzzzzzzzzzzz"
CP 5, "          z "
CP 6, "         z  "
CP 7, "        z   "
CP 8, "       z    "
CP 9, "      z     "
CP 10, "     z      "
CP 11, "    z       "
CP 12, "   z        "
CP 13, "  z         "
CP 13, " z          "
CP 14, "zzzzzzzzzzzz"
CP 35, text5
CP 15, this.cat_age & " " & cat_name1
END SELECT
END SUB

SUB cat.settings(i AS age)
   SELECT CASE i
   CASE 0:
   this.hunger = INT(RND*101)
   this.pet_count = INT(RND*201)
   this.nap_count = INT(RND*601)
   this.cat_age = "kitten"
CASE 1:
this.hunger = INT(RND*201)
this.pet_count = INT(RND*301)
this.nap_count = INT(RND*601)
this.cat_age = "young cat"
CASE 2:
this.hunger = INT(RND*351)
this.pet_count = INT(RND*451)
this.nap_count = INT(RND*601)
this.cat_age = "adult cat"
CASE 3:
this.hunger = INT(RND*301)
this.pet_count = INT(RND*401)
this.nap_count = INT(RND*601)
this.cat_age = "old cat"   
END SELECT
END SUB




SUB cat.pet_cat(key AS STRING)
   
   THIS.pet_count -= 1
   
   IF THIS.pet_count <= 50 THEN
      this.text4 = "the cat need some petting press key 'p' to pet cat!"
      
   ELSE
      this.text4 = ""
      
      ENDIF
      IF key = CHR(112) THEN 
         THIS.pet_count += 1000
         this.text4 = ""
         ENDIF
         
      END SUB
      
SUB cat.CP(row AS INTEGER, s AS STRING)
   LOCATE row, (100 - LEN(s)) / 2 : PRINT s
   'DIM AS INTEGER tx, ty 
   'tx = (800 / 2) - (Len(s) / 2)
   'ty = row
   'Draw String (tx * 8, ty * 8), s, RGB(0,0,0)
END SUB
      
SUB cat.display_screen(index AS INTEGER)
'dim as any ptr catSheet
'catSheet = imagecreate(800,600)
'DO
BLOAD ("catsheet\Idle (" & index & ").bmp"), imge(index)  
'dim as integer frame      'current animation frame
SCREENLOCK
'cls
put (0,0),imge, TRANS
CP 15, this.cat_age & " " &cat_name1
CP 34, text1
CP 35, text2
CP 32, text4
CP 33, text3
CP 31, text6
SCREENUNLOCK
SLEEP 1
'frame = frame + 1
'loop       
'         SELECT CASE index
'         CASE 0:
'         CLS
'         CP 15, this.cat_age & " " &cat_name1
'         CP 4, "^                        ^"
'         CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
'         CP 6, "<| (( <|> ))  ||   ((  <|>  )) |>"
'         CP 7, "_                              _"
'         CP 8, "_                            _"
'         CP 9, "_    >(::| * |::)<     _"
'         CP 10, "        -------          "
'         CP 11, "(  -----  )"
'         CP 12, "\\---//"
'         CP 13, "%%%"
'         CP 34, text1
'         CP 35, text2
'         CP 32, text4
'         CP 33, text3
'         CP 31, text6
'      CASE 1:
'      CLS
'      CP 15, this.cat_age & " " &cat_name1
'      CP 4, "^                        ^"
'      CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
'      CP 6, "<| (( <I> ))  ||   ((  <I>  )) |>"
'      CP 7, "_                              _"
'      CP 8, "_                            _"
'      CP 9, "_    >(::| * |::)<     _"
'      CP 10, "                          "
'      CP 11, "(  OOOO  )"
'      CP 12, "\\   //"
'      CP 13, "%%%"
'      CP 34, text1
'      CP 35, text2
'      CP 32, text4
'      CP 33, text3
'      CP 31, text6
'   CASE 2:
'   CLS
'   CP 15, this.cat_age &" "& cat_name1
'   CP 4, "^                        ^"
'   CP 5, "( ) %%%%%%%%%%%%%%%%%%%  ( )"
'   CP 6, "<| (( <dOb> ))  ||   ((  <dOb>  )) |>"
'   CP 7, "_                              _"
'   CP 8, "_                            _"
'   CP 9, "_    >(::| & |::)<     _"
'   CP 10, "                          "
'   CP 11, "(  ~~~~~  )"
'   CP 12, "\\ ~~~ //"
'   CP 13, "%%%"
'   CP 34, text1
'   CP 35, text2
'   CP 32, text4
'   CP 33, text3
'   CP 31, text6
'END SELECT
END SUB

SUB cat.cat_napping()
   
   DIM x AS INTEGER = 0
   DIM xx AS INTEGER = 30
   
   DO
      nap_time(x)
      this.text5 = "NAP TIME!"
      x += 1
      xx -= 1
      SLEEP 250
      IF x >= 3 THEN x = 0
   LOOP UNTIL xx <= 0
   
END SUB
SUB cat.cat_hunger(key AS STRING)
   
   IF this.hunger < 25 THEN
      this.text1 = "cat is hungry! press key 'f' to feed it"
   ELSE
      this.text1 = ""

   ENDIF
   IF this.hunger <= -450 THEN
     isOut = TRUE
   
   ENDIF
   IF key = CHR(102) THEN
      this.hunger += 1000
   ENDIF
END SUB
         
         
         
SUB cat.make_sound(f AS STRING, hWave AS INTEGER, t AS INTEGER)
   
   fbs_Load_WAVFile(f , @hWave)
   fbs_Play_Wave(hWave , t)
   
END SUB
         
SUB CAT.ANIMATION(f AS STRING, t AS INTEGER)
         VAR key = "" , hwave = 0, age2 = 0
         DO
      WITH THIS
            IF isOut = TRUE OR NOT FILEEXISTS(file) OR isNeglect = TRUE THEN 
               DIM AS STRING catname, age1
               INPUT "enter cat name or enter 'quit' to exit: ", catname
               IF catname = "quit" THEN
                  write_file(file)
                  END
               ENDIF
               cat_name1 = catname
               INPUT "select age of cat - 0 for kitten, 1 for young, 2 for adult, 3 for old: ", age1
               age2 = VAL(age1)
               settings(age2)
            
            ELSE 
               read_file(file)
            ENDIF
               isOut = FALSE
               isNeglect = FALSE 
            DIM i AS INTEGER = 1
            make_sound(f,hWave, t)
                        
            
            DO
                  key = INKEY
               IF nap_count > 50 THEN
                  IF key = CHR(115) THEN
                     make_sound(f,hWave, t)
                  ENDIF
                  
                  IF i >= 11 THEN i = 1
                     DISPLAY_SCREEN(i)
                     SLEEP 100
                     i += 1
                     cat_hunger(key)
                     pet_cat(key)
                     time_diff()
                  IF isOut = TRUE OR isneglect = TRUE THEN EXIT DO
                     text2 = " cat hunger is: " & hunger & " cat napping counter is: " & nap_count & _
                     " cat pet time is: " & pet_count
                     nap_count -= 1
                     hunger -= 1
                  IF key = CHR(27) THEN
                     write_file(file)
                     END
                  ENDIF
               ELSEIF nap_count <= 50 THEN
                  cat_napping()
                  nap_count = INT(RND*3001)
               ENDIF  
                                 
            LOOP
               fbs_Destroy_Wave(@hWave)
         IF isOut = TRUE OR isNeglect = TRUE THEN
            CLS
               
            text2 = "IT'S BEEN " & DATEDIFF("d", this.d1, this.d2) & " MINUTES SINCE YOU LAST OPEN THE PROGRAM"
            text1 = "CAT DIED FROM NEGLECT!!!"
            text4 = "PRESS ANY KEY TO START OVER WITH A NEW CAT!"
            CP 31, text1
            CP 34, text4
            CP 30, text2
            SLEEP 
            cls
            write_file(file)
         ENDIF
      END WITH
   LOOP UNTIL INKEY() = CHR(27)
                           
END SUB


IF fbs_Init()=false THEN
PRINT "error: FBS_INIT() " & FBS_Get_PlugError()
BEEP : SLEEP : END 1
END IF

SCREENRES scr_w, scr_h, 32
WIDTH scr_w \ 8, scr_h \ 16
DIM SHARED fiori AS cat
fiori.animation("cat_sound.wav", 1)
ron77 :)
Post Reply