コード例 #1
0
 def attack(self, char):
     if self.freeze > 0 or self.feathers == 0:
         return
     
     core.play_sound("feather_throw")
     
     self.used += 1
     
     if char.direction in "NS":
         d1 = "E"
         d2 = "W"
     else:
         d1 = "N"
         d2 = "S"
         
     f1 = self.create_feather(char)
     f2 = self.create_feather(char, d1)
     f3 = self.create_feather(char, d2)
     f1.life = 1000
     f2.life = 1000
     f3.life = 1000
                 
     self.freeze = 500
     if self.feathers != -1:
         self.feathers -= 1
         if self.feathers < 0:
             self.feathers = 0
コード例 #2
0
 def attack(self, char):
     if self.freeze > 0 or self.feathers == 0:
         return
     
     core.play_sound("feather_throw")
     
     self.used += 1
     
     f1 = self.create_feather(char)
     f2 = self.create_feather(char)
     f1.xspeed = 1
     f2.xspeed = -1
     f1.life = 1000
     f2.life = 1000
     if char.direction in "NS":
         f1.x -= 5
         f2.x += 5
     else:
         f1.y -= 5
         f2.y += 5
                 
     self.freeze = 500
     if self.feathers != -1:
         self.feathers -= 1
         if self.feathers < 0:
             self.feathers = 0
コード例 #3
0
 def attack(self, char):
     if self.freeze > 0 or self.feathers == 0:
         return
     
     core.play_sound("feather_throw")
     
     self.used += 1
     
     self.create_feather(char)
     
     self.freeze = 250
     if self.feathers != -1:
         self.feathers -= 1
         if self.feathers < 0:
             self.feathers = 0
コード例 #4
0
ファイル: game.py プロジェクト: robotlolita/red-spider-lily
def credits_screen():
    goscreen = core.load_image("credits.png", directory="gfx", auto_alpha=False)
    core.dissolve_transition( core.screen.copy().convert(), goscreen.copy().convert(), 1000 )
    
    while True:
        core.clock.tick(core.MAX_FPS)
        
        events = pygame.event.get()
        
        if core.handleEvents(events) == "quit":
            exit()
            
        for event in events:
            if event.type == KEYUP:
                core.play_sound("button_click")
                Input.update()
                core.next_screen = main_menu
                return
        
        core.screen.blit(goscreen, (0,0))                        
        core.updateScreen()
コード例 #5
0
 def attack(self, char):
     if self.freeze > 0 or self.feathers == 0:
         return
     
     core.play_sound("feather_throw")
     
     self.used += 1
                 
     f1 = self.create_feather(char, "N")
     f2 = self.create_feather(char, "S")
     f3 = self.create_feather(char, "W")
     f4 = self.create_feather(char, "E")
     f1.life = 1000
     f2.life = 1000
     f3.life = 1000
     f4.life = 1000
                 
     self.freeze = 500
     if self.feathers != -1:
         self.feathers -= 1
         if self.feathers < 0:
             self.feathers = 0
コード例 #6
0
ファイル: game.py プロジェクト: robotlolita/red-spider-lily
def main_game():  
    global mc, tutorial, hints, killed_bugs
    

