Exemplo n.º 1
0
 def physic(self):
     if self.is_active:
         enemy = game_object.collide_with(self.box_collider, Enemy)
         player = game_object.collide_with(self.box_collider, Player)
         if enemy is not None:
             enemy.deactivate()
         if player is not None:
             # player.image = pygame.image.load("./images/enemy/virrut.png")
             pass
Exemplo n.º 2
0
    def physic(self):
        # if self.is_active:
        player = game_object.collide_with(self.box_collider, Player)
        dog = game_object.collide_with(self.box_collider, Dog)
        if player is not None and player.dog_count > 0:
            print(player.dog_count)
            player.dog_count = 0

        if dog is not None and dog.is_active:
            print('hit')
            dog.deactivate()
Exemplo n.º 3
0
    def deactivate_if_need(self):
        collided_with1 = game_object.collide_with(self.box_collider, SpikeLeft)
        if len(collided_with1) > 0:
            self.deactivate()
        if self.y > 700:
            self.deactivate()

        collided_with2 = game_object.collide_with(self.box_collider, SpikeRight)
        if len(collided_with2) > 0:
            self.deactivate()

        collided_with3 = game_object.collide_with(self.box_collider, Carrot)
        if len(collided_with3) > 0:
            self.deactivate()
Exemplo n.º 4
0
    def physics(self):
        if self.is_active:
            dog = game_object.collide_with(self.box_collider, Dog)
            if dog is not None:
                # self.deactivate()
                # dog.deactivate()
                self.returning = True
                dog.returning = True
                dog.stun_timer.reset()

            enemy = game_object.collide_with(self.box_collider, Enemy)
            if enemy is not None:
                self.returning = True
                enemy.returning = True
Exemplo n.º 5
0
    def check_future_y(self):
        future_box = BoxCollider(60, 110)
        future_box.x = self.x
        future_box.y = self.y
        # future_box.x += self.dx
        future_box.y += self.dy

        collided_list = game_object.collide_with(future_box, Platform)
        for obj in collided_list:
            if type(obj) == Platform:
                move_continue = True
                distance = 1
                # while move_continue:
                #     box = self.box_collider
                #     box.y += distance
                #     collided_list2 = game_object.collide_with(box, Platform)
                #     for obj in collided_list2:
                #         if type(obj) == Platform:
                #             move_continue = False
                #         else:
                #             distance += 1
                #             self.y += numpy.sign(self.dy)
                self.dy = 0
        if self.y > 630:
            self.dy += 10
        self.y += self.dy
Exemplo n.º 6
0
    def update_animator(self):
        self.renderer.update(self.dx,self.dy)

        collide_list2 = collide_with(self.box_collider, Items)
        for obj in collide_list2:
            obj.deactivate()
            game_object.score += 10

        game_object.score += 1
Exemplo n.º 7
0
 def update(self):
     GameObject.update(self)
     collide_list = collide_with(self.box_collider)
     for game_object in collide_list:
         if type(game_object) == Enemy:
             game_object.deactivate()
             self.deactivate()
     self.move()
     self.deactivate_if_needed()
Exemplo n.º 8
0
    def physics(self):
        if self.is_active:

            dog = game_object.collide_with(self.box_collider, Dog)
            if dog is not None:
                # self.deactivate()
                # dog.deactivate()
                distance1 = get_distance((self.x, self.y), (dog.x, dog.y))
                dog.velocity = ((dog.x - self.x) / distance1 *
                                10, (dog.y - self.y) / distance1 * 10)
                dog.stun_timer.reset()
                dog.returning = False

            enemy = game_object.collide_with(self.box_collider, Enemy)
            if enemy is not None:
                distance2 = get_distance((self.x, self.y), (enemy.x, enemy.y))
                enemy.velocity = ((enemy.x - self.x) / distance2 * 20,
                                  (enemy.y - self.y) / distance2 * 20)
                enemy.stun_timer.reset()
                enemy.returning = False
