Virtual pet specification – details

virtual pet graphic

My first design for a virtual pet

If I’m to build a virtual pet game, I need to be very clear exactly what I’m expecting it to do.  Then I can start looking out for the code structures I need to implement.

I’m aiming for two products.  The simpler one will have a pet that the player can interact with, to feed and keep healthy.  The more complicated one will have a pet that can interact independently with its surroundings, and the player will need to make sure there is food available, for example, but the pet itself will decide when it wants to eat.

So for the simple version:

The pet will be awake three-quarters of the time and sleep the rest of the time.  It will have hunger, happiness and health, which will vary from 0 to 100.  All these will change over time, less so while asleep.  Hunger will be controlled by feeding it, health by giving it medicine and playing with it, and happiness by playing with it.  Waking it up when it is asleep will reduce happiness, but may be necessary if it is ill or starving, for example.

There will also be some interaction between the attributes: being too hungry will decrease happiness and health.  Hopefully I can encode this with maths, rather than needing extra if statements (making the change in happiness directly relative to the hunger and health values in some way).

There will be three buttons: feed, play and medicine.  Clicking these buttons will interact with the pet, changing the graphic and changing the appropriate value(s).

What I haven’t got for any of this is any incentive to keep the pet alive, no way to keep any kind of score.  I’m simply relying on the player wanting to keep the pet alive.  What I could do is add some sort of ageing system, whereby the maturity of the pet can be recorded.  Then the player can be trying to beat their own record of how long one pet has been kept alive.  That will go in the extended version, I think!

Code-wise: I will need a way to display graphics, plus buttons.  I need to respond to the pressing of the buttons by changing the graphics and the variables.  The variables will also change according to a timer that goes off regularly. There will be an element of randomness in the variable changes, particularly for illness, although hunger will be fairly steady.  A way of making it more complex would be to have variables changing at different rates according to activities, for example getting hungry quickly if playing and slowly if sleeping. I foresee lots of looping and lots of if statements in the code.

So I need to look for a way to display the elements, a way to run a timer to change the variables, a way to respond to button presses and code to loop and fork according to input from the buttons.

I know how to do this already in Scratch/BYOB.  It should be fairly straightforward to do it in App Inventor.  I have high hopes for Greenfoot.  Python seems a lot tougher, but there is a listing in the book I’m using that creates just such a virtual pet, that I should be able to adapt.  Processing is supposed to be good for graphic work – I’m hoping it’s a lot simpler than Flash, which would be another option for a project that involves lots of animation.  There are one or two further possibilities that I haven’t investigated yet!

One idea for Python (and possibly for any of the written languages) is to separate display from engine, as I did when I was first learning programming, so building an engine that will do the main processing, and a separate class that  controls the display, enabling the display/input to be updated later.  This means I will need to know how to create more than one class for a project, but will make it easier to update. I have access to the easygui library for Python which will display a series of buttons to click, so a rudimentary interface should be straightforward.

What I need to do now is write the algorithm for the pet’s behaviour, and then translate it into the different languages.

Once I’ve got working versions of the simple pet game, I can start on a more complicated version with the pet acting more independently.  This will require far more graphics and an element of artificial intelligence, which should be fun to play with and lead to the possibility of building up complexity gradually, for example by the player buying objects to add to the house.  Guess I’d better get going on the simple versions!



About emmyleigh
Writer/editor/proofreader who loves technology

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: