Пример #1
0
    def update_rect(self):
        pos = Vector2()
        if self.pos:
            pos = self.pos
        if self.screen_relative_pos:
            pos = pos+self.screen_relative_pos*engine.get_screen_size()
        self.rect = Rect(pos, self.size, self.angle)

        center_pos = Vector2()
        if self.body:
            center_pos = physics_manager.get_body_position(self.body)
            if self.screen_relative_pos:
                center_pos = center_pos - self.screen_relative_pos*engine.get_screen_size()

            self.not_rot_pos = center_pos

        v = self.size/2
        v.rotate(-self.angle)
        if self.angle > 0:
            pos = self.not_rot_pos + (v-self.size/2)
        else:
            pos = self.not_rot_pos + (self.size/2-v)

        size_y = Vector2(self.size.x, 0)
        size_y.rotate(self.angle)
        v = Vector2(self.size.x, self.size.y + math.fabs(size_y.y))
        self.click_rect = Rect(self.not_rot_pos-v/2, v)
Пример #2
0
    def set_answers(self, answers):
        del self.answers_text[:]
        del self.answers_image[:]
        i = 0
        answer_nmb = len(answers)
        for answer in answers:

            pos = (engine.get_screen_size()*Vector2((1 - self.answer_size.x), ((1 - self.dialog_y_size) - (answer_nmb - i) * self.answer_size.y)))
            size = (engine.get_screen_size()*Vector2(self.answer_size.x, self.answer_size.y))
            self.answers_text.append(Text(pos=pos, size=size.y, font=self.dialog_font, text=answer, relative=True))
            if self.dialog_box_image:
                self.answers_image.append(Image(self.dialog_box_image, pos, size=size, relative=True))
            i += 1
Пример #3
0
    def loop(self, screen):
        img_manager.draw_rect(screen, Vector2(), Rect(Vector2(0, 0), engine.get_screen_size()), (255, 255, 255))
        self.cat.loop(screen)
        self.ferret.loop(screen)

        if not self.dialog:
            img_manager.show_image(self.img,screen,Vector2(0,-48))


            if (self.time % 20) > 10:
                img_manager.buffer.draw(self.text)

            self.time += 1
        if not self.dialog and (input_manager.get_button("A") or input_manager.get_button("B")):
            snd_manager.set_playlist(["data/music/intro_BOSS1_gbjam.ogg","data/music/BOSS1_gbjam.ogg"])
            self.dialog = 1
            engine.show_dialog = True
            engine.textbox.set_text("Fury", "General Meow, you are still alive")
        if self.dialog == 1 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 2
                engine.textbox.set_text("General Meow", "I'm not easy to kill. Don't forget it")
        if self.dialog == 2 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 3
                engine.textbox.set_text("Fury","I won't miss you next time")
        if self.dialog == 3 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                engine.show_dialog = False
                from engine.level_manager import switch_level
                switch_level(GameState(CONST.startup))
        snd_manager.update_music_status()
Пример #4
0
 def loop(self, screen):
     img_manager.draw_rect(screen,Vector2(),Rect(Vector2(0,0),engine.get_screen_size()),(255,255,255))
     self.text.loop(screen)
     if snd_manager.get_music_status():
         from engine.level_manager import switch_level
         switch_level(Dorian())
     snd_manager.update_music_status()
Пример #5
0
    def loop(self, screen, screen_pos):
        if self.anim:
            self.anim.update_animation()
            self.img = self.anim.img
        pos = Vector2()
        if self.pos:
            pos = self.pos
        
        if self.screen_relative_pos is not None:
            pos = pos + self.screen_relative_pos * engine.get_screen_size()

        if self.screen_relative:
            pos = self.pos
        else:
            pos = pos - screen_pos
        
        center_image = False
        try:
            center_image = self.center_image
        except AttributeError:
            pass
            
        img_manager.show_image(self.img,
                   screen,
                   pos,
                   new_size=self.size,
                   center_image=center_image,
                   angle=self.angle,
                   flip=self.flip)

        GameObject.loop(self, screen, screen_pos)
