Ejemplo n.º 1
0
 def image(self, main, player=None, GV=None):
     pygame.draw.circle(main, (200, 200, 0), [
         int(self.elem.center.coord["x"]),
         int(self.elem.center.coord["y"] + GV.size * 3 / 5)
     ], int(GV.size / 5), 3)
     pygame.draw.polygon(main, (200, 200, 0), self.point_list, 3)
     a, b = collision(player.elem.points_list, self.elem.points_list)
     if a and b:
         GV.Clavier_Led.display_string(self.text)
         return True
Ejemplo n.º 2
0
 def chase(self, posOfObject):
     self.pos = self.canvas.coords(self.id)
     deltaX = posOfObject[0]-(self.pos[0]+self.pos[2])*0.5
     deltaY = posOfObject[1]-(self.pos[1]+self.pos[3])*0.5
     deltaTotal = abs(deltaX) + abs(deltaY)
     if deltaTotal!=0:
         self.momentum = int(self.velocity * (deltaX/deltaTotal) )
         self.y = int(self.velocity * (deltaY/deltaTotal) )
         self.momentum, self.y=physics.collision(self.pos, self.momentum, self.y)
         self.canvas.move(self.id, self.momentum, self.y)
Ejemplo n.º 3
0
    def image(self, main, player=None, GV=None):
        x = self.elem.center.coord["x"]
        y = self.elem.center.coord["y"]
        pygame.draw.circle(main, (0, 0, 0), [int(x), int(y)], 5)

        x += self.elem.center.speed["x"] * GV.timeSpeed
        y += self.elem.center.speed["y"] * GV.timeSpeed
        if (x < 0 or x > 1980 or y < 0 or y > 1080):
            return True
        a, b = collision(player.elem.points_list, self.elem.points_list)
        if (a and b):
            player.health -= 2
            if (player.health <= 0):
                player.isAlive = False
            return True
        for i in GV.elem_list:
            a, b = collision(i.points_list, self.elem.points_list)
            if a and b:
                return True
        self.elem.center.coord["x"] = x
        self.elem.points_list[0]["x"] = x
        self.elem.center.coord["y"] = y
        self.elem.points_list[0]["y"] = y
        return False
Ejemplo n.º 4
0
    def physics(self):
        self.pos = self.canvas.coords(self.id[0])
        self.gravity()
        self.motion()
        #collision
        self.momentum, self.y=physics.collider(self.pos, self.static, self.momentum, self.y)

        #calculates player velocity
        self.decceleration()
        self.motion()
        #Placed at the end of the of the function to stop it going through walls
        self.momentum, self.y=physics.collision(self.pos, self.momentum, self.y)
        #moves the player.
        #print(self.momentum)
        self.canvas.move(self.id[0], int(self.momentum), int(self.y) )
        self.canvas.move(self.id[1], int(self.momentum), int(self.y) )
        self.canvas.move(self.id[2], int(self.momentum), int(self.y) )
        self.canvas.move(self.id[3], int(self.momentum), int(self.y) )
Ejemplo n.º 5
0
 def image(self, main, player=None, GV=None):
     pygame.draw.circle(main, (0, 0, 200), [
         int(self.elem.center.coord["x"]),
         int(self.elem.center.coord["y"])
     ], int(self.size / 2), 5)
     pygame.draw.line(main, (0, 0, 200), [
         self.elem.center.coord["x"],
         self.elem.center.coord["y"] - self.size / 2 * 4 / 5
     ], [self.elem.center.coord["x"], self.elem.center.coord["y"]], 3)
     pygame.draw.line(
         main, (0, 0, 200),
         [self.elem.center.coord["x"], self.elem.center.coord["y"]], [
             self.elem.center.coord["x"] +
             math.sin(math.pi / 4) * self.size * 3 / 10,
             self.elem.center.coord["y"] -
             math.sin(math.pi / 4) * self.size * 3 / 10
         ], 4)
     a, b = collision(player.elem.points_list, self.elem.points_list)
     if a and b:
         player.energy = 1