#    if yesno_prompt("Play tutorial level?"):
#        tutorial = True
#        hints    = 0
    
    core.baddys_group.clear()
    core.render_group.clear()
    core.attack_group.clear()
    
    # load bg
    sky_bg = core.load_image("sky_bg.png", directory="gfx", auto_alpha=False)
    exp_bgs = core.load_image("exp_bg.png", directory="gfx")
    exp_bg = sprite.oSprite()
    exp_bg.x = 10
    exp_bg.y = 545
    exp_bg.animations = {
        "stopped": {
            "N": [0, True, [
                sprite.oFrame(core.im_crop(exp_bgs, pygame.Rect(0,0,278,33))),
                sprite.oFrame(core.im_crop(exp_bgs, pygame.Rect(0,33,278,33))),
                sprite.oFrame(core.im_crop(exp_bgs, pygame.Rect(0,66,278,33)))
            ]]
        }
    }
    exp_bg.changeState("stopped")
    core.render_group.add(exp_bg)
       
    # initialize map
    core.level = map.oMap()

    # current stats
    level = 0
    level_time = oStatsDisp(core.level.time, (700,20), useNumbers=True, formatValue=format_level_time)
    lives = oStatsDisp(3, (10, 20), image=core.load_image("haato.png", directory="gfx"))
    score = oStatsDisp(0, (0,20), xalign=0.5, useNumbers=True, formatValue=format_score)

    # main character
    mc = sprite.oSprite()
    
    mc_sprite = core.load_image("nozomi.png", directory="gfx")
    mc_mask   = core.load_image("nozomi_mask.png", directory="gfx")
    
    mc.animFromStrip( mc_sprite, [
        ["stopped","S",1,1,0,True, (23,45), (23,33)],
        ["stopped","W",4,1,0,True, (23,45), (17,33)],
        ["stopped","E",7,1,0,True, (23,45), (30,33)],
        ["stopped","N",10,1,0,True,(23,45), (23,33)],
        ["walking","S",0,3,.02,True, (23,45), (23,33)],
        ["walking","W",3,3,.02,True, (23,45), (17,33)],
        ["walking","E",6,3,.02,True, (23,45), (30,33)],
        ["walking","N",9,3,.02,True, (23,45), (23,33)],
        ["dying",  "N",12,3,0.01,False, (23,45)]
    ], 48, 48, mc_mask )
    
    mc.changeState("stopped")
    mc.AI = core.handlePlayerControls
    core.render_group.add(mc)
    
    available_attacks = [
        featheratk.oDoubleAttack(core.load_image("double_feather.png", directory="gfx")),
        featheratk.oTriangleAttack(core.load_image("triangle_feather.png", directory="gfx")),
        featheratk.oCrossAttack(core.load_image("cross_feather.png", directory="gfx"))
    ]
    
    mc.attacks = [ 
        featheratk.oBasicAttack(core.load_image("debug_feather.png", directory="gfx"))        
    ]
    mc.use_attack = 0
    
    # load map
    load_level(level, mc)
    
    killed_bugs = 0
    lost_lives = 0
    mid_rank = 0
    rank_num = 0
    
    forceUpdate = True
    
    while True:
        lag = core.clock.tick(core.MAX_FPS)
        if lag <= 0:
            lag = 1
        
        level_time.update(level_time.value - lag/1000.0)
        if level_time.value < 0:
            main_char_death(mc)
            core.play_sound("mc_dying")
            lives.update(lives.value-1)
            lost_lives += 1
        
        if core.handleEvents() == "quit":
            return
                        
        dirty_rects = core.render_group.update(lag)
        core.level.updateNests(lag)
        exp_bg.animFrame = core.mathExp.state
        
        # check collisions
        # bugs
        if core.render_group.checkCollision(False, False, mc, core.baddys_group):
            main_char_death(mc)
            core.play_sound("mc_dying")
            lives.update(lives.value-1)
            lost_lives += 1
                
        # pickups
        picked = core.pickup_group.checkCollision(False, False, mc, core.pickup_group)
        for pickup in picked:
            pickup = pickup[0]
            # new live :D
            if isinstance(pickup, sprite.oHeartSprite):
                core.play_sound("live_gain")
                lives.update(lives.value+1)
                pickup.die()
                
        # feather attacks
        kills = core.attack_group.checkCollision(False, False, None, core.baddys_group)
        score.update(score.value + 100*len(kills))
        killed_bugs += len(kills)
        for i in kills:
            core.play_sound("bug_dying")
            if hasattr(i[0], "attackMgr"):
                feather, bug = i
            if hasattr(i[1], "attackMgr"):
                bug, feather = i
            feather.attackMgr.kills += 1
            feather.die()
            bug.OnAnimationEnd = bug.die
            bug.direction = "N"
            bug.changeState("dying")
        

        if lives.value == 0 and mc.OnAnimationEnd is None:
            if rank_num == 0:
                _rank = 0
            else:
                _rank = mid_rank / rank_num
            core.next_screen = core.curry(game_over, score.value, _rank)
            return
        
        # draw level / sprites
        core.screen.blit(sky_bg, (0,0))
        dirty_rects.extend( core.level.draw(core.screen) )
        core.render_group.draw(core.screen)
        
        # draw stats
        # lives
        dirty_rects.extend( lives.draw(core.screen) )
        # math exp
        dirty_rects.extend( core.mathExp.draw(core.screen) )
        # time
        dirty_rects.extend( level_time.draw(core.screen) )
        # score
        dirty_rects.extend( score.draw(core.screen) )
        # attacks
        for i, attack in enumerate(mc.attacks):
            attack.update(lag)
            dirty_rects.extend( attack.draw(core.screen, i == mc.use_attack) )
                
#        dirty_rects.append( core.fonts.Draw(core.screen, None, 24,
#         str(core.clock.get_fps()), (650, 50), (255,255,255,255)))
        
        
        if forceUpdate:
            dirty_rects = None
        forceUpdate = False
        core.updateScreen(dirty_rects)
        

        
        # clear level =D
        if core.level.portalActive:
            _score, rank = level_clear_screen(mc, killed_bugs, level_time.value, lives.value, lost_lives, score.value)
            score.update(_score)
            mid_rank += rank
            rank_num += 1
            lost_lives = 0
            core.baddys_group.clear()
            core.attack_group.clear()
            level += 1
            
            if not load_level(level, mc):
                core.next_screen = core.curry(game_ending, core.curry(hiscores_screen, score.value, mid_rank/rank_num))
                return
            
            
            if available_attacks:
                new_attack = available_attacks.pop(0)
                feather_received(new_attack)
                mc.attacks.append( new_attack )
            
            level_time.update(core.level.time)
            mc.changeState("stopped")
            for attack in mc.attacks:
                attack.freeze = 0
                attack.used = 0
                attack.kills = 0
                attack.last_rects = []
            
            forceUpdate = True