Пример #6
0
    def loop(self, screen):
        if CONST.network and self.player:
            client.set_request(self.player.pos + engine.get_screen_size() * self.player.screen_relative_pos,
                               self.player.anim.state,
                               self.player.anim.index)
            client.get_players_request()
            players_list = client.players
            """Check if player already present else set an image"""
            for p in players_list.keys():
                if p != str(get_self_id()):
                    try:
                        self.players_img[p]

                    except KeyError:
                        self.players_img[p] = Image("", players_list[p][1], size=self.player.size)
                    self.players_img[p].pos = players_list[p][1]
                    try:
                        anim_index = self.player.anim.img_indexes[
                                     self.player.anim.state_range[players_list[p][2]][0]:
                                     self.player.anim.state_range[players_list[p][2]][1]]
                        try:
                            self.players_img[p].img = anim_index[players_list[p][3]]
                        except IndexError:
                            self.players_img[p].img = anim_index[0]
                    except KeyError:
                        pass
                    self.players_img[p].loop(screen,self.screen_pos)
Пример #7
0
def set_player(new_player):
    global player_pos, player_anim_counter, player_anim_state, client_player_lock
    from engine.init import engine
    client_player_lock.acquire()
    player_pos = new_player.pos + new_player.screen_relative_pos * engine.get_screen_size()
    player_anim_state = new_player.anim.state
    player_anim_counter = new_player.anim.anim_counter
    client_player_lock.release()
Пример #8
0
 def init(self):
     self.loading_screen = LoadingScreen()
     self.loading_screen.init_method = [GameState(CONST.startup)]
     self.loading_screen.init()
     self.text = Image('data/sprites/text/kwakwa.png',
                       engine.get_screen_size()/2)
     self.text.pos = self.text.pos-self.text.size/2
     self.count = 4 * CONST.framerate
     snd_manager.play_music("data/sound/pissed_off_duck.wav")
Пример #9
0
 def update_state(self):
     RIGHT = get_button('player_right')
     LEFT = get_button('player_left')
     UP = get_button('player_up')
     DOWN = get_button('player_down')
     
     horizontal = RIGHT-LEFT
     vertical = UP-DOWN
     
     physics_events = get_physics_event()
     
     for event in physics_events:
         if (event.a.userData == 2 and event.b.userData == 11 ) or \
                 ( event.b.userData == 2 and event.a.userData == 11):
             if event.begin:
                 self.foot += 1
             else:
                 self.foot -= 1
     
     if horizontal == -1:
         self.direction = False
         if self.foot:
             self.state = 'move'
         self.player.flip = True
         physics_manager.move(self.player.body, -self.speed)
     elif horizontal == 1:
         self.direction = True
         if self.foot:
             self.state = 'move'
         self.player.flip = False
         physics_manager.move(self.player.body, self.speed)
     else:
         if self.foot:
             if self.direction:
                 self.state = 'still'
                 self.player.flip = False
             else:
                 self.state = 'still'
                 self.player.flip = True
         physics_manager.move(self.player.body, 0)
     if not self.foot:
         if self.direction:
             self.state = 'jump'
             self.player.flip = False
         else:
             self.state = 'jump_left'
             self.player.flip = True
     physics_pos = physics_manager.get_body_position(self.player.body)
     
     if physics_pos:
         pos = physics_pos-self.player.size/2
     else:
         pos = self.player.pos
     if self.player.screen_relative_pos:
         pos = pos-self.player.screen_relative_pos*engine.get_screen_size()
     self.player.pos = pos
