Ejemplo n.º 1
0
 def draw(self):
     if self.kind == "dot":
         pixel_points = CoorsAndPixels.coor_to_pixel(self.pos, scale, size)
         radius = int((self.charge)**(1.0/3.0)*scale)
         gfxdraw.filled_circle(screen, pixel_points[0], pixel_points[1], radius, self.color)
         if radius > 1:
             gfxdraw.aacircle(screen, pixel_points[0], pixel_points[1], radius, self.color)
     elif self.kind == "line":
         #pygame.draw.aaline(screen, self.color, CoorsAndPixels.coor_to_pixel(self.pos, scale, size, True), CoorsAndPixels.coor_to_pixel([self.pos[0]+self.length*self.cos_a, self.pos[1]+self.length*self.sin_a], scale, size, True))
         pygame.draw.line(screen, self.color, CoorsAndPixels.coor_to_pixel(self.pos, scale, size, True), CoorsAndPixels.coor_to_pixel([self.pos[0]+self.length*self.cos_a, self.pos[1]+self.length*self.sin_a], scale, size, True), int(self.charge**(1.0/3.0)/5.0)+1)
Ejemplo n.º 2
0
def display_info(): #shows level name and comments (if there are any)
    label = font.render("Level " + str(level+1) + ": " + level_name, 1, (0, 0, 0))
    screen.blit(label, [10, 10])
    #label = font.render("Sim. speed: " + str(simulation_speed), 1, (0, 0, 0))
    #screen.blit(label, [10, 10+label.get_rect()[3]])
    for x in comments:
        label = font.render(x[0], 1, (0, 0, 0))
        screen.blit(label, CoorsAndPixels.coor_to_pixel([x[1][0], x[1][1]], scale, size))
Ejemplo n.º 3
0
def simulate(l_secs = 0.0, steps = 0, vel = [0.0, 0.0], pos=[0.0, 0.0]):
    local_pos = [pos[0], pos[1]]
    local_vel = [vel[0], vel[1]]
    for x in range(steps):
        for i in range(object_count):
            local_vel = objects[i].act_upon(l_secs, local_vel, local_pos)
        if local_vel == False:
            break
        prev_dots = [local_pos[0], local_pos[1]]
        local_pos[0] += local_vel[0]*l_secs
        local_pos[1] += local_vel[1]*l_secs
        green = int(255.0/steps*x)
        blue = int(255.0/steps*x)
        pygame.draw.aaline(screen, (255, green, blue), CoorsAndPixels.coor_to_pixel(prev_dots, scale, size, True), CoorsAndPixels.coor_to_pixel(local_pos, scale, size, True))
        total_velocity = math.sqrt(local_vel[0]**2 + local_vel[1]**2)
        try:
            l_secs = min(1.0/60.0, 1.0/total_velocity)
        except:
            l_secs = 1.0/400.0
Ejemplo n.º 4
0
             simulation_speed += sim_add
     if e.key == pygame.K_KP_MINUS: #decrease simulation speed
         sim_add = 10**math.floor(math.log10(simulation_speed)+1.0)/10.0
         if sim_add == simulation_speed:
             simulation_speed -= sim_add/10.0
         else:
             simulation_speed -= sim_add
         if sim_add < 0.1:
             sim_add = 0.0
     if e.key == pygame.K_r: #restart at the current level
         new_level(level)
 #mouse events
 if e.type == pygame.MOUSEBUTTONDOWN:
     if e.button == 1: #left click
         mouse_pos_old = pygame.mouse.get_pos()
         my_dot_pixels = CoorsAndPixels.coor_to_pixel(my_dot_pos, scale, size)
         #if ball is clicked
         if (mouse_pos_old[0]-my_dot_pixels[0])**2+(mouse_pos_old[1]-my_dot_pixels[1])**2 < (my_dot_mass**(1.0/3.0)*scale)**2 and not started:
             clicked_my_dot = True
     if e.button == 3: #cancel shot by right clicking
         if clicked_my_dot:
             clicked_my_dot = False
 if e.type == pygame.MOUSEBUTTONUP:
     if e.button == 1: #shoot the ball
         if clicked_my_dot == True:
             clicked_my_dot = False
             started = True
 if e.type == pygame.MOUSEMOTION and clicked_my_dot and not started: #adjust velocity for the shoot
     mouse_pos = pygame.mouse.get_pos()
     my_dot_vel[0] = -(mouse_pos_old[0]-mouse_pos[0])/scale/10.0
     my_dot_vel[1] = (mouse_pos_old[1]-mouse_pos[1])/scale/10.0