diff options
Diffstat (limited to 'Nave.py')
-rwxr-xr-x | Nave.py | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -7,7 +7,7 @@ import random import pygame from pygame.locals import * - +''' DIRECTORIOBASE = os.path.dirname(__file__) IMAGEN_NAVE = os.path.join(DIRECTORIOBASE, @@ -17,22 +17,23 @@ IMAGEN_NAVE_ENEMIGA = os.path.join(DIRECTORIOBASE, 'Imagenes', 'Naves', 'enemy02.png') IMAGEN_BALA = os.path.join(DIRECTORIOBASE, - 'Imagenes', 'Bala.png') - + 'Imagenes', 'Bala.png')''' + class Nave(pygame.sprite.Sprite): """Nave.""" - def __init__(self): + def __init__(self, imagen, jugador): pygame.sprite.Sprite.__init__(self) - self.image = pygame.image.load(IMAGEN_NAVE) + self.jugador = jugador + self.image = pygame.image.load(imagen) self.rect = self.image.get_rect() - w = pygame.display.Info().current_w - h = pygame.display.Info().current_h + self.w = pygame.display.Info().current_w + self.h = pygame.display.Info().current_h - self.rect.center = (w/2, h/2) + self.rect.center = (self.w/2, self.h/2) def update(self): """Actualiza la nave, segĂșn eventos del teclado.""" @@ -40,16 +41,20 @@ class Nave(pygame.sprite.Sprite): tecla = pygame.key.get_pressed() if tecla[pygame.K_UP]: - self.rect.y -= 5 + if self.rect.y - 5 > 0: + self.rect.y -= 5 if tecla[pygame.K_DOWN]: - self.rect.y += 5 + if self.rect.y + self.rect.h + 5 < self.h: + self.rect.y += 5 if tecla[pygame.K_RIGHT]: - self.rect.x += 5 + if self.rect.x + self.rect.w + 5 < self.w: + self.rect.x += 5 if tecla[pygame.K_LEFT]: - self.rect.x -= 5 + if self.rect.x - 5 > 0: + self.rect.x -= 5 if tecla[pygame.K_SPACE]: print "Disparar" |