Пример #10
0
    def loop(self, screen):
        img_manager.draw_rect(screen, Vector2(), Rect(Vector2(),engine.get_screen_size()),self.bg_color)
        snd_manager.update_music_status()
        """
        if CONST.render == 'kivy':
            for layer in self.objects:
                for img in layer:
                    #set img pos outside the screen
                    if isinstance(img, AnimImage):
                        for kivy_img in img.anim.img_indexes:
                            kivy_img.x = -engine.get_screen_size().x
                            kivy_img.y = -engine.get_screen_size().y
        """
        '''Event
        If mouse_click on element, execute its event, of not null'''
        if self.show_mouse:
            show_mouse()
            mouse_pos, pressed = get_mouse()
            if pressed[0] and not self.click:
                event = None
                self.click = True
                for layer in self.objects:
                    for image in layer:
                        if image.check_click(mouse_pos, self.screen_pos):
                            event = image.event
                if event:
                    event.execute()
            elif not pressed[0]:
                self.click = False



        if not self.lock:
            physics_manager.loop()


        '''Show images'''
        if self.player and self.player.anim:
            self.screen_pos = self.player.anim.get_screen_pos()
        remove_image = []
        for i, layer in enumerate(self.objects):
            if i == 2:
                NetworkGamestate.loop(self, screen)
            for j, img in enumerate(layer):
                img.loop(screen, self.screen_pos)
                if img.remove:
                    remove_image.append(img)
        for r in remove_image:
            self.objects[i].remove(r)

        '''GUI'''
        GUI.loop(self, screen)

        '''Editor'''
        if CONST.debug:
            Editor.loop(self, screen, self.screen_pos)
Пример #11
0
    def __init__(self):
        self.y_size = 100
        self.loading_text = Text(Vector2(engine.get_screen_size().x/2, self.y_size/2),self.y_size,"data/font/pixel_arial.ttf","Loading",center=True,relative=True,color=(255,255,255))
        self.counter = 0
        self.anim_length = CONST.animation_step
        self.text_points = ""
        self.init_method = []

        if CONST.render == 'sfml':
            self.loading_thread = sfml.Thread(LoadingScreen.loading, self)
            self.loading_lock = sfml.Mutex()
            self.status = False
Пример #12
0
    def __init__(self):

        add_button('editor', 'LCTRL+e')
        self.editor_click = False

        self.editor = False
        self.text_size = 50

        self.mouse_clicked = (0, 0, 0)
        self.current_selected = None


        self.scale_clicked = (0, 0)  #red, enlarg

        self.save_clicked = False

        add_button('scale_y_down', ['DOWN'])
        add_button('scale_y_up', ['UP'])
        add_button('scale_x_down', ['LEFT'])
        add_button('scale_x_up', ['RIGHT'])

        add_button('angle_up',['a'])
        add_button('angle_down',['d'])

        add_button('save', ['LCTRL+s'])

        add_button('box',['LCTRL'])

        self.new_obj = None
        self.new_obj_pos = Vector2()


        self.obj_init_pos = Vector2()
        self.mouse_init_pos = Vector2()

        '''GUI'''
        self.gui_editor_mode = Text(Vector2(0, engine.get_screen_size().y-2*self.text_size), self.text_size, "data/font/pixel_arial.ttf", "Editor mode", relative=True)
        self.gui_current_selected = Text(Vector2(0, engine.get_screen_size().y-self.text_size), self.text_size, "data/font/pixel_arial.ttf", "",relative=True)
        self.gui_saved = Text(Vector2(0,0), self.text_size, "data/font/pixel_arial.ttf", "Saved",relative=True)
Пример #13
0
    def loop(self,screen):
        log("LOLOLO")
        if self.get_loading_state():
            switch_level(GameState(CONST.startup))
            return

        img_manager.draw_rect(engine.screen,Vector2(),Rect(Vector2(), engine.get_screen_size()),(255,255,255))
        self.counter = (self.counter + 1) % self.anim_length
        if self.counter == 0:
            self.text_points += "."
            if self.text_points == '....':
                self.text_points = ""
            self.loading_text.set_text("Loading"+self.text_points)
        self.loading_text.loop(screen,Vector2())
Пример #14
0
    def loop(self, screen):
        if self.anim:
            self.anim.update_animation()
            self.img = self.anim.img
            try:
                self.show = (self.anim.invincibility % (self.anim.show_frequency * 2)) < self.anim.show_frequency
            except AttributeError:
                pass
        pos = Vector2()
        if self.pos:
            pos = self.pos

        if self.screen_relative_pos is not None:
            pos = pos + self.screen_relative_pos * engine.get_screen_size()

        if self.screen_relative:
            pos = self.pos
        else:
            from engine import level_manager

            pos -= level_manager.level.screen_pos * Vector2(self.parallax_factor, 1.0)
            if pos.x > 160 or pos.x + self.size.x < 0:
                return

        center_image = False
        try:
            center_image = self.center_image
        except AttributeError:
            pass

        if self.show:
            img_manager.show_image(
                self.img, screen, pos, new_size=self.size, center_image=center_image, angle=self.angle, flip=self.flip
            )

        try:
            img_manager.show_image(
                self.anim.deal_with_it,
                screen,
                pos + self.anim.deal_pos + self.anim.deal_delta,
                new_size=Vector2(32, 32),
            )
        except AttributeError:
            pass
        GameObject.loop(self, screen)
