コード例 #1
0
ファイル: character.py プロジェクト: BuriJuri/pygame_dev
    def update(self):

        #-- MOVEMENT ------------------------------------------------------------------------------#

        # SELF ACCELERATION
        accel = [0, 0]
        if self.keydown['UP'] == True:
            accel[1] -= self.b_stat.acc
        if self.keydown['LEFT'] == True:
            accel[0] -= self.b_stat.acc
        if self.keydown['DOWN'] == True:
            accel[1] += self.b_stat.acc
        if self.keydown['RIGHT'] == True:
            accel[0] += self.b_stat.acc

        #   RESTRICTION DUE TO DISORDER
        if self.controlled['stunned'] > 0:
            accel = [0, 0]
            self.controlled['stunned'] -= 1

        if self.controlled['airborne'] > 0:
            accel = [0, 0]
            self.controlled['airborne'] -= 1

        if self.controlled['exhaust'] > 0:
            if abs(accel[0]) < 1:
                accel[0] = 0
            else:
                accel[0] = int(accel[0] / abs(accel[0]) * (abs(accel[0]) - 2))
            if abs(accel[1]) < 1:
                accel[1] = 0
            else:
                accel[1] = int(accel[1] / abs(accel[1]) * (abs(accel[1]) - 2))
            self.controlled['exhaust'] -= 1

        #   NORMAL PROSSESS
        if (-1) * self.b_stat.max_speed <= self.speed[0] + accel[
                0] and self.speed[0] + accel[0] <= self.b_stat.max_speed:
            self.speed[0] += accel[0]
        elif self.speed[0] + accel[0] > self.b_stat.max_speed and self.speed[
                0] < self.b_stat.max_speed:
            self.speed[0] = self.b_stat.max_speed
        elif self.speed[0] + accel[0] < (
                -1) * self.b_stat.max_speed and self.speed[0] > (
                    -1) * self.b_stat.max_speed:
            self.speed[0] = (-1) * self.b_stat.max_speed

        if (-1) * self.b_stat.max_speed <= self.speed[1] + accel[
                1] and self.speed[1] + accel[1] <= self.b_stat.max_speed:
            self.speed[1] += accel[1]
        elif self.speed[1] + accel[1] > self.b_stat.max_speed and self.speed[
                1] < self.b_stat.max_speed:
            self.speed[1] = self.b_stat.max_speed
        elif self.speed[1] + accel[1] < (
                -1) * self.b_stat.max_speed and self.speed[1] > (
                    -1) * self.b_stat.max_speed:
            self.speed[1] = (-1) * self.b_stat.max_speed

        # GRAVITY
        self.speed[0] += envi.gravity[0]
        self.speed[1] += envi.gravity[1]

        # EXTERNAL ACCELERATION
        for a in self.acc_ext:
            self.speed[0] += a[0][0]
            self.speed[1] += a[0][1]
            a[1] -= 1
            if a[1] == 0:
                self.acc_ext.remove(a)

        # POSITION UPDATE
        #   RESTRICTION DUE TO DISORDER
        if self.controlled['rooted'] > 0:
            self.speed = [0, 0]
            self.controlled['rooted'] -= 1
        #   NORMAL PROCESS
        for i in range(numpy.abs(self.speed[0])):
            if self.speed[0] > 0:
                self.pos[0] += 1
            else:
                self.pos[0] -= 1
            self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                    self.ph_stat.width, self.ph_stat.height)

            # CHECK AVAILABILITY HERE
            collide = False
            for g in entity.wall_whole:
                if self.poly.colliderect(g.poly) == True:
                    collide = True
            if collide == True:
                if self.speed[0] > 0:
                    self.pos[0] -= 1
                else:
                    self.pos[0] += 1
                self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                        self.ph_stat.width,
                                        self.ph_stat.height)
                break

        for i in range(numpy.abs(self.speed[1])):
            if self.speed[1] > 0:
                self.pos[1] += 1
            else:
                self.pos[1] -= 1
            self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                    self.ph_stat.width, self.ph_stat.height)

            # CHECK AVAILABILITY HERE
            collide = False
            for g in entity.wall_whole:
                if self.poly.colliderect(g.poly) == True:
                    collide = True
            if collide == True:
                if self.speed[1] > 0:
                    self.pos[1] -= 1
                else:
                    self.pos[1] += 1
                self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                        self.ph_stat.width,
                                        self.ph_stat.height)
                break

        # AIR DRAG FORCE
        self.speed[0] = int(self.speed[0] * (1 - self.ph_stat.air_drag))
        self.speed[1] = int(self.speed[1] * (1 - self.ph_stat.air_drag))

        #-- \MOVEMENT ------------------------------------------------------------------------------#

        #-- HARMS ------------------------------------------------------------------------------#

        # DISORDERS
        if self.disorder_tick['poisoned'] > 0:
            self.damaged(
                attack.damage(self.disorder_amount['poisoned'], attack.POISON))
            self.disorder_tick['poisoned'] -= 1
        else:
            self.disorder_amount['poisoned'] = 0
        if self.disorder_tick['burning'] > 0:
            self.damaged(
                attack.damage(self.disorder_amount['burning'], attack.FIRE))
            self.disorder_tick['burning'] -= 1
        else:
            self.disorder_amount['burning'] = 0
        # HARMS
        for h in self.harms:
            self.hp -= h.amount
            self.harms.remove(h)
        if self.hp <= 0:
            self.dead()