コード例 #7
0
ファイル: game.py プロジェクト: robotlolita/red-spider-lily
def hiscores_screen(score=None, rank=0):
    last_screen = core.screen.copy().convert()
    scores = []
    
    import xdrlib
    if not os.path.exists("high_scores"):
        # fill with default scores
        default_scores = [(100000,2),(50000,2),(30000,2),(20000,2),(10000,2),(8000,1),
                          (4000,1),(500,0)]
        for i in range(8):
            s, r = default_scores[i]
            scores.append( ("Nozomi", s, r) )
    
    else:
        # load from file
        data = open("high_scores", "rb").read()
        loader = xdrlib.Unpacker(data)
        for i in range(8):
            scores.append( (loader.unpack_string(), loader.unpack_int(), loader.unpack_int()) )
        
        
    # verify if we have a high score =D
    if score is not None:
        for index, _score in enumerate(scores):
            name, _score, _rank = _score
            if (score > _score) or (score == _score and rank > _rank):
                player_name = core.InputPrompt("Nice timing! You've scored high, Mr/Mrs...", "Player")
                scores.insert(index, (player_name, score, rank))
                break
    
        # save scores
        p = xdrlib.Packer()
        for name, score, rank in scores:
            p.pack_string(name)
            p.pack_int(score)
            p.pack_int(rank)
            
        f = open("high_scores", "wb")
        f.write(p.get_buffer())
        f.close()
    
    # load graphics =D
    bg = core.load_image("hiscores.png", directory="gfx")
    stars = pygame.transform.smoothscale(core.load_image("rank_star.png", directory="gfx"), (86,40))
    stars = [ core.im_crop(stars, pygame.Rect(0,0,43,40)),
              core.im_crop(stars, pygame.Rect(43,0,43,40)) ]
    
    
    core.screen.blit(bg, (0,0))
    
    
    # render high scores!
    for index, score in enumerate(scores):
        name, score, rank = score
        # 260, 100
        y = 100 + 40*index
        # name
        core.fonts.Draw(core.screen, None, 36, name, pygame.Rect(260,y,200,40),
         (255,255,255,255),alignVert='center',antialias=True)
        
        # points
        score = str(score)
        w = 160-core.numbers.getWidth(score)
        core.numbers.draw(core.screen, (470+w,y+8), score)
        
        # rank
        if rank > 2:
            core.screen.blit(stars[1], (660,y))
        else:
            core.screen.blit(stars[0], (660,y))
        if rank > 1:
            core.screen.blit(stars[1], (703,y))
        else:
            core.screen.blit(stars[0], (703,y))
        if rank > 0:
            core.screen.blit(stars[1], (746,y))
        else:
            core.screen.blit(stars[0], (746,y))
            
    core.dissolve_transition(last_screen, core.screen.copy().convert(), 1000)
    
    while True:
        events = pygame.event.get()
        if core.handleEvents(events) == "quit":
            exit()
            
        for event in events:
            if event.type == KEYUP:
                core.next_screen = main_menu
                core.play_sound("button_click")
                Input.update()
                return
コード例 #8
0
ファイル: game.py プロジェクト: robotlolita/red-spider-lily
def main_menu():
    core.play_music("main menu")
    # load bg
    bg = core.load_image("main_menu.png", directory="gfx", auto_alpha=False)
    selected = 0
    
    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])]]
            }
        }
        core.render_group.add(button)
        return button
    
    selected = 0
    buttons = []
    core.render_group.clear()
    for i, button in enumerate(["new game","help","credits","exit"]):
        y = 180 + i*40
        x = 75
        buttons.append( genButton(core.game_images[button], (x,y)) )
    
    menu_screens = [
        game_intro,     # new game
        hiscores_screen,# high scores
        credits_screen, # credits
        exit_screen,    # exit
    ]
    
    forceUpdate = True
    last_screen = core.screen.copy().convert()
    
    while True:
        lag = core.clock.tick(core.MAX_FPS)
        
        if core.handleEvents() == "quit":
            exit()
                    
        if Input.up(K_UP):
            core.play_sound("cursor_move")
            selected -= 1
            if selected < 0:
                selected = len(buttons)-1
        if Input.up(K_DOWN):
            core.play_sound("cursor_move")
            selected += 1
            if selected >= len(buttons):
                selected = 0
        if Input.up(K_RETURN):
            core.next_screen = menu_screens[selected]
            core.play_sound("button_click")
            return
        
        for i, button in enumerate(buttons):
            button.changeState("active" if i == selected else "inactive")
                    
        dirty_rects = core.render_group.update(lag)
        core.screen.blit(bg, (0,0))
        core.render_group.draw(core.screen)        
        
        if last_screen is not None:
            core.dissolve_transition(last_screen, core.screen.copy().convert(), 1000)
            last_screen = None
        
        if forceUpdate:
            dirty_rects = None
        core.updateScreen(dirty_rects)
コード例 #9
0
ファイル: game.py プロジェクト: robotlolita/red-spider-lily
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)