Пример #15
0
 def loop(self,screen,screen_pos):
     pos = (0,0)
     if self.pos:
         pos = self.pos
     
     if self.screen_relative_pos is not None:
         pos = pos + self.screen_relative_pos*engine.get_screen_size()
     
     if self.screen_relative:
         pos = self.pos
     else:
         pos = pos-screen_pos
     if CONST.debug:
         self.update_rect()
         if not self.screen_relative:
             img_manager.draw_rect(screen, screen_pos, self.rect, (0,0,255,200), self.angle)
             if self.click_rect:
                 img_manager.draw_rect(screen,screen_pos,self.click_rect,(0,255,0,100))
Пример #16
0
 def init_dialog_text(self):
     self.dialog_text = Text(pos=engine.get_screen_size()*Vector2(self.dialog_margin,1-self.dialog_y_size+self.dialog_margin),
                             size=engine.get_screen_size()*Vector2(1-2*self.dialog_margin,self.dialog_y_size/2-1.5*self.dialog_margin).y,
                             font=self.dialog_font,
                             text="",
                             relative=True)
     self.dialog_text2 = Text(pos=engine.get_screen_size()*Vector2(self.dialog_margin,1-self.dialog_y_size/2+self.dialog_margin),
                              size=engine.get_screen_size()*Vector2(1-2*self.dialog_margin,self.dialog_y_size/2-1.5*self.dialog_margin).y,
                              font=self.dialog_font,
                              text="",
                              relative=True)
     self.dialog_box = Image(path=self.dialog_box_image,
                             pos=(engine.get_screen_size()*Vector2(0,1-self.dialog_y_size)).get_tuple(),
                             size=(engine.get_screen_size()*Vector2(1.0, self.dialog_y_size)).get_tuple(),
                             relative=True)
Пример #17
0
    def loop(self, screen):
        img_manager.draw_rect(screen, Vector2(), Rect(Vector2(0, 0), engine.get_screen_size()), (255, 255, 255))
        self.cat.loop(screen)
        self.ferret.loop(screen)
        if not self.dialog:
            snd_manager.set_playlist(["data/music/intro_BOSS1_gbjam.ogg","data/music/BOSS1_gbjam.ogg"])
            self.dialog = 1
            engine.show_dialog = True
            engine.textbox.set_text("Fury", "I'm coming for you, General Meow")
        if self.dialog == 1 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 3
                engine.textbox.set_text("General Meow", "I have a surprise for you, Fury")

        if self.dialog == 3 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                engine.show_dialog = False
                from levels.gamestate import GameState
                boss_level = GameState("data/json/boss_level.json")
                boss_level.last_checkpoint = self.last_checkpoint
                level_manager.switch_level(boss_level)
        snd_manager.update_music_status()
Пример #18
0
def update_event():
    """
    Update the states of Input Event
    """

    if CONST.render == 'sfml':
        from engine.init import engine
        window = engine.screen
        update_joy_event()
        for event in window.events:
            update_keyboard_event(event)
            
            if type(event) is sfml.CloseEvent:
                from engine.init import engine
                engine.finish = True
            elif type(event) is sfml.MouseButtonEvent:
                screen_ratio = float(engine.get_screen_size().y)/Vector2(engine.screen.size).y
                from levels.gamestate import GameState
                if get_level().__class__ == GameState:
                    log((Vector2(event.position)*screen_ratio+get_level().screen_pos).get_tuple())
            elif type(event) is sfml.ResizeEvent:
                new_size = event.size
    elif CONST.render == 'pookoo':
        update_keyboard_event()
