Example #1
0
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)
Example #2
0
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 ) )
Example #3
0
    def step(self, dt):

        if self.target.current_map.timer < 2.0:
            self.target.visible = False
            self.target.current_map.timer += dt
            return
        else:
            self.target.visible = True

        # handle input and move the character
        if self.target.current_map.dialog_layer.visible == True:
            return
        self.target.velocity = ((KEYBOARD[key.RIGHT] - KEYBOARD[key.LEFT]) *
                                150,
                                (KEYBOARD[key.UP] - KEYBOARD[key.DOWN]) * 150)
        if self.target.current_map is not None:

            x0 = self.target.position[0]
            y0 = self.target.position[1]

            x = self.target.position[0] + self.target.velocity[0] * dt
            y = self.target.position[1] + self.target.velocity[1] * dt

            #rect = cocos.rect.Rect(x-12, y, 24, 16)
            rect_x = cocos.rect.Rect(x - 12, y0, 24, 16)
            rect_y = cocos.rect.Rect(x0 - 12, y, 24, 16)

            for i in range(int(x / TILE_SIZE) - 1, int(x / TILE_SIZE) + 2):
                for j in range(int(y / TILE_SIZE) - 1, int(y / TILE_SIZE) + 2):
                    cell = self.target.current_map.map_layer.get_cell(i, j)
                    cell2 = self.target.current_map.map_layer2.get_cell(i, j)

                    if cell is not None:
                        if cell.intersects(rect_x):
                            if cell is not None and 'passable' in cell and cell[
                                    'passable'] == 'True':
                                if cell2 is not None and 'passable' in cell2 and cell2[
                                        'passable'] == 'True':
                                    pass
                                else:
                                    self.target.velocity = (
                                        0, self.target.velocity[1])
                            else:
                                self.target.velocity = (
                                    0, self.target.velocity[1])

                        if cell.intersects(rect_y):
                            if cell is not None and 'passable' in cell and cell[
                                    'passable'] == 'True':
                                if cell2 is not None and 'passable' in cell2 and cell2[
                                        'passable'] == 'True':
                                    pass
                                else:
                                    self.target.velocity = (
                                        self.target.velocity[0], 0)
                            else:
                                self.target.velocity = (
                                    self.target.velocity[0], 0)

            if self.target.velocity != (0, 0):
                self.target.map_position = [
                    int(self.target.position[0]) / TILE_SIZE,
                    int(self.target.position[1]) / TILE_SIZE
                ]
                self.target.current_map.scroller.set_focus(
                    self.target.position[0], self.target.position[1])
                self.target.battle_timer += dt

                cell = self.target.current_map.map_layer2.get_cell(
                    self.target.map_position[0], self.target.map_position[1])
                if 'door' in cell:
                    self.target.current_map = MAPS[cell['door_map']]
                    dest = cell['door_destination'].split()
                    dest = [int(dest[0]), int(dest[1])]
                    self.target.current_map.spawnPlayer(self.target, dest)
            #
            # if next_cell is not None and 'passable' in next_cell and next_cell['passable'] == 'True':
            #     if 'door' in next_cell:
            #         self.target.current_map = MAPS[next_cell['door_map']]
            #         dest = next_cell['door_destination'].split()
            #         dest = [int(dest[0]), int(dest[1])]
            #         self.target.current_map.spawnPlayer(self.target, dest)
            #     self.target.map_position = [int(self.target.position[0]) / TILE_SIZE, int(self.target.position[1]) / TILE_SIZE]
            #     self.target.current_map.scroller.set_focus(self.target.position[0], self.target.position[1])
            #     self.target.battle_timer += dt
            # else:
            #     # Nice to have : slider le long des murs
            #     self.target.velocity = (0,0)

            player_rect = self.target.get_rect()
            player_rect.x += self.target.velocity[0] * dt
            player_rect.y += self.target.velocity[1] * dt

            if self.target.current_map.name == 'falaise':

                if TRIGGERS['cliff'] == 3:
                    self.target.current_map.displayDialog('Nod_Nel_Followers')
                    TRIGGERS['cliff'] = 4

                if TRIGGERS['cliff'] == 2:
                    for npc in self.target.current_map.npcs:
                        self.target.current_map.npcs[npc].do(
                            cocos.actions.interval_actions.MoveBy(
                                (0, 32 * 14 + 32 * random.randint(-2, 2)),
                                random.randint(4, 5)))
                    TRIGGERS['cliff'] = 3

                if TRIGGERS['cliff'] == 1:
                    self.target.current_map.displayDialog('Nod_Nel_G')
                    TRIGGERS['cliff'] = 2

            if self.target.current_map.name == 'forest':
                if TRIGGERS['forest'] == 1:
                    self.target.current_map.displayDialog('Nod_Nel_Dude')
                    TRIGGERS['forest'] = 2

            if TRIGGERS['found_nel'] and TRIGGERS['village_state'] == 1:
                TRIGGERS['village_state'] = 2
                self.target.current_map.char_layer.remove(
                    self.target.current_map.npcs['nel11'])
                self.target.current_map.npcs.pop('nel11')
                self.target.current_map.npcs['villagera4'].do(
                    cocos.actions.interval_actions.MoveBy((-1000, 0), 5))

            if TRIGGERS[
                    'village_state'] == 3 and self.target.current_map.name == 'inside_ceremony_hall':
                thewise = Character('n_the_wise', (0, 0))
                self.target.current_map.placeCharacter(thewise, (13, 2))
                thewise.do(cocos.actions.interval_actions.MoveBy((0, 256), 3))
                self.target.current_map.displayDialog('N_friends_Wise_A')
                TRIGGERS['village_state'] = 4

            if TRIGGERS['village_state'] == 10:
                self.target.current_map.displayDialog('Nod_Nel_D')
                TRIGGERS['village_state'] = 11

            if TRIGGERS['village_state'] == 9:
                self.target.current_map = MAPS['village3']
                self.target.current_map.spawnPlayer(self.target, (6, 9))
                TRIGGERS['village_state'] = 10

            if TRIGGERS['village_state'] == 8:
                self.target.current_map.displayDialog('Ellipse')
                TRIGGERS['village_state'] = 9

            if TRIGGERS['village_state'] == 7:
                self.target.current_map = MAPS['inside_house_nod']
                self.target.current_map.spawnPlayer(self.target, (5, 8))
                TRIGGERS['village_state'] = 8

            if TRIGGERS['village_state'] == 6:
                self.target.current_map.displayDialog('Nod_Nel_C')
                TRIGGERS['village_state'] = 7

            if TRIGGERS['village_state'] == 5:
                self.target.current_map = MAPS['village2']
                self.target.current_map.spawnPlayer(self.target, (24, 16))
                TRIGGERS['village_state'] = 6

            if TRIGGERS[
                    'village_state'] == 4 and self.target.current_map.name == 'village':
                self.target.current_map.displayDialog('Nod_Nel_B')
                TRIGGERS['village_state'] = 5

            for npc in self.target.current_map.npcs:
                if player_rect.intersects(
                        self.target.current_map.npcs[npc].get_rect()):
                    self.target.velocity = (0, 0)
                    self.target.in_dialog = True

                    if TRIGGERS['village_state'] == 1 and not TRIGGERS[
                            'found_nel']:
                        print 'Name', self.target.current_map.npcs[npc].name
                        if self.target.current_map.npcs[npc].name == 'nel11':
                            self.target.current_map.displayDialog('Nod_Nel_A')
                            TRIGGERS['found_nel'] = True
                        else:
                            self.target.current_map.displayDialog(
                                'Villageois_A')
                    elif TRIGGERS['village_state'] == 2:
                        if self.target.current_map.name == 'inside_ceremony_hall':
                            self.target.current_map.displayDialog(
                                'N_friends_A')
                            TRIGGERS['village_state'] = 3
                        else:
                            self.target.current_map.displayDialog(
                                'Villageois_B')

            for item in self.target.current_map.items:
                if player_rect.intersects(
                        self.target.current_map.items[item].get_rect()):
                    print "ITEMY!"

        super(MoveCharacter, self).step(dt)
