diff options
author | flavio <fdanesse@gmail.com> | 2011-12-07 23:10:50 (GMT) |
---|---|---|
committer | flavio <fdanesse@gmail.com> | 2011-12-07 23:10:50 (GMT) |
commit | 9d57ae40095b2928672b2f4b23a87b8d5927753e (patch) | |
tree | f36922e4cb1db2642d954a9fe71493fcdc55df23 /Ficha_Bicho.py |
CucaraSims Base
Diffstat (limited to 'Ficha_Bicho.py')
-rw-r--r-- | Ficha_Bicho.py | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/Ficha_Bicho.py b/Ficha_Bicho.py new file mode 100644 index 0000000..19c0346 --- /dev/null +++ b/Ficha_Bicho.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Ficha_Bicho.py por: +# Flavio Danesse <fdanesse@gmail.com> +# CeibalJAM! - Uruguay + +# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import pygame, gc +from pygame.locals import * + +gc.enable() + +import BiblioJAM +from BiblioJAM.JAMLabel import JAMLabel +import BiblioJAM.JAMGlobals as JAMG + +import Globals as VG +MAGENTA= (255, 0, 255) + +class Ficha_Bicho(pygame.sprite.OrderedUpdates): + def __init__(self): + pygame.sprite.OrderedUpdates.__init__(self) + self.bicho= None + x, y, self.separador= (10, 70, 13) + + self.label_tiempo= JAMLabel("Años: 0 Dias: 0 Horas: 0") + self.label_tiempo.set_text(tamanio= 30) + self.label_tiempo.set_posicion( (x,y) ) + self.add(self.label_tiempo) + + y += self.label_tiempo.get_tamanio()[1] + self.separador + self.label_hambre= JAMLabel("Nivel de Apetito: ") + self.label_hambre.set_text(tamanio= 25) + self.label_hambre.set_posicion( (x,y) ) + self.add(self.label_hambre) + + y += self.label_hambre.get_tamanio()[1] + self.separador + self.label_sed= JAMLabel("Nivel de Sed: ") + self.label_sed.set_text(tamanio= 25) + self.label_sed.set_posicion( (x,y) ) + self.add(self.label_sed) + + self.barra_nutricion= Barra() + self.barra_nutricion.rect.x= self.label_tiempo.get_posicion()[0] + 170 + self.barra_nutricion.rect.centery= self.label_hambre.get_posicion()[1]+ (self.label_hambre.get_tamanio()[1]/2) + self.add(self.barra_nutricion) + + self.barra_hidratacion= Barra() + self.barra_hidratacion.rect.x= self.label_tiempo.get_posicion()[0] + 170 + self.barra_hidratacion.rect.centery= self.label_sed.get_posicion()[1]+ (self.label_sed.get_tamanio()[1]/2) + self.add(self.barra_hidratacion) + + self.circulo= Circulo( (60,60) ) + self.add(self.circulo) + + def set_bicho(self, bicho): + tamanio= (bicho.rect.w, bicho.rect.h) + self.circulo.image= pygame.transform.scale(self.circulo.imagen_original, (tamanio)) + self.bicho= bicho + + def update(self): + if self.bicho: + self.actualizar_datos() + + def actualizar_datos(self): + edad = "Dias: %s Horas: %s" % (self.bicho.dias, self.bicho.horas) + if edad != self.label_tiempo.get_text(): + self.label_tiempo.set_text(texto= edad) + + nutricion = "Nutrición: %s" % (self.bicho.hambre) + if nutricion != self.label_hambre.get_text(): + self.label_hambre.set_text(texto= nutricion) + self.barra_nutricion.set_valor(self.bicho.hambre) + + hidratacion = "Hidratación: %s" % (self.bicho.sed) + if hidratacion != self.label_sed.get_text(): + self.label_sed.set_text(texto= hidratacion) + self.barra_hidratacion.set_valor(self.bicho.sed) + + self.circulo.rect.center= self.bicho.rect.center + +class Barra(pygame.sprite.Sprite): +# Barra de Progreso + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.imagen_original= self.get_barra() + self.image= self.imagen_original.copy() + self.rect= self.image.get_rect() + self.ultimo_valor= 0 + + def set_valor(self, valor): + # actualiza el progreso en la barra + if valor == self.ultimo_valor: return + if valor >= 0 and valor <= 100: + verde = (0,255,0,1) + amarillo = (255,255,0,1) + rojo = (255,0,0,1) + if valor <= 33: + color = rojo + if valor > 33 and valor <= 66: + color = amarillo + if valor > 66: + color = verde + + rectangulo = (0,0,valor,10) + self.image = self.imagen_original.copy() + pygame.draw.rect(self.image, color, rectangulo, 0) + elif valor > 100: + verde = (0,255,0,1) + rectangulo = (0,0,100,10) + self.image = self.imagen_original.copy() + pygame.draw.rect(self.image, verde, rectangulo, 0) + else: + self.image = self.imagen_original.copy() + self.ultimo_valor = valor + + def get_barra(self): + superficie= JAMG.get_Rectangulo_Transparente( (100, 10) ) + superficie= JAMG.get_my_surface_whit_border(superficie, (255,255,0,255), 2) + return superficie + +class Circulo(pygame.sprite.Sprite): + def __init__(self, tamanio): + pygame.sprite.Sprite.__init__(self) + self.imagen_original = self.get_surface(tamanio) + self.image = self.imagen_original.copy() + self.rect = self.image.get_rect() + + def get_surface(self, tamanio_panel): + superficie= JAMG.get_Rectangulo_Transparente( tamanio_panel ) + superficie= JAMG.get_my_surface_whit_border(superficie, (255,255,0,255), 5) + return superficie + |