##Copyright (C) 2006 by Han Dao
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#You can contract the author at wikipediankiba@gmail.com
#PROJECT: Dynpet
#DESCRIPTION: Dynpet is a computer program similiar to the Tamagotchi.
#FUNCTION OF THIS PART: Contain the Pet object
#TODO: Build a new complete Pet class here
class Pet
include Rubygame::Sprites::Sprite
def initialize
super
@rect = Rubygame::Rect.new( 300 , 200 , 50 , 50 )
#The inital image that is displayed when the game started up.
@image = Rubygame::Image.load("data/pets/test1.png")
@file
@data
#@animate contain data for rendering animation
@anistring
@animate
@counter = cycle = 0
@sequence = []
end
def data_rip
@animate['file'].each do |file|
@sequence << file
end
end
def animate_change option
if option == 1
@string = 'idle'
else
@string = 'right'
end
@cycle = 0
end
def animate rate
#@counter and rate exist for the purpose of setting animation speed.
if @counter == rate
@counter = 0
@image = Rubygame::Image.load(@sequence[@animate[@string][@cycle]])
@cycle += 1
if @cycle == 6
@cycle = 0
end
end
@counter +=1
end
def load data , main
@data = data
@file = Game_File.new(main)
@animate = @file.yaml_read("data/pets/sprite.d_ani")
data_rip
@rect.centerx = @data['x']
@rect.centery = @data['y']
@rect.centerx %= 800
@rect.centery %= 600
end
def save
@file.yaml_write @data , @data['filename']
end
end