Пример #1
0
  def on_init(self):
    pygame.init()
    self._display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
    self._running = True
    image = pygame.image.load("ball.png")
    image = image.convert_alpha()

    ball_sprite = gameobject(50, 92, image, ball_group)
    ball_sprite.rect = ball_sprite.image.get_rect()
    ball_sprite.set_hitbox(10, 10, -20, -20)
    ball_sprite.body.mass = 1.0


    red_ball = gameobject(200,92, image.copy() )
    red_ball.image.fill((80,0,0,127), (red_ball.rect), pygame.BLEND_RGB_ADD)
    red_ball.set_hitbox(10, 10, -20, -20)
    red_ball.body.mass = 1.1

    ball_group.add(red_ball)

    bigball_sprite = gameobject(250, -20, image, ball_group)
    bigball_sprite.image = pygame.transform.scale(image, (200,200) )
    bigball_sprite.rect = bigball_sprite.image.get_rect()
    bigball_sprite.set_hitbox(25, 25, -50, -50)
    bigball_sprite.body.mass = 1.5

    #Font
    myfont = pygame.font.SysFont("monospace", 16)
    global tx_instruction
    tx_instruction = myfont.render("Hold space to add force. H to show hitbox. T to hide text.", 0, (255,0,0) )
Пример #2
0
 def changeBalls(self):
   ball_group.add(self.ball_sprite)
   self.ball_sprite = gameobject(10, 440, self.image, active_group)
   self.ball_sprite.rect = self.ball_sprite.image.get_rect()
   self.ball_sprite.set_hitbox(10, 10, -20, -20)
   self.ball_sprite.body.mass = self.mass
   self.ball_sprite.K = self.K
   self.line.append(lineMaker())
   self.color = (randint(0,255), randint(0,255), randint(0,255))
   self.line[-1].color = self.color
   pass
Пример #3
0
  def on_init(self):
    pygame.init()
    self._display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
    self._running = True
    self.image = pygame.image.load("ball.png")
    self.image = self.image.convert_alpha()
    self.image = pygame.transform.scale(self.image, (45,45) )

    self.ball_sprite = gameobject(10, 440, self.image, active_group)
    self.ball_sprite.rect = self.ball_sprite.image.get_rect()
    self.ball_sprite.set_hitbox(10, 10, -20, -20)
    self.ball_sprite.body.mass = self.mass
    self.ball_sprite.K = self.k * self.rho * self.A * self.Cd

    # red_ball = gameobject(200,92, image.copy() )
    # red_ball.image.fill((80,0,0,127), (red_ball.rect), pygame.BLEND_RGB_ADD)
    # red_ball.set_hitbox(10, 10, -20, -20)
    # red_ball.body.mass = 1.1

    # ball_group.add(red_ball)

    #Font
    self.myfont = pygame.font.SysFont("monospace", 16)
  
    self.tx_instruction = self.myfont.render("Hold space to add force. H to show hitbox. T to hide text.", 0, (255,0,0) )
    self.tx_values = self.myfont.render("Angle: {0} Force: {1} Lines: {2} Dots: {3} Rho: A: {4} Cd: {5} k: {6} K:{7}".format(
                        self.angle, self.initial_speed, self.countLines(), len(dots_group), self.A, self.rho, self.Cd, self.k, self.A*self.rho*self.Cd*self.k ), 0, (255,0,0) ) 

    if self.rho > -0.001 and self.rho < 0.001:
      self.rho = 0
    if self.A > -0.001 and self.A < 0.001:
      self.A = 0
    if self.k > -0.001 and self.k < 0.001:
      self.k = 0
    if self.Cd > -0.001 and self.Cd < 0.001:
      self.Cd = 0
    if self.K > -0.0001 and self.K < 0.0001:
      self.K = 0
    self.tx_values_2 = self.myfont.render("K:{0} = Rho: {1} A: {2} Cd: {3} k: {4}".format(
                         self.K, self.rho, self.A, self.Cd, self.k ), 0, (255,0,0) )