Commits

Richard Jones committed 234ec84

remove unnecessary refactoring of Sprite step; leave background as blit

Comments (0)

Files changed (13)

         if key[pygame.K_DOWN]:
             self.rect.y += 300 * dt
 
-class Background(pygame.sprite.Sprite):
-    def __init__(self, *groups):
-        super(Background, self).__init__(*groups)
-        self.image = pygame.image.load('background.png')
-        self.rect = pygame.rect.Rect((0, 0), self.image.get_size())
-
 class Game(object):
     def main(self, screen):
         clock = pygame.time.Clock()
 
-        sprites = pygame.sprite.OrderedUpdates()
-        background = Background()
-        sprites.add(background)
-        player = Player()
-        sprites.add(player)
+        background = pygame.image.load('background.png')
+        sprites = pygame.sprite.Group()
+        self.player = Player(sprites)
 
         while 1:
             dt = clock.tick(30)
                     return
 
             sprites.update(dt / 1000.)
+            screen.blit(background, (0, 0))
             sprites.draw(screen)
             pygame.display.flip()
 

10-refactoring.py

-import pygame
-
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
-        self.rect = pygame.rect.Rect(location, self.image.get_size())
-
-class Player(Sprite):
-    def update(self, dt):
-        key = pygame.key.get_pressed()
-        if key[pygame.K_LEFT]:
-            self.rect.x -= 300 * dt
-        if key[pygame.K_RIGHT]:
-            self.rect.x += 300 * dt
-        if key[pygame.K_UP]:
-            self.rect.y -= 300 * dt
-        if key[pygame.K_DOWN]:
-            self.rect.y += 300 * dt
-
-class Game(object):
-    def main(self, screen):
-        clock = pygame.time.Clock()
-
-        sprites = pygame.sprite.OrderedUpdates()
-        background = Sprite('background.png', (0, 0))
-        sprites.add(background)
-        player = Player('player.png', (320, 240))
-        sprites.add(player)
-
-        while 1:
-            dt = clock.tick(30)
-
-            for event in pygame.event.get():
-                if event.type == pygame.QUIT:
-                    return
-                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
-                    return
-
-            sprites.update(dt / 1000.)
-            sprites.draw(screen)
-            pygame.display.flip()
-
-if __name__ == '__main__':
-    pygame.init()
-    screen = pygame.display.set_mode((640, 480))
-    Game().main(screen)
-
 import pygame
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
-        self.rect = pygame.rect.Rect(location, self.image.get_size())
 
