def victory(self): self.victory_box.visible = True self.victory_label.visible = True self.victory_ok = True self.setMenuLevel(-1) # self.parent.bgm = pyglet.media.load("bgm/ld26victory.ogg", streaming=False) # self.parent.bgm_player.queue(self.parent.bgm) # self.parent.bgm_player.eos_action = self.parent.bgm_player.EOS_LOOP # self.parent.bgm_player.next() self.dic_victory = [] item = self.items[random.randint(0,len(self.items)-1)] self.dic_victory.append(('victory',True)) self.dic_victory.append(('item',item)) INVENTORY.add(item) self.dic_victory.append(('xp',self.xp)) self.heros[0].xp += self.xp if self.heros[0].level < 10: if self.heros[0].xp >= LEVELS[self.heros[0].level]['nextlevel']: self.heros[0].xp = 0 self.dic_victory.append(('next',True)) for hero in self.heros: hero.set_level()
def victory(self): self.victory_box.visible = True self.victory_label.visible = True self.victory_ok = True self.setMenuLevel(-1) self.parent.bgm = pyglet.media.load("bgm/ld26victory.ogg", streaming=False) self.parent.bgm_player.queue(self.parent.bgm) self.parent.bgm_player.eos_action = self.parent.bgm_player.EOS_LOOP self.parent.bgm_player.next() self.dic_victory = [] item = self.items[random.randint(0,len(self.items)-1)] self.dic_victory.append(('victory',True)) self.dic_victory.append(('item',item)) INVENTORY.add(item) self.dic_victory.append(('xp',self.xp)) self.heros[0].xp += self.xp if self.heros[0].level < 10: if self.heros[0].xp >= LEVELS[self.heros[0].level]['nextlevel']: self.heros[0].xp = 0 self.dic_victory.append(('next',True)) for hero in self.heros: hero.set_level()
def test_combat(zone): INVENTORY.add('potion') INVENTORY.add('potion') INVENTORY.add('dragon blood') INVENTORY.add('stone') INVENTORY.add('honey') heros = [Character('nod1',(0,0),'NOD',1),Character('nel1',(0,0),'NEL',1)] dummy_scene = FightScene(zone,heros) cocos.director.director.push(dummy_scene)
def start_game(): INVENTORY.add('potion') INVENTORY.add('potion') INVENTORY.add('dragon blood') HOOK['NED'] = Character('nel1',(0,0),'NEL',1) player = Character('nod1',(0,0),'NOD',1) player.map_mode() player.do(MoveCharacter()) player.do(CheckForBattle()) MAPS['inside_house_nod'] = Map('inside_house_nod') MAPS['village'] = Map('village') MAPS['village2'] = Map('village2') MAPS['village3'] = Map('village3') MAPS['inside_house_gen_1'] = Map('inside_house_gen_1') MAPS['inside_house_gen_2'] = Map('inside_house_gen_2') MAPS['inside_house_gen_3'] = Map('inside_house_gen_3') MAPS['inside_house_gen_4'] = Map('inside_house_gen_4') MAPS['inside_ceremony_hall'] = Map('inside_ceremony_hall') MAPS['grassland'] = Map('grassland') MAPS['forest'] = Map('forest') MAPS['falaise'] = Map('falaise') MAPS['inside_house_nod'].spawnPlayer(player, (7,9)) MAPS['inside_house_nod'].displayDialog('Intro') cocos.director.director.window.push_handlers(KEYBOARD)
def init_game(): print "Initialising the game..." INVENTORY.add('potion') INVENTORY.add('potion') INVENTORY.add('dragon blood') HOOK['NED'] = Character('nel1',(0,0),'NEL',1) player = Character('nod1',(0,0),'NOD',1) player.map_mode() player.do(MoveCharacter()) player.do(CheckForBattle()) MAPS['inside_house_nod'] = Map('inside_house_nod') MAPS['village'] = Map('village') MAPS['village2'] = Map('village2') MAPS['village3'] = Map('village3') MAPS['inside_house_gen_1'] = Map('inside_house_gen_1') MAPS['inside_house_gen_2'] = Map('inside_house_gen_2') MAPS['inside_house_gen_3'] = Map('inside_house_gen_3') MAPS['inside_house_gen_4'] = Map('inside_house_gen_4') MAPS['inside_ceremony_hall'] = Map('inside_ceremony_hall') MAPS['grassland'] = Map('grassland') MAPS['forest'] = Map('forest') MAPS['falaise'] = Map('falaise') main_command = [ ('Start game',start_game,[player]), ('Credits',push_credit,[]), ('Battle (Prairie)',test_combat,['prairie']), ('Battle (Forest)',test_combat,['forest']), ('How to play',push_how_to_play,[]) ] menu_scene = cocos.scene.Scene() menu_scene.schedule(callback) #Title sprite = cocos.sprite.Sprite('img/GUI/titre.png',(400,450)) menu_scene.add(sprite) menu = Menu(main_command) menu_scene.add(menu) print "Going to menu..." cocos.director.director.replace(cocos.scenes.FadeTransition( menu_scene, duration=2 ) )
def applic_action(self): self.applic_ok = True color_heal = (0,255,0,255) color_hit = (255,0,0,255) color_mp = (0,255,0,255) power = 0 modif = 1. rnd = 1. if self.action not in ('fight-enemy','fight-hero') and self.action not in ITEMS: power = LEVELS[self.heros[self.active].level][self.action] name = self.target.name if self.action not in FRIEND_SKILL: modif = MONSTERS[name][self.action] if self.action in ITEMS: power = ITEMS[self.action] if self.action == 'stone': power += LEVELS[self.heros[self.active].level]['hit'] if self.action == 'fight-hero': power = LEVELS[self.heros[self.active].level]['hit'] if self.action == 'fight-enemy': name = self.origin.name power = MONSTERS[name]['hit'] #modification de la puissance if self.action not in ITEMS: rnd = random.randint(5,15) * 0.1 power = int(power * rnd * modif) #effet if self.action in FRIEND_SKILL: if self.action == 'honey': self.target.mp[0] += power if self.target.mp[0] > self.target.mp[1]: self.target.mp[0] = self.target.mp[1] else: ok = True if self.action in ('life','dragon blood'): if not self.target.is_dead(): ok = False if self.action in ('potion','heal'): if self.target.is_dead(): ok = False if not ok: power = 0 self.target.hp += power else: self.target.hp -= power if self.action in MAGIC: self.origin.mp[0] -= MAGIC[self.action] elif self.action in ITEMS: INVENTORY.remove(self.action) #position pos = self.target.position pos = pos[0], pos[1] + self.target.height - 20 #couleur du texte if self.action in FRIEND_SKILL: if self.action == 'honey': color = color_mp else: color = color_heal else: color = color_hit label = cocos.text.Label(text = str(power),position = pos, font_name = 'Statix', color= color , font_size = 30, anchor_x = 'center') to = pos[0], pos[1] + 30 action = cocos.actions.interval_actions.MoveTo(to, 0.5) label.do(action) self.add(label) self.attacks.append(label)
def setMenuLevel(self,level): self.menu_level = level if self.menu_level == -1: self.n_command = 0 self.choice_arrow.visible = False for menu in self.sub_menu: menu.visible = False self.bar_visible = -1 self.parent.active_arrow.visible = False for l in self.sub_list: for label in l: label.visible = False elif self.menu_level == 0: self.n_command = 0 for menu in self.sub_menu: menu.visible = False self.bar_visible = -1 self.parent.active_arrow.visible = True for l in self.sub_list: for label in l: label.visible = False for l in self.sub_list_add: for label in l: label.visible = False self.choice_arrow.visible = False elif self.menu_level == 1: self.n_slot = 0 self.parent.active_arrow.visible = True if self.n_command == 0: self.action = 'fight-hero' self.choice_arrow.kill() self.choice_arrow = Sprite('img/GUI/arrow_enemy.png') self.add(self.choice_arrow,z=6) self.setMenuLevel(2) if self.n_command == 1 or self.n_command == 2: self.choice_arrow.visible = False menu = self.sub_menu[self.active] menu.visible = True self.bar_visible = self.active for label in self.sub_list[self.active]: label.visible = True for label in self.sub_list_add[self.active]: label.visible = True for cmd in self.sub_list[self.active]: cmd.element.text = '' for cmd in self.sub_list_add[self.active]: cmd.element.text = '' if self.n_command == 1: list_skill = self.heros[self.active].skills for index in range(len(list_skill)): self.sub_list[self.active][index].element.text = list_skill[index] self.sub_list_add[self.active][index].element.text = str(MAGIC[list_skill[index].lower()]) + ' mp' self.next_slot(0) if self.n_command == 2: list_items = INVENTORY.items() list_items.sort() for index in range(len(list_items)): self.sub_list[self.active][index].element.text = list_items[index][0] self.sub_list_add[self.active][index].element.text = 'x' + str (list_items[index][1]) self.next_slot(0) elif self.menu_level == 2: self.choice_arrow.visible = True self.parent.active_arrow.visible = False self.n_choice = 0 self.next_choice()