Ejemplo n.º 6
0
def scenario_stats(s):
    stats = {}
    # print(s.name)
    observed_path = s.path
    pucks = s.pucks
    surfaces = s.surfaces

    collision_times = {}
    collision_velocities = {}
    pre_post_collision = {}

    # iterate through all paths to update scenario
    for path in observed_path:
        # iterate through positions for each path
        # print(path)
        positions = path[0]
        velocities = path[1]
        for i in range(len(positions)):
            # update new locations of pucks
            new_x, new_y = positions[i]
            new_vx, new_vy = velocities[i]
            pucks[i].update_pos(new_x, new_y)
            pucks[i].update_v(new_vx, new_vy)

            # Rest time on surfaces
            for puck in pucks:
                for surf in surfaces:
                    if (physics.collision(puck, surf)
                            and len(puck.positions) > 1):
                        if (puck.positions[-1] == puck.positions[-2]):
                            if (puck, surf) in collision_times:
                                collision_times[(puck.color, surf.color)] += 1
                                collision_velocities[(puck.color,
                                                      surf.color)].append(
                                                          puck.velocity)
                            else:
                                collision_times[(puck.color, surf.color)] = 0
                                collision_velocities[(puck.color,
                                                      surf.color)] = [
                                                          puck.velocity
                                                      ]

            for p1 in pucks:
                for p2 in pucks:
                    if (p1 != p2 and physics.collision(p1, p2) and
                        ((p1.color, p2.color) not in pre_post_collision)
                            and len(p2.velocities) > 1
                            and len(p1.velocities) > 1):

                        # print("Pre- and post-collision velocity ratio")
                        # print("p1 x: ", p1.velocities[-2][0]/p1.velocities[-1][0])
                        # print("p2 x: ", p2.velocities[-2][0]/p2.velocities[-1][0])
                        # print("p1 y: ", p1.velocities[-2][1]/p1.velocities[-1][1])
                        # print("p2 y: ", p2.velocities[-2][1]/p2.velocities[-1][1])
                        pre_post_collision[(p1.color, p2.color)] = [
                            (p1.velocities[-2][0] / p1.velocities[-1][0],
                             p1.velocities[-2][1] / p1.velocities[-1][1]),
                            (p2.velocities[-2][0] / p2.velocities[-1][0],
                             p2.velocities[-2][1] / p2.velocities[-1][1])
                        ]

    stats["pre_post"] = pre_post_collision

    stats["rest_time_surf"] = collision_times
    # print("Rest time on surfaces", collision_times)

    velocity_loss = {}
    # print("Velocity loss while on surfaces")
    for k in collision_velocities.keys():
        if k not in velocity_loss:
            velocity_loss[k] = (collision_velocities[k][-1][0] -
                                collision_velocities[k][0][0],
                                collision_velocities[k][-1][1] -
                                collision_velocities[k][0][1])
        # else:
        #     velocity_loss[k].append((collision_velocities[k][-1][0] -
        #                     collision_velocities[k][0][0],
        #                     collision_velocities[k][-1][1] -
        #                     collision_velocities[k][0][1]))
        # print("x ", collision_velocities[k][-1][0] - collision_velocities[k][0][0])
        # print("y ", collision_velocities[k][-1][1] - collision_velocities[k][0][1])

    stats["velocity_loss"] = velocity_loss

    # after all paths get stats on each puck
    stats["dist_average"] = physics.average_dist(pucks)
    # print("Average pairwise distance between particles", physics.average_dist(pucks))

    stats["total_change"] = physics.total_pairwise_dist(pucks)
    # print("Total change in pairwise distance", physics.total_pairwise_dist(pucks))
    # print('\n')

    av_position = {}
    av_velocity = {}
    total_change = {}
    for puck1 in pucks:
        # print(puck1.color)
        av_position[puck1.color] = puck1.get_average_pos()
        # print("average  diff", puck1.get_average_pos())

        total_change[puck1.color] = puck1.total_change()
        # print("total change", puck1.total_change())

        av_velocity[puck1.color] = puck1.get_average_v()
        # print("average velocity", puck1.get_average_v())

        # print('\n')

    stats["av_position"] = av_position
    stats["total_change_pucks"] = total_change
    stats["av_velocity"] = av_velocity

    return stats
Ejemplo n.º 7
0
 def image(self, main, player=None, GV=None):
     pygame.draw.polygon(main, self.color, self.point_list)
     a, b = collision(self.elem.points_list, player.elem.points_list)
     if a and b:
         player.isAlive = False
     return False
Ejemplo n.º 8
0
 def image(self, main, player=None, GV=None):
     pygame.draw.polygon(main, self.color, self.point_list)
     a, b = collision(self.elem.points_list, player.elem.points_list)
     if a and b:
         GV.level_pass += 1
     return False