def update(self): self.rect.center = self.body.position - framework.scrolling self.image = framework.rot_center(self.image_default, math.degrees(-self.body.angle)) self.body.angular_velocity = self.body.angular_velocity * .98 self.body.angle *= .99 if self.balloon: pygame.draw.aaline(framework.screen,pygame.color.THECOLORS["brown"],self.body.position - pymunk.Vec2d(105,0).rotated(self.body.angle) - framework.scrolling, self.balloon.body.position - pymunk.Vec2d(185,20).rotated(self.balloon.body.angle) - framework.scrolling) pygame.draw.line(framework.screen,pygame.color.THECOLORS["gray"],self.body.position - pymunk.Vec2d(102,0).rotated(self.body.angle) - framework.scrolling, self.balloon.body.position - pymunk.Vec2d(185,20).rotated(self.balloon.body.angle) - framework.scrolling) pygame.draw.line(framework.screen,pygame.color.THECOLORS["brown"],self.body.position + pymunk.Vec2d(115,0).rotated(self.body.angle) - framework.scrolling, self.balloon.body.position + pymunk.Vec2d(185,20).rotated(self.balloon.body.angle) - framework.scrolling) pygame.draw.line(framework.screen,pygame.color.THECOLORS["gray"],self.body.position + pymunk.Vec2d(112,0).rotated(self.body.angle) - framework.scrolling, self.balloon.body.position + pymunk.Vec2d(185,20).rotated(self.balloon.body.angle) - framework.scrolling) if framework.debug: for shape in self.shapes: scrolled_points = [point - framework.scrolling for point in shape.get_vertices()] pygame.draw.polygon(framework.screen, pygame.color.THECOLORS["green"], scrolled_points, True)
def __init__(self, image, x, y, angle=0, angular_velocity=0, width=10, height=10, mass=1, elasticity=0, friction=.8, offset=(0, 0), jumpable=0): pygame.sprite.Sprite.__init__(self) self.image_default = pygame.image.load(image).convert() self.image_default.set_colorkey((1, 0, 0)) self.image = self.image_default self.rect = self.image.get_rect() self.rect.center = (x, y) points = [(-width, -height / 2), (-width, height / 2), (width, height / 2), (width, -height / 2)] self.body = pymunk.Body(mass, pymunk.moment_for_poly(mass, points, offset)) self.body.position = x, y self.body.angular_velocity = angular_velocity self.body.velocity_limit = 300 self.shape = pymunk.Poly(self.body, points, offset) # self.shape.layers = self.shape.layers ^ 0b1000 self.shapes = [self.shape] self.shape.elasticity = elasticity self.shape.friction = friction self.shape.collision_type = jumpable # 0 - can't jump off of it; 1 - can jump when standing on it self.rotated_images = {} for i in range(0, 360, 5): self.rotated_images[i] = framework.rot_center( self.image_default, i)
def __init__( self, image, x, y, angle=0, angular_velocity=0, width=10, height=10, mass=1, elasticity=0, friction=0.8, offset=(0, 0), jumpable=0, ): pygame.sprite.Sprite.__init__(self) self.image_default = pygame.image.load(image).convert() self.image_default.set_colorkey((1, 0, 0)) self.image = self.image_default self.rect = self.image.get_rect() self.rect.center = (x, y) points = [(-width, -height / 2), (-width, height / 2), (width, height / 2), (width, -height / 2)] self.body = pymunk.Body(mass, pymunk.moment_for_poly(mass, points, offset)) self.body.position = x, y self.body.angular_velocity = angular_velocity self.body.velocity_limit = 300 self.shape = pymunk.Poly(self.body, points, offset) # self.shape.layers = self.shape.layers ^ 0b1000 self.shapes = [self.shape] self.shape.elasticity = elasticity self.shape.friction = friction self.shape.collision_type = jumpable # 0 - can't jump off of it; 1 - can jump when standing on it self.rotated_images = {} for i in range(0, 360, 5): self.rotated_images[i] = framework.rot_center(self.image_default, i)
def update(self): self.rect.center = self.body.position - framework.scrolling self.image = framework.rot_center(self.image_default, math.degrees(-self.body.angle)) if framework.debug: scrolled_points = [point - framework.scrolling for point in self.shape.get_vertices()] pygame.draw.polygon(framework.screen, pygame.color.THECOLORS["green"], scrolled_points, True)