Example #4
0
    def step(self, dt):

        if self.target.current_map.timer < 2.0:
            self.target.visible = False
            self.target.current_map.timer += dt
            return
        else:
            self.target.visible = True

        # handle input and move the character
        if self.target.current_map.dialog_layer.visible == True:
            return
        self.target.velocity = ((KEYBOARD[key.RIGHT] - KEYBOARD[key.LEFT]) * 150,(KEYBOARD[key.UP] - KEYBOARD[key.DOWN]) * 150 )
        if self.target.current_map is not None:

            x0 = self.target.position[0]
            y0 = self.target.position[1]

            x = self.target.position[0] + self.target.velocity[0]*dt
            y = self.target.position[1] + self.target.velocity[1]*dt

            #rect = cocos.rect.Rect(x-12, y, 24, 16)
            rect_x = cocos.rect.Rect(x-12, y0, 24,16)
            rect_y = cocos.rect.Rect(x0-12, y, 24,16)

            for i in range(int(x/TILE_SIZE)-1,int(x/TILE_SIZE)+2):
                for j in range(int(y/TILE_SIZE)-1, int(y/TILE_SIZE)+2):
                    cell = self.target.current_map.map_layer.get_cell(i,j)
                    cell2 = self.target.current_map.map_layer2.get_cell(i,j)

                    if cell is not None:
                        if cell.intersects(rect_x):
                            if cell is not None and 'passable' in cell and cell['passable'] == 'True':
                                if cell2 is not None and 'passable' in cell2 and cell2['passable'] == 'True':
                                    pass
                                else:
                                    self.target.velocity = (0,self.target.velocity[1])
                            else:
                                self.target.velocity = (0,self.target.velocity[1])
                        
                        if cell.intersects(rect_y):
                            if cell is not None and 'passable' in cell and cell['passable'] == 'True':
                                if cell2 is not None and 'passable' in cell2 and cell2['passable'] == 'True':
                                    pass
                                else:
                                    self.target.velocity = (self.target.velocity[0],0)
                            else:
                                self.target.velocity = (self.target.velocity[0],0)

            if self.target.velocity != (0,0):
                self.target.map_position = [int(self.target.position[0]) / TILE_SIZE, int(self.target.position[1]) / TILE_SIZE]
                self.target.current_map.scroller.set_focus(self.target.position[0], self.target.position[1])
                self.target.battle_timer += dt

                cell = self.target.current_map.map_layer2.get_cell(self.target.map_position[0],self.target.map_position[1])
                if 'door' in cell:
                    self.target.current_map = MAPS[cell['door_map']]
                    dest = cell['door_destination'].split()
                    dest = [int(dest[0]), int(dest[1])]
                    self.target.current_map.spawnPlayer(self.target, dest)
            #    
            # if next_cell is not None and 'passable' in next_cell and next_cell['passable'] == 'True':
            #     if 'door' in next_cell:
            #         self.target.current_map = MAPS[next_cell['door_map']]
            #         dest = next_cell['door_destination'].split()
            #         dest = [int(dest[0]), int(dest[1])]
            #         self.target.current_map.spawnPlayer(self.target, dest)
            #     self.target.map_position = [int(self.target.position[0]) / TILE_SIZE, int(self.target.position[1]) / TILE_SIZE]
            #     self.target.current_map.scroller.set_focus(self.target.position[0], self.target.position[1])
            #     self.target.battle_timer += dt
            # else:
            #     # Nice to have : slider le long des murs
            #     self.target.velocity = (0,0)


            player_rect = self.target.get_rect()
            player_rect.x += self.target.velocity[0]*dt
            player_rect.y += self.target.velocity[1]*dt

            if self.target.current_map.name == 'falaise':
                

                if TRIGGERS['cliff'] == 3:
                    self.target.current_map.displayDialog('Nod_Nel_Followers')
                    TRIGGERS['cliff'] = 4

                if TRIGGERS['cliff'] == 2:
                    for npc in self.target.current_map.npcs:
                        self.target.current_map.npcs[npc].do(cocos.actions.interval_actions.MoveBy((0,32*14+32*random.randint(-2,2)),random.randint(4,5)))
                    TRIGGERS['cliff'] = 3

                if TRIGGERS['cliff'] == 1:
                    self.target.current_map.displayDialog('Nod_Nel_G')
                    TRIGGERS['cliff'] = 2

            if self.target.current_map.name == 'forest':
                if TRIGGERS['forest'] == 1:
                    self.target.current_map.displayDialog('Nod_Nel_Dude')
                    TRIGGERS['forest'] = 2                



            if TRIGGERS['found_nel'] and TRIGGERS['village_state'] == 1:
                TRIGGERS['village_state'] = 2
                self.target.current_map.char_layer.remove(self.target.current_map.npcs['nel11'])
                self.target.current_map.npcs.pop('nel11')
                self.target.current_map.npcs['villagera4'].do(cocos.actions.interval_actions.MoveBy((-1000,0),5))

            if TRIGGERS['village_state'] == 3 and self.target.current_map.name == 'inside_ceremony_hall':
                thewise = Character('n_the_wise',(0,0))
                self.target.current_map.placeCharacter(thewise, (13,2))
                thewise.do(cocos.actions.interval_actions.MoveBy((0,256),3))
                self.target.current_map.displayDialog('N_friends_Wise_A')
                TRIGGERS['village_state'] = 4


            if TRIGGERS['village_state'] == 10:
                self.target.current_map.displayDialog('Nod_Nel_D')
                TRIGGERS['village_state'] = 11


            if TRIGGERS['village_state'] == 9:
                self.target.current_map = MAPS['village3']
                self.target.current_map.spawnPlayer(self.target, (6,9))
                TRIGGERS['village_state'] = 10                


            if TRIGGERS['village_state'] == 8:
                self.target.current_map.displayDialog('Ellipse')
                TRIGGERS['village_state'] = 9


            if TRIGGERS['village_state'] == 7:
                self.target.current_map = MAPS['inside_house_nod']
                self.target.current_map.spawnPlayer(self.target, (5,8))
                TRIGGERS['village_state'] = 8


            if TRIGGERS['village_state'] == 6:
                self.target.current_map.displayDialog('Nod_Nel_C')
                TRIGGERS['village_state'] = 7

            if TRIGGERS['village_state'] == 5:
                self.target.current_map = MAPS['village2']
                self.target.current_map.spawnPlayer(self.target, (24,16))
                TRIGGERS['village_state'] = 6

            if TRIGGERS['village_state'] == 4 and self.target.current_map.name == 'village':
                self.target.current_map.displayDialog('Nod_Nel_B')
                TRIGGERS['village_state'] = 5

            for npc in self.target.current_map.npcs:
                if player_rect.intersects(self.target.current_map.npcs[npc].get_rect()):
                    self.target.velocity = (0,0)
                    self.target.in_dialog = True

                    if TRIGGERS['village_state'] == 1 and not TRIGGERS['found_nel']:
                        print 'Name', self.target.current_map.npcs[npc].name
                        if self.target.current_map.npcs[npc].name == 'nel11':
                            self.target.current_map.displayDialog('Nod_Nel_A')
                            TRIGGERS['found_nel'] = True
                        else:
                            self.target.current_map.displayDialog('Villageois_A')
                    elif TRIGGERS['village_state'] == 2:
                        if self.target.current_map.name == 'inside_ceremony_hall':
                            self.target.current_map.displayDialog('N_friends_A')
                            TRIGGERS['village_state'] = 3
                        else:
                            self.target.current_map.displayDialog('Villageois_B')


            for item in self.target.current_map.items:
                if player_rect.intersects(self.target.current_map.items[item].get_rect()):
                    print "ITEMY!"

        super(MoveCharacter, self).step(dt)