예제 #1
0
파일: scene.py 프로젝트: jpmit/ggj14
    def __init__(self, name, game):
        self.next = self
        
        # this is the name of the level, which is '1', '2', etc.
        self.name = name
        
        self.game = game
        # get background info for this scene (not currently used)

        # get level data for this scene
        self.level = Level(name, self.game)

        self.player = self.level.player
        self.lsize = self.level.get_size()

#        print "level size:", lsize
        self.camera = Camera(self.player.rect, self.lsize[0], self.lsize[1])

        # my name is the name displayed at the top of the screen
        self.myname = name + ':' + LEVEL_NAMES[name]
        self.namefont = pygame.font.Font('fonts/ShareTechMono-Regular.ttf' , 20)
        self.nametxt = self.namefont.render(self.myname, True, 
                                            WHITE)
        
        # play music if not already going
        self.game.jukebox.play_music_if('game')

        # get special stuff, e.g. tutorial (this should be a list, and
        # empty if there is no special stuff).
        self.special_stuff = special.get_special_stuff(self, self.game)
예제 #2
0
파일: scene.py 프로젝트: jpmit/ggj14
class PlayScene(Scene):
    def __init__(self, name, game):
        self.next = self
        
        # this is the name of the level, which is '1', '2', etc.
        self.name = name
        
        self.game = game
        # get background info for this scene (not currently used)

        # get level data for this scene
        self.level = Level(name, self.game)

        self.player = self.level.player
        self.lsize = self.level.get_size()

#        print "level size:", lsize
        self.camera = Camera(self.player.rect, self.lsize[0], self.lsize[1])

        # my name is the name displayed at the top of the screen
        self.myname = name + ':' + LEVEL_NAMES[name]
        self.namefont = pygame.font.Font('fonts/ShareTechMono-Regular.ttf' , 20)
        self.nametxt = self.namefont.render(self.myname, True, 
                                            WHITE)
        
        # play music if not already going
        self.game.jukebox.play_music_if('game')

        # get special stuff, e.g. tutorial (this should be a list, and
        # empty if there is no special stuff).
        self.special_stuff = special.get_special_stuff(self, self.game)

    def process_input(self, events, pressed, dt):
        # move the player 
        self.player.process_input(events, pressed, dt)

        for ev in events:
            if (ev.action == SWITCH and ev.down):
                self.game.jukebox.play_sfx('switch')
                self.level.switch()

        # process special stuff (e.g. tutorial)
        for spec in self.special_stuff:
            spec.process_input(events, pressed, dt)

    def update(self, dt):

        self.player.update()
        
        # check for player going off the level
        ybot = self.player.rect.y + self.player.rect.h
        xleft = self.player.rect.x
        if ((xleft < 0) or (xleft > self.lsize[0]) 
            or (ybot < 0) or (ybot > self.lsize[1])):
            self.player.isdead = True
        
        if self.player.isdead:
            self.game.jukebox.play_sfx('dead')
            self.next = DeadScene(self, self.game)

        if self.player.collidedoor:
            self.player.complete_image = self.player.image
            self.game.jukebox.play_sfx('complete')
            self.next = LevelCompleteScene(self, self.game)

        # move camera
        self.camera.update()

        # process special stuff (e.g. tutorial)
        for spec in self.special_stuff:
            spec.update(dt)

    def render(self, screen):

        # background is white at the moment
        screen.blit(self.game.bg, (0, 0))
#        screen.fill(BLACK)
        
        # sprites in the foreground (current level)
        for s in self.level.current_sprites:
            if s.rect.colliderect(self.camera.rect):
                screen.blit(s.image, RelRect(s, self.camera))

        # sprites in the background (other level)
        for s in self.level.other_sprites:
            if s.rect.colliderect(self.camera.rect):
                screen.blit(s.image_other, RelRect(s, self.camera))

        # permanent sprites (e.g. spikes, doors)
        for s in self.level.permanent_sprites:
            if s.rect.colliderect(self.camera.rect):
                screen.blit(s.image, RelRect(s, self.camera))

        # player
        if self.player.image:
            screen.blit(self.player.image, RelRect(self.player, self.camera))

        # name of the level
        screen.blit(self.nametxt, NAME_POS)

        # render special stuff (e.g. tutorial)
        for spec in self.special_stuff:
            spec.render(screen)