def __init__(self, midbottom, data): Entity.__init__(self, data) self.add(data.playerGroup) self.add(data.mobs) # red theme colour - currently unused colourDict = { (206, 209, 138): (206, 138, 138), # robe (170, 192, 171): (191, 170, 170), # shoes and hat (206, 201, 175): (204, 184, 173), # skin (233, 234, 232): (233, 234, 232) } # moustache animImages = {} for animName in [ 'run', 'jump', 'idle', 'cast', 'push', 'pull', 'grab' ]: animImages[animName] = pygame.image.load( 'assets/mobs/player/%s.png' % (animName)) #animImages = self.setColours(colourDict, animImages) self.initAnimations(animImages) collisionRect = pygame.Rect((0, 0), (83, 120)) collisionRect.midbottom = midbottom self.collisions = CollisionComponent(self, collisionRect, True) self.gravity = GravityComponent(self) self.obeysGravity = True self.weight = 1 self.movedThisFrame = False self.moveSpeedModifier = { 'left': 0, 'right': 0 } # a number added on to the player's moveSpeed every frame # eg when pushing a crate self.xVel = self.yVel = 0 self.facing = 'R' self.isOnGround = False self.lastTimeOnGround = 0 self.releasedJumpButton = True self.animation.play('idleR') self.animation.update() self.rect = self.image.get_rect(midbottom=midbottom) self.pullRect = pygame.Rect((0, 0), (40, self.rect.height)) self.pullStartFacing = None self.isPulling = False
def __init__(self, rect, image, data, isRectangle=True): Entity.__init__(self, data) self.add(data.staticObjects) self.add(data.worldGeometry) self.image = image self.rect = rect h = rect.height / 2.0 w = rect.width / 2.0 self.body = data.world.CreateStaticBody(position=(data.pixelsToMetreCoords(rect.topleft)), shape=polygonShape(box=(data.pixelsToMetresConvert((h, w))))) print str(self.body.position) print str(data.pixelsToMetresConvert((h, w)))
def __init__(self, rect, image, data, isRectangle=True): Entity.__init__(self, data) self.add(data.staticObjects) self.add(data.worldGeometry) self.image = image self.rect = rect h = rect.height / 2.0 w = rect.width / 2.0 self.body = data.world.CreateStaticBody( position=(data.pixelsToMetreCoords(rect.topleft)), shape=polygonShape(box=(data.pixelsToMetresConvert((h, w))))) print str(self.body.position) print str(data.pixelsToMetresConvert((h, w)))
def __init__(self, data, image, center, avgLifeSpan, velocity, obeysGravity): """obeysGravity: 0 is no gravity, 1 is falling particle, -1 is upward floating particle""" Entity.__init__(self, data) self.add(data.particles) self.image = image self.rect = image.get_rect(center=center) self.coords = list(center) self.velocity = list(velocity) self.obeysGravity = obeysGravity if obeysGravity: self.gravity = GravityComponent(self) self.weight = Particle.weight self.birthTime = time.time() self.lifeTime = random.uniform(avgLifeSpan - 0.3, avgLifeSpan + 0.3) if self.lifeTime < 0: self.lifeTime = 0.05
def __init__(self, midbottom, data): Entity.__init__(self, data) self.add(data.playerGroup) self.add(data.mobs) # red theme colour - currently unused colourDict = {(206, 209, 138): (206, 138, 138), # robe (170, 192, 171): (191, 170, 170), # shoes and hat (206, 201, 175): (204, 184, 173), # skin (233, 234, 232): (233, 234, 232)} # moustache animImages = {} for animName in ['run', 'jump', 'idle', 'cast', 'push', 'pull', 'grab']: animImages[animName] = pygame.image.load('assets/mobs/player/%s.png' %(animName)) #animImages = self.setColours(colourDict, animImages) self.initAnimations(animImages) collisionRect = pygame.Rect((0, 0), (83, 120)) collisionRect.midbottom = midbottom self.collisions = CollisionComponent(self, collisionRect, True) self.gravity = GravityComponent(self) self.obeysGravity = True self.weight = 1 self.movedThisFrame = False self.moveSpeedModifier = {'left': 0, 'right': 0} # a number added on to the player's moveSpeed every frame # eg when pushing a crate self.xVel = self.yVel = 0 self.facing = 'R' self.isOnGround = False self.lastTimeOnGround = 0 self.releasedJumpButton = True self.animation.play('idleR') self.animation.update() self.rect = self.image.get_rect(midbottom = midbottom) self.pullRect = pygame.Rect((0, 0), (40, self.rect.height)) self.pullStartFacing = None self.isPulling = False
def __init__(self, rect, image, data, pushable): Entity.__init__(self, data) self.add(data.dynamicObjects) self.rect = rect self.mask = pygame.mask.from_surface(image) self.maskOutline = self.mask.outline() self.isPushable = pushable self.movedThisFrame = False #self.collisions = CollisionComponent(self, False, True) #self.gravity = GravityComponent(self) self.enchantments = EnchantmentComponent(self) self.isBeingStoodOn = False h = rect.height / 2.0 w = rect.width / 2.0 self.body = data.world.CreateDynamicBody(position=(data.pixelsToMetreCoords(self.rect.topleft)), angle=0) self.body.CreatePolygonFixture(box=(data.pixelsToMetresConvert((h, w))), density=1, friction=0.3)
def __init__(self, rect, image, data, pushable): Entity.__init__(self, data) self.add(data.dynamicObjects) self.rect = rect self.mask = pygame.mask.from_surface(image) self.maskOutline = self.mask.outline() self.isPushable = pushable self.movedThisFrame = False #self.collisions = CollisionComponent(self, False, True) #self.gravity = GravityComponent(self) self.enchantments = EnchantmentComponent(self) self.isBeingStoodOn = False h = rect.height / 2.0 w = rect.width / 2.0 self.body = data.world.CreateDynamicBody( position=(data.pixelsToMetreCoords(self.rect.topleft)), angle=0) self.body.CreatePolygonFixture(box=(data.pixelsToMetresConvert( (h, w))), density=1, friction=0.3)