コード例 #2
0
#-- MAPS FOR USE ------------------------------------------------------------------------------#
maps = {}

# TEST MAP (test_map)
test_map = mapping.mapping((40, 24))
test_map_chars = []
temp = ch.character("HEOSU", (600, 300), player_bstat, player_phstat)
temp.set_map(test_map)
test_map_chars.append(temp)

test_map.map_setting(mapping.map_temp, {'start': (50, 300)}, test_map_chars)
test_map.background_setting(pygame.image.load("img/map/test_map_bg.png"))
test_map.add_block(
    entity.eventblock(
        test_map, (5, 5), entity.PLAYER_COLLIDE,
        lambda: test_map.player.harms.append(attack.damage(5, False))))
test_map.add_block(
    entity.eventblock(test_map, (10, 5), entity.PLAYER_COLLIDE,
                      lambda: test_map.player.set_acc((3, 3), 10)))
test_map.add_block(
    entity.eventblock(test_map, (15, 5), entity.PLAYER_COLLIDE,
                      lambda: test_map.player.set_controlled('stunned', 30)))
test_map.add_block(
    entity.eventblock(test_map, (20, 5), entity.PLAYER_COLLIDE,
                      lambda: test_map.player.set_controlled('exhaust', 30)))
test_map.add_block(
    entity.eventblock(test_map, (25, 5), entity.PLAYER_COLLIDE,
                      lambda: test_map.player.set_controlled('airborne', 10)))
test_map.add_block(
    entity.eventblock(test_map, (30, 5), entity.PLAYER_COLLIDE,
                      lambda: test_map.player.set_disorder('poisoned', 30, 1)))
