Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Ficha_Bicho.py
blob: de6eb68c93963d8e52ce735de574da15954b19cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/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
import 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