Ejemplo n.º 1
0
def yesno_prompt(text):
    last_screen = core.screen.copy().convert()
    ls = last_screen.copy().convert()
    bg = core.load_image("yesno_prompt.png", directory="gfx")
    selected = 0
    button_group = sprite.oSpriteGroup()
    def genButton(images, pos):
        button = sprite.oSprite()
        button.x = pos[0]
        button.y = pos[1]
        button.animations = {
            "active": {
                "N": [0,True,[sprite.oFrame(images[0])]]
            },
            "inactive": {
                "N": [0,True,[sprite.oFrame(images[1])]]
            }
        }
        button_group.add(button)
        return button
    
    selected = 0
    buttons = []
    buttons.append( genButton(core.game_images["no"], (200,300)) )
    buttons.append( genButton(core.game_images["yes"], (400,300)) )
    forceUpdate = True
    
    while True:
        lag = core.clock.tick(core.MAX_FPS)
        
        if core.handleEvents() == "quit":
            exit()
                    
        if Input.up(K_LEFT):
            core.play_sound("cursor_move")
            selected -= 1
            if selected < 0:
                selected = len(buttons)-1
        if Input.up(K_RIGHT):
            core.play_sound("cursor_move")
            selected += 1
            if selected >= len(buttons):
                selected = 0
        if Input.up(K_RETURN):
            core.play_sound("button_click")
            core.dissolve_transition(core.screen.copy().convert(), ls, 1000)
            return bool(selected)
        
        for i, button in enumerate(buttons):
            button.changeState("active" if i == selected else "inactive")
                    
        dirty_rects = button_group.update(lag)
        core.screen.blit(ls, (0,0))
        core.screen.blit(bg, (0,0))
        button_group.draw(core.screen)        
        
        dirty_rects.append(core.fonts.Draw(core.screen, None, 36, text,
         pygame.Rect(50,250,700,50), (255,255,255,255), alignHoriz='center', antialias=True))        
        
        if last_screen is not None:
            core.dissolve_transition(last_screen, core.screen.copy().convert(), 1000)
            last_screen = None
        
        core.updateScreen(dirty_rects)
Ejemplo n.º 2
0
# The sound that is currently playing. So if the sound we are playing is the
# same as the new sound to play we don't need to stop the sound.
playing_s = ""

# The background musics for specific areas
game_musics = {}

# The images we use in more than one screen
game_images = { }

# The sound effects we play in game
game_sounds = { }

# Sprite groups
render_group = sprite.oSpriteGroup()
baddys_group = sprite.oSpriteGroup()
attack_group = sprite.oSpriteGroup()
pickup_group = sprite.oSpriteGroup()
level = None

# currying thingy taken from somewhere on the net =D
curry = lambda func, *args, **kw:\
            lambda *p, **n:\
                 func(*args + p, **dict(kw.items() + n.items()))

def updateScreen(dirtyRects=None):
    global forceUpdate
    if not forceUpdate and dirtyRects is not None:
        pygame.display.update(dirtyRects)
    else: