예제 #1
0
파일: states.py 프로젝트: sabren/blaze
 def __init__(self, screen, lvl=None):
     State.__init__(self, screen)
     pygame.mixer.music.stop()
     self.jkbx = jukebox.Jukebox()
     self.jkbx.stop_song()
     self.jkbx.load_song('sisters')
     self.jkbx.set_song_volume(0.2)
     self.jkbx.play_song('sisters', 10)
     pygame.mouse.set_visible(False)
     self.cursor = pygame.image.load(os.path.join('data', 'crosshair.bmp'))
     self.cursor.set_colorkey((0,0,0))
     if lvl != None:
         lvl = level.load(lvl)
     else:
         lvl = lvl.new(5,5)
     self.background = pygame.Surface((len(lvl['tiles'])*20,
                                       len(lvl['tiles'][0])*20))
     self.game_window = pygame.Surface((800,600))
     self.tiles = sprites.Group()
     y = 0
     for row in lvl['tiles']:
         x = 0
         for t in row:
             t.rect = pygame.Rect((x,y),(20,20))
             t.add(self.tiles)
             x += 20
         y += 20
     self.tiles.draw(self.background)
     self.level = self.background.copy()
     self.sprites = sprites.Group()
     self.hero = sprites.hero(lvl['hero'], self.sprites)
     self.hero.rect = pygame.Rect(lvl['hero'], self.hero.rect.size)
     self.enemies = pygame.sprite.Group()
     for enemy in lvl['enemies']:
         pos = enemy.pos
         enemy = sprites.Howitzer([self.sprites, self.enemies])
         enemy.rect.center = pos
         enemy.target = self.hero
     self.display = scrolling.scrolling_display(self.level,
                                                self.game_window, (0,0))
     self.FX = effects.Effects(self.screen, self.jkbx, self.background)
     self.tile_rects = [t.rect for t in self.tiles]
     self.HUD = HUD()
     self.paused = False
     self.won = False
     self.lost = False
     self.lose_delay = -1
     self.win_delay = -1
     self.old_time = pygame.time.get_ticks()
예제 #2
0
파일: states.py 프로젝트: sabren/blaze
    def __init__(self, screen, lvl, lvl_name):
        Menu.__init__(self, screen, ['Hero', 'Tiles', 'Enemies'], '')

        #The reload()s are here because the tiles and sprites kept dissappearing
        #in the toolbar when the editor was visited twice.
        reload(sprites)
        reload(level)

        self.lvl = lvl
        self.lvl_name = lvl_name
        self.background = pygame.Surface((len(lvl['tiles'])*20,
                                          len(lvl['tiles'][0])*20))

        #tiles
        self.tiles = sprites.Group()
        y = 0
        for row in lvl['tiles']:
            x = 0
            for tile in row:
                tile = level.tile(tile.image)
                tile.rect.center = (x,y)
                self.tiles.add(tile)
                x += 20
            y += 20
        self.tiles.draw(self.background)
        self.edit_window = pygame.Surface((650, 600))
        self.display = scrolling.scrolling_display(
            self.background, self.edit_window, (
                (self.background.get_width()/2)-(self.edit_window.get_width()/2),
                (self.background.get_height()/2)-(self.edit_window.get_height()/2)))

        #toolbar
        self.toolbar_background = pygame.image.load(
            os.path.join('data', 'flag2.bmp'))
        self.toolbar = pygame.Surface((150, 10000))
        self.toolbar.blit(self.toolbar_background, (0,0))
        self.toolbar.blit(self.toolbar_background, (0,600))
        self.toolbar.blit(self.toolbar_background, (0,1200))
        self.toolbar_items = sprites.Group()
        self.font = pygame.font.SysFont('Verdana', 30)
        self.font.set_underline(True)
        self.labels = [self.font.render(option, True, (0,0,0))
                       for option in self.options]
        self.font.set_underline(False)
        self.toolbar.blit(
            self.labels[0],
            ((self.toolbar.get_width()/2)-(self.labels[0].get_width()/2),
             50))
        if self.lvl_name == '__NEW__':
            self.hero = sprites.hero((-1000,0))
            self.hero.rect.center = (-1000,0)
        else:
            self.hero = sprites.hero(lvl['hero'])
            self.hero.rect.center = lvl['hero']
        self.h = sprites.Sprite(
            self.hero.image, [self.toolbar_items],
            ((self.toolbar.get_width()/2)-(self.hero.image.get_width()/2),
             self.labels[0].get_rect().bottom+55))
        self.hero.release()
        self.h.release()
        self.toolbar.blit(
            self.labels[1],
            ((self.toolbar.get_width()/2)-(self.labels[1].get_width()/2),
             self.h.rect.bottom+5))
        x = 0
        y = self.h.rect.bottom+self.labels[1].get_height()+10
        for tile in level.tiles:
            tile.rect = tile.rect.move((x,y))
            self.toolbar_items.add(tile)
            if tile.rect.right > 150:
                x = 0
                y += 22
            else:
                x += 22
        for sprite in self.toolbar_items.sprites():
            if sprite.rect.bottom > y: y = sprite.rect.bottom+5
        self.toolbar.blit(
            self.labels[2],
            ((self.toolbar.get_width()/2)-(self.labels[2].get_width()/2),
             y))
        x = 22
        y += 50
        for enemy in sprites.enemies:
            enemy.rect = enemy.rect.move((x,y))
            self.toolbar_items.add(enemy)
            if x == 22:
                x += 55
            else:
                x = 22
                y += 55
        self.toolbar_items.draw(self.toolbar)
        self.toolbar_pos = (0,0)

        self.sprites = sprites.Group(lvl['enemies']+[self.hero])
        self.scrolling = (0,0)
        self.selected = None
        self.mouse_down = False
        self.draw()
        self.toolbar_scrolling = 0