コード例 #3
0
ファイル: character.py プロジェクト: ckswjd99/pygame_dev
    def update(self):

        #-- CENTER FOLLOWING COORD ------------------------------------------------------------------------------#
        following_constant = 1
        self.center_following_coord[0] -= (
            self.center_following_coord[0] -
            self.get_center()[0]) / following_constant
        self.center_following_coord[1] -= (
            self.center_following_coord[1] -
            self.get_center()[1]) / following_constant
        #-- \CENTER FOLLOWING COORD ------------------------------------------------------------------------------#

        #-- FACE ------------------------------------------------------------------------------#
        if self.keydown['UP'] == True and self.keydown[
                'LEFT'] == False and self.keydown[
                    'DOWN'] == False and self.keydown['RIGHT'] == False:
            self.face = 1.5
        elif self.keydown['UP'] == False and self.keydown[
                'LEFT'] == True and self.keydown[
                    'DOWN'] == False and self.keydown['RIGHT'] == False:
            self.face = 1
        elif self.keydown['UP'] == False and self.keydown[
                'LEFT'] == False and self.keydown[
                    'DOWN'] == True and self.keydown['RIGHT'] == False:
            self.face = 0.5
        elif self.keydown['UP'] == False and self.keydown[
                'LEFT'] == False and self.keydown[
                    'DOWN'] == False and self.keydown['RIGHT'] == True:
            self.face = 0

        #-- FACE ------------------------------------------------------------------------------#

        #-- MOVEMENT ------------------------------------------------------------------------------#

        # SELF ACCELERATION
        accel = [0, 0]
        if self.keydown['UP'] == True:
            accel[1] -= self.b_stat.acc
        if self.keydown['LEFT'] == True:
            accel[0] -= self.b_stat.acc
        if self.keydown['DOWN'] == True:
            accel[1] += self.b_stat.acc
        if self.keydown['RIGHT'] == True:
            accel[0] += self.b_stat.acc

        #   RESTRICTION DUE TO DISORDER
        if self.controlled['stunned'] > 0:
            accel = [0, 0]
            self.controlled['stunned'] -= 1

        if self.controlled['airborne'] > 0:
            accel = [0, 0]
            self.controlled['airborne'] -= 1

        if self.controlled['exhaust'] > 0:
            if abs(accel[0]) < 1:
                accel[0] = 0
            else:
                accel[0] = int(accel[0] / abs(accel[0]) * (abs(accel[0]) - 2))
            if abs(accel[1]) < 1:
                accel[1] = 0
            else:
                accel[1] = int(accel[1] / abs(accel[1]) * (abs(accel[1]) - 2))
            self.controlled['exhaust'] -= 1

        #   NORMAL PROSSESS
        if (-1) * self.b_stat.max_speed <= self.speed[0] + accel[
                0] and self.speed[0] + accel[0] <= self.b_stat.max_speed:
            self.speed[0] += accel[0]
        elif self.speed[0] + accel[0] > self.b_stat.max_speed and self.speed[
                0] < self.b_stat.max_speed:
            self.speed[0] = self.b_stat.max_speed
        elif self.speed[0] + accel[0] < (
                -1) * self.b_stat.max_speed and self.speed[0] > (
                    -1) * self.b_stat.max_speed:
            self.speed[0] = (-1) * self.b_stat.max_speed

        if (-1) * self.b_stat.max_speed <= self.speed[1] + accel[
                1] and self.speed[1] + accel[1] <= self.b_stat.max_speed:
            self.speed[1] += accel[1]
        elif self.speed[1] + accel[1] > self.b_stat.max_speed and self.speed[
                1] < self.b_stat.max_speed:
            self.speed[1] = self.b_stat.max_speed
        elif self.speed[1] + accel[1] < (
                -1) * self.b_stat.max_speed and self.speed[1] > (
                    -1) * self.b_stat.max_speed:
            self.speed[1] = (-1) * self.b_stat.max_speed

        # GRAVITY
        self.speed[0] += envi.gravity[0]
        self.speed[1] += envi.gravity[1]

        # EXTERNAL ACCELERATION
        for a in self.acc_ext:
            self.speed[0] += a[0][0]
            self.speed[1] += a[0][1]
            a[1] -= 1
            if a[1] == 0:
                self.acc_ext.remove(a)

        # POSITION UPDATE
        #   RESTRICTION DUE TO DISORDER
        if self.controlled['rooted'] > 0:
            self.speed = [0, 0]
            self.controlled['rooted'] -= 1
        #   NORMAL PROCESS
        for i in range(numpy.abs(self.speed[0])):
            if self.speed[0] > 0:
                self.pos[0] += 1
            else:
                self.pos[0] -= 1
            self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                    self.ph_stat.width, self.ph_stat.height)

            # CHECK AVAILABILITY HERE
            collide = False
            for g in self.map.blocks:
                if self.poly.colliderect(
                        g.poly) == True and g.collision_character == True:
                    collide = True
            if collide == True:
                if self.speed[0] > 0:
                    self.pos[0] -= 1
                else:
                    self.pos[0] += 1
                self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                        self.ph_stat.width,
                                        self.ph_stat.height)
                break

        for i in range(numpy.abs(self.speed[1])):
            if self.speed[1] > 0:
                self.pos[1] += 1
            else:
                self.pos[1] -= 1
            self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                    self.ph_stat.width, self.ph_stat.height)

            # CHECK AVAILABILITY HERE
            collide = False
            for g in self.map.blocks:
                if self.poly.colliderect(
                        g.poly) == True and g.collision_character == True:
                    collide = True
            if collide == True:
                if self.speed[1] > 0:
                    self.pos[1] -= 1
                else:
                    self.pos[1] += 1
                self.poly = pygame.Rect(self.pos[0], self.pos[1],
                                        self.ph_stat.width,
                                        self.ph_stat.height)
                break

        # AIR DRAG FORCE
        #   RESTRICTION DUE TO CHARGE
        if self.charge > 10:
            self.ph_stat.air_drag += 0.3
        self.speed[0] = int(self.speed[0] * (1 - self.ph_stat.air_drag))
        self.speed[1] = int(self.speed[1] * (1 - self.ph_stat.air_drag))
        if self.charge > 10:
            self.ph_stat.air_drag -= 0.3

        #-- \MOVEMENT ------------------------------------------------------------------------------#

        #-- ACT ------------------------------------------------------------------------------#
        is_pushed = False
        if self.action_key == "MOUSE_LEFT":
            is_pushed = self.mousedown['LEFT']
        elif self.action_key == "MOUSE_RIGHT":
            is_pushed = self.mousedown['RIGHT']

        if self.action == None:  # if action is empty, check if new action is added
            if self.mousedown['LEFT'] == True:
                self.action_key = "MOUSE_LEFT"
                self.action = self.slot_mouse[0].copy()
            if self.mousedown['RIGHT'] == True:
                self.action_key = "MOUSE_RIGHT"
                self.action = self.slot_mouse[1].copy()
        else:  # there is already action processed
            self.action.set_is_pushed(is_pushed)
            if is_pushed == True:  #   controller is still pushing perform key
                if self.charge < 100:
                    self.charge += 1
            else:  #   controller is not still pushing perform key
                self.action_key = None
                self.charge = 0
            self.action.update()
        #-- \ACT ------------------------------------------------------------------------------#

        #-- HARMS ------------------------------------------------------------------------------#

        # DISORDERS
        if self.disorder_tick['poisoned'] > 0:
            self.damaged(
                attack.damage(self.disorder_amount['poisoned'], attack.POISON))
            self.disorder_tick['poisoned'] -= 1
        else:
            self.disorder_amount['poisoned'] = 0
        if self.disorder_tick['burning'] > 0:
            self.damaged(
                attack.damage(self.disorder_amount['burning'], attack.FIRE))
            self.disorder_tick['burning'] -= 1
        else:
            self.disorder_amount['burning'] = 0
        # HARMS
        for h in self.harms:
            self.hp -= h.amount
            self.harms.remove(h)
        if self.hp <= 0:
            self.dead()
