action cat animation

Game development specific discussions.
BasicCoder2
Posts: 3738
Joined: Jan 01, 2009 7:03
Location: Australia

action cat animation

Postby BasicCoder2 » Feb 05, 2021 8:23

I was writing my own version of a virtual pet but gave up on it. However I thought I might as well post the code that would display the virtual pets current action.

If you want to run the code below the attached image has to be loaded into a paint program and saved as a .bmp file.

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls

dim shared as string actions(0 to 5)
actions(0)="SITTING"
actions(1)="EATING"
actions(2)="MEOWING"
actions(3)="SLEEPING"
actions(4)="PURRING"
actions(5)="PLAYING"

dim shared as any ptr actionCat
actionCat = imagecreate(983,328)
bload "actionCat.bmp",actionCat

dim shared as integer frame
dim shared as integer action
dim shared as integer counter   'count cycles to display same action

dim as double st
st = timer

action = int(rnd(1)*6)

sub display()
    screenlock
    cls
    put (320-82,240-82),actionCat,(action*164,frame*164)-(action*164+163,frame*164+163),trans
    locate 20,20
    print actions(action)
    screenunlock
end sub

sub update()
       frame = frame + 1
       if frame = 2 then frame = 0
       
       counter = counter + 1
       if counter = 5 then
           counter = 0
           action = int(Rnd(1)*6)  'choose one of six actions
       end if
       
end sub

do
    if (timer-st)> 0.5 then
        st = timer  'reset start
        display()
        update()
    end if
    sleep 2
loop until multikey(&H01)


Image
Dr_D
Posts: 2430
Joined: May 27, 2005 4:59
Contact:

Re: action cat animation

Postby Dr_D » Feb 06, 2021 1:10

I've thought about making a virtual pet before. I still might do it someday. Why did you give up on it, just lost interest?
BasicCoder2
Posts: 3738
Joined: Jan 01, 2009 7:03
Location: Australia

Re: action cat animation

Postby BasicCoder2 » Feb 06, 2021 8:46

I never had any interest in a virtual pet program as such. ron77 was using it as an example in OOP and as someone who never uses OOP techniques I was curious to give it a go. I might still post my effort if it reaches a stage I think is worth posting for critical comment.

Return to “Game Dev”

Who is online

Users browsing this forum: No registered users and 2 guests