Exemplo n.º 9
0
    def update(self):
        GameObject.update(self)

        collide_list = collide_with(self.box_collider, Enemy)
        for game_object in collide_list:
            explosion = EnemyExplosion(game_object.x, game_object.y)
            add_game_object(explosion)
            game_object.deactivate()
            self.deactivate()

        self.move()
        self.deactivate_if_needed()
Exemplo n.º 10
0
    def check_future_x(self):
        future_box = BoxCollider(60, 110)
        future_box.x = self.x
        future_box.y = self.y

        # future_box.x += self.dx
        future_box.x += self.dx

        collided_list = game_object.collide_with(future_box, Platform)
        for obj in collided_list:
            if type(obj) == Platform:
                # print('hello')
                self.dx = 0

        self.x += self.dx
Exemplo n.º 11
0
    def move(self):
        self.dx = 0
        # self.dy = 0
        if global_input_manager.right_pressed:
            self.dx += 4
        if global_input_manager.left_pressed:
            self.dx -= 4
        if global_input_manager.up_pressed:
            box_at_bottom = self.box_collider
            box_at_bottom.y = self.box_collider.y + 2
            btm = game_object.collide_with(box_at_bottom, Platform)
            for obj in btm:
                if type(obj) == Platform:
                    self.dy = self.jump_speed

        self.dy += 0.98

        self.check_future_y()
        self.check_future_x()
Exemplo n.º 12
0
 def physics(self):
     enemy = game_object.collide_with(self.box_collider, Enemy)
     if enemy is not None:
         enemy.deactivate()
         self.deactivate()
Exemplo n.º 13
0
    def update(self):
        if self.box_collider is not None:
            self.box_collider.x = self.x
            self.box_collider.y = self.y

        if self.input_manager.right_pressed:
            self.x += 2
        elif self.input_manager.left_pressed:
            self.x -= 2

        if not self.isJump:
            if self.input_manager.x_pressed:
                self.isJump = True
        else:
            if self.jumpCount >= -5:
                neg = 1
                if self.jumpCount < 0:
                    neg = -1
                self.y -= self.jumpCount**2 * 0.8 * neg
                if neg == 1:
                    if len(game_object.collide_with(self.box_collider,
                                                    Grass)) != 0:
                        self.jumpCount *= -1

                elif neg == -1:
                    if len(game_object.collide_with(self.box_collider,
                                                    Grass)) != 0:
                        list_collide = game_object.collide_with(
                            self.box_collider, Grass)
                        for object in list_collide:
                            dy = object.y - 32
                            if object.y < self.y:
                                continue
                            if dy <= self.y:
                                self.y = dy
                        self.jumpCount = -5
                self.jumpCount -= 1
            else:
                self.isJump = False
                self.jumpCount = 5

        if not self.isJump:
            if len(game_object.collide_with(self.box_collider, Grass)) != 0:
                list_collide = game_object.collide_with(
                    self.box_collider, Grass)
                for object in list_collide:

                    if self.box_collider.y == object.y:
                        if self.x >= object.x:
                            self.x += 1
                        elif self.x < object.x:
                            self.x -= 1
                        pass
                    else:
                        self.move = True
                        dy = object.y - 32
                        if dy <= self.y:
                            self.y = dy

            elif len(game_object.collide_with(self.box_collider, Spike)) != 0:
                self.is_active = False
            elif len(game_object.collide_with(self.box_collider,
                                              SpikeFake)) != 0:
                list_object = game_object.collide_with(self.box_collider,
                                                       SpikeFake)
                for obj in list_object:
                    obj.renderer = ImageRenderer(
                        'assets/images/sprite/spike0000.png')
                self.count += 1
                if self.count >= 30:
                    self.is_active = False
                    self.count = 0

            else:
                for object in game_object.game_objects:
                    if (object.x <= self.x <= object.x + 32
                            or object.x <= self.x + self.width <= object.x + 32
                        ) and self.y < object.y:
                        if self.x + 32 == object.x:
                            continue
                        else:
                            self.y = object.y - 32

                            break
Exemplo n.º 14
0
 def physics(self):
     if self.is_active:
         shot1 = game_object.collide_with(self.box_collider, Shot1)
         if shot1 is not None and shot1.returning:
             self.has_shoot1 = True
             shot1.deactivate()