- Código: Seleccionar todo
- #!/usr/bin/env python
 import pygame
 from pygame.locals import *
 from sys import exit
 from pygame.sprite import Sprite
 class Nave(Sprite):
 
 def __init__(self):
 Sprite.__init__(self)
 self.image = pygame.image.load("nave.png")
 self.dx = 320
 self.dy = 240
 
 def update(self):
 self.update_input()
 
 def update_input(self):
 teclas = pygame.key.get_pressed()
 
 if teclas[K_UP]:
 self.dy-=1
 
 if teclas[K_DOWN]:
 self.dy+=1
 
 if teclas[K_LEFT]:
 self.dx-=1
 
 if teclas[K_RIGHT]:
 self.dx+=1
 
 class Nivel(Sprite):
 
 def __init__(self):
 self.isla = 1
 self.agua = 0
 
 def getLayout(self):
 return [[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 ,9, 9, 9, 9, 9, 9, 9, 9, 9, 9],\
 [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 ,9, 9, 9, 9, 9, 9, 9, 9, 9, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 1, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ,0, 1, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 1, 0, 1, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],\
 [9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9]]
 
 def getSprites(self):
 isla, rect = pygame.image.load("isla.png")
 agua, rect = pygame.image.load("oceano.png", -0)
 return [isla,agua]
 
 pygame.init()
 screen = pygame.display.set_mode((640,480),0,32)
 pygame.display.set_caption("Shooter")
 nave = Nave()
 nivel = Nivel()
 while True:
 for event in pygame.event.get():
 if event.type == QUIT:
 exit()
 
 screen.fill((0,0,0))
 screen.blit(nave.image,(nave.dx,nave.dy))
 nave.update()
 nivel.update()
 pygame.display.update()
Gracias




