From 044cd047007c17c9efcd71d3c169df414014abbb Mon Sep 17 00:00:00 2001 From: Alan Aguiar Date: Tue, 30 Apr 2013 07:59:09 +0000 Subject: add basic globe --- diff --git a/src/api/Anim.py b/src/api/Anim.py index db3bea8..db3bea8 100644..100755 --- a/src/api/Anim.py +++ b/src/api/Anim.py diff --git a/src/api/GameState.py b/src/api/GameState.py index 42c09c7..42c09c7 100644..100755 --- a/src/api/GameState.py +++ b/src/api/GameState.py diff --git a/src/api/Globe.py b/src/api/Globe.py new file mode 100644 index 0000000..6f8effa --- /dev/null +++ b/src/api/Globe.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- + +import pygame +import Image +from api.Sprite import CSprite + +path = 'assets/images/dialog/' + + +class Globe(CSprite): + """ a basic label + properties: + font: font to use + text: text to display + fgColor: foreground color + bgColor: background color + center: position of label's center + size: (width, height) of label + """ + + def __init__(self, size, fontName = "freesansbold.ttf"): + CSprite.__init__(self) + #self.font = pygame.font.Font(fontName, 20) + h = size[0] + v = size[1] + #up_left = Image.loadImage(path + 'esquina-up-left.png', False) + up_left = pygame.image.load(path + 'esquina-up-left.png') + up_right = Image.loadImage(path + 'esquina-up-right.png', True) + down_left = Image.loadImage(path + 'esquina-down-left.png') + down_right = Image.loadImage(path + 'esquina-down-right.png', False) + up = Image.loadImage(path + 'borde-sin-sombra.png') + down = Image.loadImage(path + 'borde-con-sombra.png') + center = Image.loadImage(path + 'fondo.png') + + + horizontal = (h - 68) / 34 + vertical = (v - 68) / 34 + horizontal = horizontal + 2 + vertical = vertical + 2 + h = horizontal * 34 + v = vertical * 34 + + self.image = pygame.Surface((h, v)) + self.image.fill((255,255,255)) + + for i in range(horizontal): + for j in range(vertical): + x = i * 34 + y = j * 34 + if (i == 0) and (j == 0): + self.image.blit(up_left, (x, y)) + elif (i == 0) and (j==(vertical - 1)): + self.image.blit(down_left, (x, y)) + elif (i == (horizontal - 1)) and (j == 0): + self.image.blit(up_right, (x, y)) + elif (i == (horizontal - 1)) and (j == (vertical - 1)): + self.image.blit(down_right, (x, y)) + else: + self.image.blit(center, (x, y)) + + #self.image = pygame.Surface((34, 34)) + #self.image.blit(down_right, (0, 0)) + self.image.set_colorkey((255,255,255)) + #self.image = self.image.convert_alpha((255, 255, 255)) + #self.text = "" + """self.fgColor = ((0x00, 0x00, 0x00)) + self.bgColor = ((0xFF, 0xFF, 0xFF))""" + self.center = (200, 200) + self.size = (34, 34) + + def set_center(self, aCenter): + self.center = aCenter + + def set_size(self, aSize): + self.size = aSize + self._update_image() + + def set_fgColor(self, afgColor): + self.fgColor = afgColor + self._update_image() + + def set_bgColor(self, abgColor): + self.bgColor = abgColor + self._update_image() + + def set_text(self, aText): + self.text = aText + self._update_image() + + def _update_image(self): + self.image = pygame.Surface(self.size) + self.image.fill(self.bgColor) + fontSurface = self.font.render(self.text, True, self.fgColor, self.bgColor) + #center the text + xPos = (self.image.get_width() - fontSurface.get_width())/2 + self.image.blit(fontSurface, (xPos, 0)) + + def update(self): + self.rect = self.image.get_rect() + self.rect.center = self.center + \ No newline at end of file diff --git a/src/api/Points.py b/src/api/Points.py index 2424709..2424709 100644..100755 --- a/src/api/Points.py +++ b/src/api/Points.py diff --git a/src/api/Sprite.py b/src/api/Sprite.py index 6cfa895..6cfa895 100644..100755 --- a/src/api/Sprite.py +++ b/src/api/Sprite.py diff --git a/src/game/CreditsState.py b/src/game/CreditsState.py index e4b79f5..3cf7a79 100644 --- a/src/game/CreditsState.py +++ b/src/game/CreditsState.py @@ -11,6 +11,7 @@ from api.Game import CGame import api.Button from api.Button import CButton import api.Image as CImage +from api.Globe import Globe import pygame @@ -38,6 +39,19 @@ class CCreditsState(CGameState): self.mBackground = CImage.loadImage('assets/images/back_credits.png', False) CGame().setBackground(self.mBackground) + self.mGlobe = Globe((200, 200)) + CGame().addChild(self.mGlobe) + + """self.mPiece1 = Globe((200, 200)) + #self.mPiece1.loadImage('assets/images/a1g1/piece1.png', False) + #self.mPiece1.loadImage('assets/images/dialog/esquina-up-left.png', False) + self.mPiece1.loadImage('assets/images/dialog/esquina-down-right.png', False) + size = self.mPiece1.getSize() + self.mPiece1.setRegistrationPointOffset(size[0] / 2 , size[1] / 2) + + CGame().addChild(self.mPiece1)""" + + def update(self): #print "menu update" CGameState.update(self) -- cgit v0.9.1