def __init__(self, position, size, spaces, bullet_type, color=(255, 255, 255)): Sprite.__init__(self, position, size) self.body = pymunk.Body(3, pymunk.inf) self.body.position = Vec2d(position) self.body.body_type = pymunk.Body.KINEMATIC size = Vec2d(size) self.shape = pymunk.Poly(self.body, [(-size.x / 2, size.y / 2), (size.x / 2, size.y / 2), (size.x / 2, -size.y / 2), (-size.x / 2, -size.y / 2)]) self.size = size self.grid_position = 2 self.next_grid_position = None self.direction = Vec2d(0, 0) self.speed = 300 self.spaces = spaces[:] self.moving_velocity = Vec2d(0, 0) self.bullet_type = bullet_type self.bullet_speed = 500 self.last_bullet = None self.color = color self.image.fill(color) self.base_image = self.image.copy() self.scale = 1 self.body.kill = False
def __init__(self, position, size): Sprite.__init__(self, position, size) self.body = pymunk.Body(body_type=pymunk.Body.KINEMATIC) self.body.position = Vec2d(position) size = Vec2d(size) self.shape = pymunk.Poly(self.body, [(0, 0), (0, -size.y), (size.x, -size.y), (size.x, 0)]) self.shape.friction = 1. self.shape.collision_type = 2
def __init__(self, position, size, velocity): Sprite.__init__(self, position, size) # print 'created bullet' self.image.fill((255, 255, 255)) self.base_image = self.image.copy() self.body = pymunk.Body(3, pymunk.inf) self.body.position = position self.body.velocity = velocity self.shape = pymunk.Circle(self.body, size[0] / 2) self.shape.collision_type = 3 self.body.kill = False
def __init__(self, position, size): Sprite.__init__(self, position, size) self.body = pymunk.Body(body_type=pymunk.Body.STATIC) self.a = Vec2d(position) self.b = Vec2d(1, 0) self.b.rotate_degrees(size[1]) self.b *= size[0] self.b += self.a self.image = pygame.Surface((0, 0)) print self.a, self.b self.shape = pymunk.Poly(self.body, ((0, 0), (0, 0)))
def __init__(self, position, size): Sprite.__init__(self, position, size) # moment = pymunk.moment_for_poly(5, map(lambda p: Vec2d(p), [(0, 0), (0, -size.y), (size.x, -size.y), (size.x, 0)])) self.body = pymunk.Body(body_type=pymunk.Body.DYNAMIC) self.image.fill((200, 100, 50)) self.body.mass = 5 self.body.moment = pymunk.inf self.body.position = Vec2d(position) size = Vec2d(size) self.shape = pymunk.Poly(self.body, [(0, 0), (0, -size.y), (size.x, -size.y), (size.x, 0)], radius=1) self.shape.friction = 1.0 self.shape.elasticity = 1 self.gravity = Vec2d(0, -1000) self.shape.collision_type = 10
def __init__(self, position, direction): bullet_size = (10, 10) bullet_speed = 1000 radius = bullet_size[0] / 2 Sprite.__init__(self, position, bullet_size) self.gravity = Vec2d(0, 0) self.body = pymunk.Body(body_type=pymunk.Body.KINEMATIC) self.body.position = position self.shape = pymunk.Circle(self.body, radius) self.shape.friction = 1.0 self.shape.collision_type = collision_types["Bullet"] self.body.velocity = bullet_speed * direction self.shape.kill = False # death flag triggered when hits asteroid
def __init__(self, position, size): Sprite.__init__(self, position, size) scale = [32, 48] self.animation = SpriteSheets.Animation('images/xmasgirl1.png', (32, 48), colorkey=None, scale=scale) self.animation.animate(2) self.image = self.animation.next() self.image.convert() self.size = scale self.gravity = Vec2d(0, -1000) # an acceleration of some sort? self.body = pymunk.Body(3, pymunk.inf) self.shape = pymunk.Circle(self.body,size[0]) self.shape.name = 'feet' self.head = pymunk.Circle(self.body, size[0]*2, (0, 25)) self.head.friction = 0 self.torso = pymunk.Circle(self.body, size[0]*1.5, (0, 10)) self.torso.friction = 0 self.shape.collision_type, self.head.collision_type, self.torso.collision_type = 1, 1, 1 self.body.position = position self.max_speed = 100*2. self.accel_time = 0.05 self.accel = (self.max_speed/self.accel_time) self.shape.friction = -self.accel/self.gravity.y self.grounded = False self.jump_impulse = 800 self.air_speed_max = 10000 self.air_speed = self.air_speed_max self.targetvx = 0 self.direction = 1 self.body.pass_through = False self.body.kill = False self.body.last_pass = None
def pymunk2pygame(self, screen): Sprite.pymunk2pygame(self, screen) self.rect.x -= self.scale * self.size[0] / 2 self.rect.y -= self.scale * self.size[1] / 2