def move(self, ignore_list):
     if self.speed > 0:
         if collide(self.ent.position, self.ent.forward, 2.5, ignore_list,
                    self._speed):
             speed = self.speed
             if self.lights:
                 self.hp -= self.speed * 20
                 self.light_time -= self.speed * 40
             else:
                 self.hp -= self.speed * 40
             self.speed = None
             return speed
     if self.speed < 0:
         if collide(self.ent.position, self.ent.back, 2.3, ignore_list,
                    self._speed):
             speed = self.speed
             if self.lights:
                 self.hp -= abs(self.speed) * 20
                 self.light_time -= abs(self.speed) * 40
             else:
                 self.hp -= abs(self.speed) * 40
             self.speed = None
             return -speed
     self.ent.position += self.ent.forward * self.speed
     return 0
Example #2
0
 def collision(obj, game):
     temp_colliding_units = game.get_colliding_units(obj)
     for to_hit in temp_colliding_units:
         if to_hit not in obj.colliding_units:
             to_hit.colliding_units.append(obj)
             utils.collide(to_hit, obj.pos)
             utils.collide(obj, to_hit.pos)
     obj.colliding_units = temp_colliding_units
Example #3
0
def click(obj, obj_type, x, y):
    # return true if x and y are inside of obj bounds
    global content

    if obj_type == go.RECT:
        r = content[obj]["rect"]
        return utils.collide(x, y, r[0], r[1], r[2], r[3])
    if obj_type == go.TEXT:
        label = content[obj]["text"]
        tx = content[obj]["x"]
        ty = content[obj]["y"]
        width = label.content_width
        height = label.content_height
        if label.anchor_x == "center":
            # subtract half width
            return utils.collide(x, y, tx - (width / 2), ty, width, height)
        else:
            return utils.collide(x, y, tx, ty, width, height)

    if obj_type == go.BUTTON:
        # button collision is handles before
        return False
    if obj_type == go.IMG:
        return False  # sprite offsetter is not implemented yet!
Example #4
0
 def check_collisions(self, obj):
     posy1, posy2, posx1, posx2 = self.get_coords(obj)
     #return None
     for x in self.elements:
         if x != obj and utils.collide(obj, x):
             return x
     if self.quads != None:
         if posy1 >= 0 and posy2 <= 1 and posx1 >= 0 and posx2 <= 1:
             if posy1 == posy2 and posx1 == posx2:
                 result = self.quads[posy1][posx1].check_collisions(obj)
                 if result != None:
                     return result
             else:
                 for y in range(0, 2):
                     for x in range(0, 2):
                         result = self.quads[y][x].check_collisions(obj)
                         if result != None:
                             return result
     return None
Example #5
0
    def update_obj_pos(self, obj):
        obj.pos[0] += obj.speed[0]
        obj.pos[1] += obj.speed[1]

        if obj.pos[1] + obj.radius < 0.:
            obj.is_active = False

        if isinstance(obj, Player) and obj.pos[1] + obj.radius > self._height:
            utils.collide(obj, [obj.pos[0], self._height])
        if obj.pos[1] - obj.radius > self._height:
            obj.is_active = False

        if isinstance(obj, Unit) and obj.pos[0] - obj.radius < 0.:
            utils.collide(obj, [0., obj.pos[1]])
        if obj.pos[0] + obj.radius < 0.:
            obj.is_active = False

        if isinstance(obj, Unit) and obj.pos[0] + obj.radius > self._width:
            utils.collide(obj, [self._width, obj.pos[1]])
        if obj.pos[0] - obj.radius > self._width:
            obj.is_active = False
             tail_length=tail_length, color=np.array([color0,color1,color2]), name=name, mass=mass, r=r)
        )


exp = 3.432
epoch = 0
epochs = 10**exp

G = 10
all_stars = ALL_STARS

# Plot frames
start = datetime.now()
print('Simulating...')
while True:
    stars, ALL_STARS, ORIGIN, CENTRIAL = collide(stars, ALL_STARS, ORIGIN, CENTRIAL)
    stars, ORIGIN, CENTRIAL = accelerate(stars, G, ORIGIN, CENTRIAL, dt=1e-3)

    fig = plt.figure(figsize=(8,8))
    ax = fig.add_subplot(1,1,1)
    ax.set_xticks([])
    ax.set_yticks([])
    plt.axis([-100+ORIGIN[0],100+ORIGIN[0],-100+ORIGIN[1],100+ORIGIN[1]])

    for star in stars:
        circle = Circle(star.pos, star.r, color=star.color)
        ellipse = Ellipse(star.pos, star.r, star.r/2, star.spin*epoch, color=1-star.color)
        ax.add_patch(circle)
        ax.add_patch(ellipse)

    plt.savefig(os.path.join('.',frame_path,str(epoch).zfill(int(exp)+1)+'.jpg'))
 def check_collisions(self):
     for wall in self.env.walls:
         if utils.collide(wall, self.env.robot):
             return True
Example #8
0
 def hit(self, mx, my):
     # only tell if hit but don't change button
     return utils.collide(mx, my, self.x, self.y, self.w, self.h)
Example #9
0
angleRect = angle.get_rect()

# set the center of the rectangular object.
forceRect.center = (100, 100)
angleRect.center = (100, 150)

running = True
while running:
    screen.fill((255, 255, 255))
    screen.blit(force2, forceRect)
    screen.blit(angle, angleRect)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    for i, obj in enumerate(objs):
        obj.update_pos()
        obj.display(screen)
        for obj2 in objs[i + 1:]:
            force = Object.gravitational_force(obj, obj2)
            force2 = font.render(f'Gravity: {objs[0].velocity.magnitude}',
                                 True, green, blue)
            angle = font.render(f'Angle: {objs[1].velocity.magnitude}', True,
                                green, blue)
            obj.update_velocity(
                Vector(force.magnitude / obj.mass, force.angle - .5 * math.pi))
            obj2.update_velocity(
                Vector(force.magnitude / obj2.mass,
                       force.angle + .5 * math.pi))
            collide(obj, obj2)
    pygame.display.flip()