Ejemplo n.º 1
0
class Game(Application):
    title = "Shoot Em'"
    screen_size = 800, 600
    moving = False
    
    def __init__(self):
        Application.__init__(self)
        
        self.player = Player(self.screen,300,550)
        self.enemy = Enemy(self.screen,300,150,20,20,(255,0,0))
        self.bounds = self.screen.get_rect()
        self.enemyGroup = EnemyGroup()
        self.xplos = ExplosionGroup()
        Explosion.group = self.xplos
        self.direction = None
    
        self.spawners = [EnemySpawner(self.screen, 1000, self.enemyGroup, self.bounds)]
        
            
    def handle_event(self, event):
        if event.type == KEYDOWN and event.key == K_LEFT:
            self.moving = True
            self.direction = "l"
        elif event.type == KEYUP and event.key == K_LEFT:
            self.moving = False
        elif event.type == KEYDOWN and event.key == K_RIGHT:
            self.moving = True
            self.direction = "r"
        elif event.type == KEYUP and event.key == K_RIGHT:
            self.moving = False

    
    def update(self):
        dt = min(200, self.clock.get_time())
        self.enemy.update(dt)
        if self.moving:
            self.player.update(self.direction)
        for spawner in self.spawners:
            spawner.update(dt)
    
    def draw(self, screen):
        screen.fill((0,0,0))
        self.player.draw_image(screen)
        self.enemy.draw_image(screen)
Ejemplo n.º 2
0
 def __init__(self):
     Application.__init__(self)
     
     self.player = Player(self.screen,300,550)
     self.enemy = Enemy(self.screen,300,150,20,20,(255,0,0))
     self.bounds = self.screen.get_rect()
     self.enemyGroup = EnemyGroup()
     self.xplos = ExplosionGroup()
     Explosion.group = self.xplos
     self.direction = None
 
     self.spawners = [EnemySpawner(self.screen, 1000, self.enemyGroup, self.bounds)]