Пример #19
0
    def update_state(self):
        lock = level_manager.level.lock
        RIGHT = input_manager.get_button('RIGHT')
        LEFT = input_manager.get_button('LEFT')
        UP = input_manager.get_button('UP')
        DOWN = input_manager.get_button('DOWN')
        A_BUTTON = input_manager.get_button('A')
        B_BUTTON = input_manager.get_button('B')
        if lock or self.life == 0:
            RIGHT = False
            LEFT = False
            UP = False
            DOWN = False
            A_BUTTON = False
            B_BUTTON = False


        
        horizontal = RIGHT-LEFT
        vertical = UP-DOWN
        
        physics_events = get_physics_event()
        
        for event in physics_events:
            #log("Physics collision: "+str(event.a.userData)+" "+str(event.b.userData)+" "+str(event.begin) +" "+str(physics_manager.get_body_position(self.obj.body).get_tuple()))
            if (event.a.userData == 2 and 15 >= event.b.userData >= 11 ) or \
                    ( event.b.userData == 2 and 15 >= event.a.userData >= 11):
                if event.begin:
                    self.foot += 1
                else:
                    self.foot -= 1
            elif (event.a.userData == 3 and event.b.userData == 11 ) or \
                    ( event.b.userData == 3  and event.a.userData == 11):
                if event.begin:
                    self.wall = 1
                else:
                    self.wall = 0

            elif (event.a.userData == 4 and event.b.userData == 11 ) or \
                    ( event.b.userData == 4  and event.a.userData == 11):
                if event.begin:
                    self.wall = 2
                else:
                    self.wall = 0
            elif (event.a.userData == 3 and event.b.userData == 12 ) or \
                    ( event.b.userData == 3  and 15 >= event.a.userData == 12):
                log("Physics: "+str(event.a.userData)+" "+str(event.b.userData))
                if event.begin:
                    self.not_sliding_wall = 1
                else:
                    self.not_sliding_wall = 0

            elif (event.a.userData == 4 and event.b.userData == 12 ) or \
                    ( event.b.userData == 4  and event.a.userData == 12):
                log("Physics: "+str(event.a.userData)+" "+str(event.b.userData))
                if event.begin:
                    self.not_sliding_wall = 2
                else:
                    self.not_sliding_wall = 0
            elif (event.a.userData == 1 and event.b.userData >= 20 and event.b.userData % 10 == 0) or \
                    ( event.b.userData == 1 and event.a.userData >= 20 and event.a.userData % 10 == 0):
                log("Touched by cat")
                if event.begin:
                    self.touched = True
                    self.cat_touched = True
                else:
                    self.touched = False
            elif (event.a.userData == 1 and event.b.userData >= 20 and event.b.userData %10 != 0) or \
                    ( event.b.userData == 1 and event.a.userData >= 20 and event.a.userData %10 != 0):
                log("Touched by bullet")
                if event.begin:
                    self.touched = True
                else:
                    self.touched = False
            if (event.a.userData == 1 and event.b.userData == 13 ) or \
                    ( event.b.userData == 1 and event.a.userData == 13):
                log("Touched by spike")
                if event.begin:
                    self.touched = True
                else:
                    self.touched = False





        if self.invincibility:
            self.invincibility -= 1

        if A_BUTTON and ((self.foot and self.jump_step) or (not self.foot and self.jump_step and self.wall)):
            if self.wall == 1:
                #going RIGHT because LEFT wall
                physics_manager.move(self.player.body, vx=self.speed)
                self.wall_jump_step = CONST.wall_jump

            elif self.wall == 2:
                physics_manager.move(self.player.body, vx=-self.speed)
                self.wall_jump_step = CONST.wall_jump
            physics_manager.jump(self.player.body)
            snd_manager.play_sound(self.jump_sound)
            self.jump_step -= 1
        elif not self.foot and not self.wall :
            self.jump_step = 0
        elif (self.foot or (not self.foot and self.wall)) and not A_BUTTON:
            self.jump_step = CONST.jump_step



        if horizontal == -1:
            #LEFT
            self.direction = False
            if self.foot:
                self.state = 'move'
            self.player.flip = True

            move_condition = self.wall != 1 and self.wall_jump_step == 0 and self.not_sliding_wall != 1
            if get_value('boss_limit') is not None:
                move_condition = move_condition and (self.player.pos + \
                                                    self.player.screen_relative_pos * \
                                                    engine.screen_size).x > get_value('boss_limit')[0]
            if move_condition:
                physics_manager.move(self.player.body, -self.speed)
        elif horizontal == 1:
            #RIGHT
            self.direction = True
            if self.foot:
                self.state = 'move'
            self.player.flip = False

            move_condition = self.wall != 2 and self.wall_jump_step == 0 and self.not_sliding_wall != 2
            if get_value('boss_limit') is not None:
                move_condition = move_condition and (self.player.pos + \
                                                    self.player.screen_relative_pos * \
                                                    engine.screen_size ).x < get_value('boss_limit')[1]
            if move_condition:
                physics_manager.move(self.player.body, self.speed)
        else:
            if self.foot:
                if self.direction:
                    self.state = 'still'
                    self.player.flip = False
                else:
                    self.state = 'still'
                    self.player.flip = True
            if self.wall_jump_step == 0:
                physics_manager.move(self.player.body, 0)

        if not self.foot:
            if self.direction:
                self.state = 'jump'
                self.player.flip = False
            else:
                self.state = 'jump'
                self.player.flip = True



        #"gravity" effect like nes game
        velocity = physics_manager.get_body_velocity(self.player.body)
        delta = self.gravity
        if self.wall and self.wall_jump_step == 0:
            velocity.y = self.wall_speed
            self.state = 'slide'
            if self.direction:
                self.player.flip = False
            else:
                self.player.flip = True
        elif self.foot:
            pass
        else:
            velocity.y += delta
        physics_manager.set_body_velocity(self.player.body, velocity)

        physics_pos = physics_manager.get_body_position(self.player.body)
        
        if physics_pos:
            pos = physics_pos-self.player.size/2
        else:
            pos = self.player.pos
        if self.player.screen_relative_pos:
            pos = pos-self.player.screen_relative_pos*engine.get_screen_size()
        self.player.pos = pos

        self.set_screen_pos()

        if self.wall_jump_step != 0:
            self.wall_jump_step -= 1

        for i in range(self.life):
            img_manager.show_image(self.heart,img_manager.buffer,pos=Vector2(i*18,0),new_size=Vector2(16,16))

        if self.move_deal:
            if self.deal_delta.y < 0:
                self.deal_delta = Vector2(0,self.deal_delta.y+1)
            elif self.dialog == 0:
                self.deal_delta = Vector2()
                if engine.textbox.finished:
                    if input_manager.get_button('A') or input_manager.get_button('B'):
                        snd_manager.set_playlist(["data/music/menu_gbjam.ogg"])
                        self.dialog = -1
                        engine.textbox.set_text("Furbrawl", "A game by Team KwaKwa")

            if not self.direction:
                self.deal_delta = Vector2(-20,self.deal_delta.y)
            else:
                self.deal_delta = Vector2(0, self.deal_delta.y)

        if self.dialog == -1 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 1
                engine.textbox.set_text("Lead designer", "Elias Farhan")
        if self.dialog == 1 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 2
                engine.textbox.set_text("Programmer", """Hamza "Tenchi" Haiken""")
        if self.dialog == 2 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 3
                engine.textbox.set_text("Artist", """Josh Grilli""")
        if self.dialog == 3 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 4
                engine.textbox.set_text("Artist", """Austin Lewis""")
        if self.dialog == 4 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 5
                engine.textbox.set_text("Music", """Dorian SRed""")
        if self.dialog == 5 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                self.dialog = 6
                engine.textbox.set_text("THANKS", """For playing the game""")
        if self.dialog == 6 and engine.textbox.finished:
            if input_manager.get_button('A') or input_manager.get_button('B'):
                engine.show_dialog = False
                from levels.logo_kwakwa import Kwakwa
                level_manager.switch_level(Kwakwa())
        if self.touched and not self.invincibility and self.life > 0:
            self.life -= 1
            self.invincibility = CONST.invincibility
            self.anim_counter = self.anim_freq-1

            if self.life == 0:
                level_manager.level.game_over = True
                self.invincibility = 1000
            if self.cat_touched:
                self.touched = False
                self.cat_touched = False
        if self.invincibility > CONST.invincibility - 20 or level_manager.level.game_over:
            self.state = 'hit'

        if self.invincibility %20 > 10:
            self.player.show = False
        else:
            self.player.show = True

        if B_BUTTON and self.attacking == 0:
            self.state = 'attack'
            self.attacking = self.attack_time
        if self.attacking > 1:
            self.state = 'attack'
            self.attacking -= 1
            self.slash.update_animation(state='slash')
            slash_pos = Vector2()
            if self.direction:
                slash_pos = self.player.pos + engine.screen_size * self.player.screen_relative_pos + Vector2(self.player.size.x/1.5,0)
            else:
                slash_pos = self.player.pos + engine.screen_size * self.player.screen_relative_pos - Vector2(self.player.size.x/1.5,0)
            img_manager.show_image(self.slash.img, engine.screen, pos=slash_pos-level_manager.level.screen_pos,new_size=Vector2(36,36),flip=not self.direction)
        elif not B_BUTTON:
            self.attacking = 0
        if ( self.player.pos + engine.screen_size * self.player.screen_relative_pos ).x > 2500:
            from levels.dialog import Dialog
            boss_level = Dialog()
            boss_level.last_checkpoint = level_manager.level.last_checkpoint
            level_manager.switch_level(boss_level)