-class Player(Sprite):
+class Player(pygame.sprite.Sprite):
+    def __init__(self, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player.png')
+        self.rect = pygame.rect.Rect((320, 240), self.image.get_size())
+
     def update(self, dt, game):
         last = self.rect.copy()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
-        sprites = pygame.sprite.OrderedUpdates()
-        background = Sprite('background.png', (0, 0))
-        sprites.add(background)
-        player = Player('player.png', (320, 240))
-        sprites.add(player)
+        background = pygame.image.load('background.png')
+        sprites = pygame.sprite.Group()
+        self.player = Player(sprites)
+
         self.walls = pygame.sprite.Group()
+        block = pygame.image.load('block.png')
         for x in range(0, 640, 32):
             for y in range(0, 480, 32):
                 if x in (0, 640-32) or y in (0, 480-32):
-                    self.walls.add(Sprite('block.png', (x, y)))
+                    wall = pygame.sprite.Sprite(self.walls)
+                    wall.image = block
+                    wall.rect = pygame.rect.Rect((x, y), block.get_size())
         sprites.add(self.walls)
 
         while 1:
                     return
 
             sprites.update(dt / 1000., self)
+            screen.blit(background, (0, 0))
             sprites.draw(screen)
             pygame.display.flip()
 
 import pygame
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
-        self.rect = pygame.rect.Rect(location, self.image.get_size())
 
-class Player(Sprite):
+class Player(pygame.sprite.Sprite):
+    def __init__(self, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player.png')
+        self.rect = pygame.rect.Rect((320, 240), self.image.get_size())
+
     def update(self, dt, game):
         last = self.rect.copy()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
-        sprites = pygame.sprite.OrderedUpdates()
-        background = Sprite('background.png', (0, 0))
-        sprites.add(background)
-        player = Player('player.png', (320, 240))
-        sprites.add(player)
+        background = pygame.image.load('background.png')
+        sprites = pygame.sprite.Group()
+        self.player = Player(sprites)
+
         self.walls = pygame.sprite.Group()
+        block = pygame.image.load('block.png')
         for x in range(0, 640, 32):
             for y in range(0, 480, 32):
                 if x in (0, 640-32) or y in (0, 480-32):
-                    self.walls.add(Sprite('block.png', (x, y)))
+                    wall = pygame.sprite.Sprite(self.walls)
+                    wall.image = block
+                    wall.rect = pygame.rect.Rect((x, y), block.get_size())
         sprites.add(self.walls)
 
         while 1:
                     return
 
             sprites.update(dt / 1000., self)
+            screen.blit(background, (0, 0))
             sprites.draw(screen)
             pygame.display.flip()
 
 import pygame
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
-        self.rect = pygame.rect.Rect(location, self.image.get_size())
+class Player(pygame.sprite.Sprite):
+    def __init__(self, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player.png')
+        self.rect = pygame.rect.Rect((320, 240), self.image.get_size())
+        self.resting = False
+        self.dy = 0
 
-class Player(Sprite):
-    resting = False
-    dy = 0
     def update(self, dt, game):
         last = self.rect.copy()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
-        sprites = pygame.sprite.OrderedUpdates()
-        background = Sprite('background.png', (0, 0))
-        sprites.add(background)
-        player = Player('player.png', (320, 240))
-        sprites.add(player)
+        background = pygame.image.load('background.png')
+        sprites = pygame.sprite.Group()
+        self.player = Player(sprites)
+
         self.walls = pygame.sprite.Group()
+        block = pygame.image.load('block.png')
         for x in range(0, 640, 32):
             for y in range(0, 480, 32):
                 if x in (0, 640-32) or y in (0, 480-32):
-                    self.walls.add(Sprite('block.png', (x, y)))
+                    wall = pygame.sprite.Sprite(self.walls)
+                    wall.image = block
+                    wall.rect = pygame.rect.Rect((x, y), block.get_size())
         sprites.add(self.walls)
 
         while 1:
                     return
 
             sprites.update(dt / 1000., self)
+            screen.blit(background, (0, 0))
             sprites.draw(screen)
             pygame.display.flip()
 
 import pygame
 import tmx
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
+class Player(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player.png')
         self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.resting = False
+        self.dy = 0
 
-class Player(Sprite):
-    resting = False
-    dy = 0
     def update(self, dt, game):
         last = self.rect.copy()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
+        background = pygame.image.load('background.png')
+
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
         start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player('player.png', (start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
+        self.player = Player((start_cell.px, start_cell.py), self.sprites)
         self.tilemap.layers.append(self.sprites)
 
-        background = pygame.image.load('background.png')
-
         while 1:
             dt = clock.tick(30)
 
                     return
 
             self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             self.tilemap.draw(screen)
             pygame.display.flip()
 

15-blocker-sides.py

 import pygame
 import tmx
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
+class Player(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player.png')
         self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.resting = False
+        self.dy = 0
 
-class Player(Sprite):
-    resting = False
-    dy = 0
     def update(self, dt, game):
         last = self.rect.copy()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
+        background = pygame.image.load('background.png')
+
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
         start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player('player.png', (start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
+        self.player = Player((start_cell.px, start_cell.py), self.sprites)
         self.tilemap.layers.append(self.sprites)
 
-        background = pygame.image.load('background.png')
-
         while 1:
             dt = clock.tick(30)
 
                     return
 
             self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             self.tilemap.draw(screen)
             pygame.display.flip()
 
 import pygame
 import tmx
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
+class Enemy(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Enemy, self).__init__(*groups)
+        self.image = pygame.image.load('enemy.png')
         self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.direction = 1
 
-class Enemy(Sprite):
-    direction = 1
     def update(self, dt, game):
         self.rect.x += self.direction * 100 * dt
         for cell in game.tilemap.layers['triggers'].collide(self.rect, 'reverse'):
         if self.rect.colliderect(game.player.rect):
             game.player.is_dead = True
 
-class Player(Sprite):
-    resting = False
-    dy = 0
-    is_dead = False
+class Player(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player.png')
+        self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.resting = False
+        self.dy = 0
+        self.is_dead = False
+
     def update(self, dt, game):
         last = self.rect.copy()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
+        background = pygame.image.load('background.png')
+
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
         start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player('player.png', (start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
+        self.player = Player((start_cell.px, start_cell.py), self.sprites)
         self.tilemap.layers.append(self.sprites)
 
         self.enemies = tmx.SpriteLayer()
         for enemy in self.tilemap.layers['triggers'].find('enemy'):
-            self.enemies.add(Enemy('enemy.png', (enemy.px, enemy.py)))
+            Enemy((enemy.px, enemy.py), self.enemies)
         self.tilemap.layers.append(self.enemies)
 
-        background = pygame.image.load('background.png')
-
         while 1:
             dt = clock.tick(30)
 
                     return
 
             self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             self.tilemap.draw(screen)
             pygame.display.flip()
 

17-player-direction.py

 import pygame
 import tmx
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
+class Enemy(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Enemy, self).__init__(*groups)
+        self.image = pygame.image.load('enemy.png')
         self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.direction = 1
 
-class Enemy(Sprite):
-    direction = 1
     def update(self, dt, game):
         self.rect.x += self.direction * 100 * dt
         for cell in game.tilemap.layers['triggers'].collide(self.rect, 'reverse'):
         if self.rect.colliderect(game.player.rect):
             game.player.is_dead = True
 
-class Player(Sprite):
-    resting = False
-    dy = 0
-    is_dead = False
-    direction = 1
-
-    def __init__(self, location):
-        super(Player, self).__init__('player-right.png', location)
+class Player(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player-right.png')
         self.right_image = self.image
         self.left_image = pygame.image.load('player-left.png')
+        self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.resting = False
+        self.dy = 0
+        self.is_dead = False
+        self.direction = 1
 
     def update(self, dt, game):
         last = self.rect.copy()
     def main(self, screen):
         clock = pygame.time.Clock()
 
+        background = pygame.image.load('background.png')
+
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
         start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player((start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
+        self.player = Player((start_cell.px, start_cell.py), self.sprites)
         self.tilemap.layers.append(self.sprites)
 
         self.enemies = tmx.SpriteLayer()
         for enemy in self.tilemap.layers['triggers'].find('enemy'):
-            self.enemies.add(Enemy('enemy.png', (enemy.px, enemy.py)))
+            Enemy((enemy.px, enemy.py), self.enemies)
         self.tilemap.layers.append(self.enemies)
 
-        background = pygame.image.load('background.png')
-
         while 1:
             dt = clock.tick(30)
 
                     return
 
             self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             self.tilemap.draw(screen)
             pygame.display.flip()
 
 import pygame
 import tmx
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
+class Enemy(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Enemy, self).__init__(*groups)
+        self.image = pygame.image.load('enemy.png')
         self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.direction = 1
 
-class Enemy(Sprite):
-    direction = 1
     def update(self, dt, game):
         self.rect.x += self.direction * 100 * dt
         for cell in game.tilemap.layers['triggers'].collide(self.rect, 'reverse'):
 
 class Bullet(pygame.sprite.Sprite):
     image = pygame.image.load('bullet.png')
-    def __init__(self, location, direction):
-        super(Bullet, self).__init__()
+    def __init__(self, location, direction, *groups):
+        super(Bullet, self).__init__(*groups)
         self.rect = pygame.rect.Rect(location, self.image.get_size())
         self.direction = direction
         self.lifespan = 1
         if pygame.sprite.spritecollide(self, game.enemies, True):
             self.kill()
 
-class Player(Sprite):
-    resting = False
-    dy = 0
-    is_dead = False
-    gun_cooldown = 0
-    direction = 1
-
-    def __init__(self, location):
-        super(Player, self).__init__('player-right.png', location)
+class Player(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player-right.png')
         self.right_image = self.image
         self.left_image = pygame.image.load('player-left.png')
+        self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.resting = False
+        self.dy = 0
+        self.is_dead = False
+        self.direction = 1
+        self.gun_cooldown = 0
 
     def update(self, dt, game):
         last = self.rect.copy()
 
         if key[pygame.K_LSHIFT] and not self.gun_cooldown:
             if self.direction > 0:
-                game.sprites.add(Bullet(self.rect.midright, 1))
+                Bullet(self.rect.midright, 1, game.sprites)
             else:
-                game.sprites.add(Bullet(self.rect.midleft, -1))
+                Bullet(self.rect.midleft, -1, game.sprites)
             self.gun_cooldown = 1
 
         self.gun_cooldown = max(0, self.gun_cooldown - dt)
     def main(self, screen):
         clock = pygame.time.Clock()
 
+        background = pygame.image.load('background.png')
+
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
         start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player((start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
+        self.player = Player((start_cell.px, start_cell.py), self.sprites)
         self.tilemap.layers.append(self.sprites)
 
         self.enemies = tmx.SpriteLayer()
         for enemy in self.tilemap.layers['triggers'].find('enemy'):
-            self.enemies.add(Enemy('enemy.png', (enemy.px, enemy.py)))
+            Enemy((enemy.px, enemy.py), self.enemies)
         self.tilemap.layers.append(self.enemies)
 
-        background = pygame.image.load('background.png')
-
         while 1:
             dt = clock.tick(30)
 
                     return
 
             self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             self.tilemap.draw(screen)
             pygame.display.flip()
 
 import pygame
 import tmx
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
+class Enemy(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Enemy, self).__init__(*groups)
+        self.image = pygame.image.load('enemy.png')
         self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.direction = 1
 
-class Enemy(Sprite):
-    direction = 1
     def update(self, dt, game):
         self.rect.x += self.direction * 100 * dt
         for cell in game.tilemap.layers['triggers'].collide(self.rect, 'reverse'):
 
 class Bullet(pygame.sprite.Sprite):
     image = pygame.image.load('bullet.png')
-    def __init__(self, location, direction):
-        super(Bullet, self).__init__()
+    def __init__(self, location, direction, *groups):
+        super(Bullet, self).__init__(*groups)
         self.rect = pygame.rect.Rect(location, self.image.get_size())
         self.direction = direction
         self.lifespan = 1
             game.explosion.play()
             self.kill()
 
-class Player(Sprite):
-    resting = False
-    dy = 0
-    is_dead = False
-    gun_cooldown = 0
-    direction = 1
-
-    def __init__(self, location):
-        super(Player, self).__init__('player-right.png', location)
+class Player(pygame.sprite.Sprite):
+    def __init__(self, location, *groups):
+        super(Player, self).__init__(*groups)
+        self.image = pygame.image.load('player-right.png')
         self.right_image = self.image
         self.left_image = pygame.image.load('player-left.png')
+        self.rect = pygame.rect.Rect(location, self.image.get_size())
+        self.resting = False
+        self.dy = 0
+        self.is_dead = False
+        self.direction = 1
+        self.gun_cooldown = 0
 
     def update(self, dt, game):
         last = self.rect.copy()
 
         if key[pygame.K_LSHIFT] and not self.gun_cooldown:
             if self.direction > 0:
-                game.sprites.add(Bullet(self.rect.midright, 1))
+                Bullet(self.rect.midright, 1, game.sprites)
             else:
-                game.sprites.add(Bullet(self.rect.midleft, -1))
+                Bullet(self.rect.midleft, -1, game.sprites)
             self.gun_cooldown = 1
             game.shoot.play()
 
     def main(self, screen):
         clock = pygame.time.Clock()
 
+        background = pygame.image.load('background.png')
+
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
         start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player((start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
+        self.player = Player((start_cell.px, start_cell.py), self.sprites)
         self.tilemap.layers.append(self.sprites)
 
         self.enemies = tmx.SpriteLayer()
         for enemy in self.tilemap.layers['triggers'].find('enemy'):
-            self.enemies.add(Enemy('enemy.png', (enemy.px, enemy.py)))
+            Enemy((enemy.px, enemy.py), self.enemies)
         self.tilemap.layers.append(self.enemies)
 
-        background = pygame.image.load('background.png')
-
         self.jump = pygame.mixer.Sound('jump.wav')
         self.shoot = pygame.mixer.Sound('shoot.wav')
         self.explosion = pygame.mixer.Sound('explosion.wav')
                     return
 
             self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             self.tilemap.draw(screen)
             pygame.display.flip()
 
 import pygame
-import tmx
 import kezmenu
 
-class Sprite(pygame.sprite.Sprite):
-    def __init__(self, image, location):
-        super(Sprite, self).__init__()
-        self.image = pygame.image.load(image)
-        self.rect = pygame.rect.Rect(location, self.image.get_size())
-
-class Enemy(Sprite):
-    direction = 1
-    def update(self, dt, game):
-        self.rect.x += self.direction * 100 * dt
-        for cell in game.tilemap.layers['triggers'].collide(self.rect, 'reverse'):
-            if self.direction > 0:
-                self.rect.right = cell.left
-            else:
-                self.rect.left = cell.right
-            self.direction *= -1
-            break
-        if self.rect.colliderect(game.player.rect):
-            game.player.is_dead = True
-
-class Bullet(pygame.sprite.Sprite):
-    image = pygame.image.load('bullet.png')
-    def __init__(self, location, direction):
-        super(Bullet, self).__init__()
-        self.rect = pygame.rect.Rect(location, self.image.get_size())
-        self.direction = direction
-        self.lifespan = 1
-
-    def update(self, dt, game):
-        self.lifespan -= dt
-        if self.lifespan < 0:
-            self.kill()
-            return
-        self.rect.x += self.direction * 400 * dt
-
-        if pygame.sprite.spritecollide(self, game.enemies, True):
-            game.explosion.play()
-            self.kill()
-
-class Player(Sprite):
-    resting = False
-    dy = 0
-    is_dead = False
-    gun_cooldown = 0
-    direction = 1
-
-    def __init__(self, location):
-        super(Player, self).__init__('player-right.png', location)
-        self.right_image = self.image
-        self.left_image = pygame.image.load('player-left.png')
-
-    def update(self, dt, game):
-        last = self.rect.copy()
-
-        key = pygame.key.get_pressed()
-        if key[pygame.K_LEFT]:
-            self.rect.x -= 300 * dt
-            self.image = self.left_image
-            self.direction = -1
-        if key[pygame.K_RIGHT]:
-            self.rect.x += 300 * dt
-            self.image = self.right_image
-            self.direction = 1
-
-        if key[pygame.K_LSHIFT] and not self.gun_cooldown:
-            if self.direction > 0:
-                game.sprites.add(Bullet(self.rect.midright, 1))
-            else:
-                game.sprites.add(Bullet(self.rect.midleft, -1))
-            self.gun_cooldown = 1
-            game.shoot.play()
-
-        self.gun_cooldown = max(0, self.gun_cooldown - dt)
-
-        if self.resting and key[pygame.K_SPACE]:
-            game.jump.play()
-            self.dy = -500
-        self.dy = min(400, self.dy + 40)
-
-        self.rect.y += self.dy * dt
-
-        new = self.rect
-        self.resting = False
-        for cell in game.tilemap.layers['triggers'].collide(new, 'blockers'):
-            blockers = cell['blockers']
-            if 'l' in blockers and last.right <= cell.left and new.right > cell.left:
-                new.right = cell.left
-            if 'r' in blockers and last.left >= cell.right and new.left < cell.right:
-                new.left = cell.right
-            if 't' in blockers and last.bottom <= cell.top and new.bottom > cell.top:
-                self.resting = True
-                new.bottom = cell.top
-                self.dy = 0
-            if 'b' in blockers and last.top >= cell.bottom and new.top < cell.bottom:
-                new.top = cell.bottom
-                self.dy = 0
-
-        game.tilemap.set_focus(new.x, new.y)
-
-class Game(object):
-    def main(self, screen):
-        clock = pygame.time.Clock()
-
-        self.tilemap = tmx.load('map.tmx', screen.get_size())
-
-        self.sprites = tmx.SpriteLayer()
-        start_cell = self.tilemap.layers['triggers'].find('player')[0]
-        self.player = Player((start_cell.px, start_cell.py))
-        self.sprites.add(self.player)
-        self.tilemap.layers.append(self.sprites)
-
-        self.enemies = tmx.SpriteLayer()
-        for enemy in self.tilemap.layers['triggers'].find('enemy'):
-            self.enemies.add(Enemy('enemy.png', (enemy.px, enemy.py)))
-        self.tilemap.layers.append(self.enemies)
-
-        background = pygame.image.load('background.png')
-
-        self.jump = pygame.mixer.Sound('jump.wav')
-        self.shoot = pygame.mixer.Sound('shoot.wav')
-        self.explosion = pygame.mixer.Sound('explosion.wav')
-
-        while 1:
-            dt = clock.tick(30)
-
-            for event in pygame.event.get():
-                if event.type == pygame.QUIT:
-                    return
-                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
-                    return
-
-            self.tilemap.update(dt / 1000., self)
-            screen.blit(background, (0,0))
-            self.tilemap.draw(screen)
-            pygame.display.flip()
-
-            if self.player.is_dead:
-                print 'YOU DIED'
-                return
+# hack to allow us to import a module with an illegal name
+game = __import__('19-sound')
+Game = game.Game
 
 class Menu(object):
     running = True
 
         while self.running:
             menu.update(pygame.event.get(), clock.tick(30)/1000.)
-            screen.blit(background, (0,0))
+            screen.blit(background, (0, 0))
             menu.draw(screen)
             pygame.display.flip()
 
     def __contains__(self, key):
         if key in self._deleted:
             return False
-        return key in self._added_properties or key in self.tile.properties)
+        return key in self._added_properties or key in self.tile.properties
     def __getitem__(self, key):
         if key in self._deleted:
             raise KeyError(key)