コード例 #4
0
ファイル: mapping.py プロジェクト: ckswjd99/pygame_dev
            screen.blit(self.effect_screen, (0, 0))
            self.transition_tick += 1


#-- TEST BENCH ------------------------------------------------------------------------------#

if __name__ == "__main__":

    map_now = mapping(player, (40, 24))
    map_now.map_setting(map_temp, {'start': (50, 300)})
    map_now.background_setting(pygame.image.load("img/background.png"))
    map_now.start(player, map_now.spawn_list['start'])
    map_now.add_block(
        entity.eventblock(
            map_now, (5, 5), entity.PLAYER_COLLIDE,
            lambda: map_now.player.harms.append(attack.damage(5, False))))
    map_now.add_block(
        entity.eventblock(map_now, (10, 5), entity.PLAYER_COLLIDE,
                          lambda: map_now.player.set_acc((3, 3), 10)))
    map_now.add_block(
        entity.eventblock(
            map_now, (15, 5), entity.PLAYER_COLLIDE,
            lambda: map_now.player.set_controlled('stunned', 30)))
    map_now.add_block(
        entity.eventblock(
            map_now, (20, 5), entity.PLAYER_COLLIDE,
            lambda: map_now.player.set_controlled('exhaust', 30)))
    map_now.add_block(
        entity.eventblock(
            map_now, (25, 5), entity.PLAYER_COLLIDE,
            lambda: map_now.player.set_controlled('airborne', 10)))