Пример #20
0
def load_physic_objects(physics_data,image):
    if image is None:
        return
    body_type = get_element(physics_data, "type")
    if body_type:
        pos = Vector2()
        if image.pos:
            pos = image.pos
        if image.screen_relative_pos:
            pos = pos+image.screen_relative_pos*engine.get_screen_size()
        if image.size:
            pos = pos+image.size/2
        if body_type == "dynamic":
            image.body = physics_manager.add_body(pos, BodyType.dynamic)
        elif body_type == "static":
            image.body = physics_manager.add_body(pos, BodyType.static)
        elif body_type == 'kinematic':
            image.body = physics_manager.add_body(pos, BodyType.kinematic)
    pos = (0,0)
    if image.pos:
        pos = image.pos
    if image.screen_relative_pos:
        pos = pos+image.screen_relative_pos*engine.get_screen_size()+image.size/2
    angle = get_element(physics_data, "angle")
    if angle:
        image.body.angle = angle*math.pi/180
    else:
        if image.body and image.angle != 0:
            if CONST.physics == 'b2':
                image.body.angle = image.angle*math.pi/180
            elif CONST.physics == 'pookoo':
                #TODO: set angle for body
                pass
            '''Set new pos for body'''
            v = image.size/2
            v.rotate(image.angle)
            pos = image.pos+v
            pos = pixel2meter(pos)
            if CONST.physics == 'b2':
                image.body.position = pos.get_tuple()
            elif CONST.physics == 'pookoo':
                #TODO: set pos for body
                pass
            
    fixtures_data = get_element(physics_data,"fixtures")
    if fixtures_data:
        for physic_object in fixtures_data:
            sensor = get_element(physic_object, "sensor")
            if sensor is None:
                sensor = False
            user_data = get_element(physic_object,"user_data")
            if user_data is None:
                user_data = image
            obj_type = get_element(physic_object, "type")
            if obj_type == "box":
                pos = get_element(physic_object,"pos")
                if not pos:
                    pos = Vector2()

                size = get_element(physic_object,"size")
                if not size:
                    size = image.size/2

                angle = get_element(physic_object,"angle")
                if angle is None:
                    
                    angle = 0
                image.fixtures.append(physics_manager.add_box(image.body, Vector2(pos), Vector2(size), angle, user_data, sensor))
            elif obj_type == "circle":
                pos = get_element(physic_object,"pos")
                if not pos:
                    pos = (0,0)
                radius = get_element(physic_object,"radius")
                if not radius:
                    radius = 1

                image.fixtures.append(physics_manager.add_circle(image.body,pos,radius,sensor,user_data))