Example #1
0
	def __init__(self, xy, wh, bgColor=None, add=True):
		Sprite.__init__(self, xy, wh)

		if bgColor:
			self.image.fill(bgColor)
		if add:
			globs.currentgame.entities.add(self)
Example #2
0
class Block_002(Block):
	'''
	Grass
	'''
	def __init__(self, xy):
		Block.__init__(self, xy, bgColor=(50,200,50))
		grasswh = (60,25)
		self.image = pygame.image.load(globs.datadir+"/png/blocks/grass.png")
		self.image.convert()
		self.grass = Sprite(self.rect.topleft, grasswh)
		self.grass.image.set_colorkey((255,0,255))
		self.grass.image = pygame.image.load(globs.datadir+"/png/blocks/002_decoration.png")
		self.grass.image.convert()
		self.grass.image.convert_alpha()

	def blitDecoration(self, xy):
		self.grass.rect.topleft = (self.rect.x-5, self.rect.y-20)
		self.grass.worldBlit()
Example #3
0
	def __init__(self, xy):
		Block.__init__(self, xy, bgColor=(50,200,50))
		grasswh = (60,25)
		self.image = pygame.image.load(globs.datadir+"/png/blocks/grass.png")
		self.image.convert()
		self.grass = Sprite(self.rect.topleft, grasswh)
		self.grass.image.set_colorkey((255,0,255))
		self.grass.image = pygame.image.load(globs.datadir+"/png/blocks/002_decoration.png")
		self.grass.image.convert()
		self.grass.image.convert_alpha()
Example #4
0
	def __init__(self, xy, flags=[], wh=(50,50), bgColor=None, alpha=None):
		Sprite.__init__(self, xy, wh)

		self.bgColor = bgColor

		if not 'uncollidable' in flags:
			globs.currentgame.collidableBlocks.add(self)
			self.collidable = True
		else:
                        self.collidable = False
		if 'climbable' in flags:
			globs.currentgame.climbableBlocks.add(self)
		if 'actionBlock' in flags:
			globs.currentgame.actionBlocks.add(self)
		if 'worldActionBlock' in flags:
			globs.currentgame.worldActionBlocks.add(self)

		if bgColor:
			self.image.fill(self.bgColor)
		if alpha:
			self.image.set_alpha(alpha)
Example #5
0
	def __init__(self, xy, wh, health, add=True):
		CollidableEntity.__init__(self, xy, wh, (255,0,255), add=add)

		#self.attackArea = Sprite(parent, (0,0), (attackArea, attackArea))
		#print(self.attackArea)
		#self.updateAttackArea()

		self.maxhealth = health
		self.health = self.maxhealth
		self.lasthealth = None
		self.hitted = []

		if add:
			globs.currentgame.living_entities.add(self)

		# Initialize healthbar
		self.healthbar = Sprite((0,0), (self.image.get_width(), 5))
Example #6
0
class LivingEntity(CollidableEntity):
	def __init__(self, xy, wh, health, add=True):
		CollidableEntity.__init__(self, xy, wh, (255,0,255), add=add)

		#self.attackArea = Sprite(parent, (0,0), (attackArea, attackArea))
		#print(self.attackArea)
		#self.updateAttackArea()

		self.maxhealth = health
		self.health = self.maxhealth
		self.lasthealth = None
		self.hitted = []

		if add:
			globs.currentgame.living_entities.add(self)

		# Initialize healthbar
		self.healthbar = Sprite((0,0), (self.image.get_width(), 5))

	def drawHealthbar(self):
		self.healthbar.image.fill((0,0,0))

		healthpercentage = float(self.health)/self.maxhealth

		w = self.healthbar.rect.w * healthpercentage
		newrect = pygame.Rect(0, 0, w, self.healthbar.rect.h)
		self.healthbar.image.fill((255,0,0), newrect)


	def blitHealthbar(self):
		xy = (self.rect.x, self.rect.y-10)

		if self.health != self.lasthealth:
			self.drawHealthbar()
		self.lasthealth = self.health

		self.healthbar.rect = self.healthbar.image.get_rect(topleft=xy)
		self.healthbar.worldBlit()

	def worldBlit(self):
		CollidableEntity.worldBlit(self)
		self.blitHealthbar()

	def isAlive(self):
		if self.health <= 0:
			return False
		return True

	def die(self):
		self.kill()
		print(str(self) + " died")
		for item in self.hitted:
			item.hitting = None
		print(self.hitted)

	def checkHurt(self):
		pass

		#collidedItems = pygame.sprite.spritecollide(self, globs.currentgame.lethals, False)
		#for collidedItem in collidedItems:
		#	print(collidedItem)
		#	if collidedItem and collidedItem.owner != self and collidedItem != self:
		#		print(collidedItem.__class__)
		#		print("hitted!")
		#		collidedItem.hit(self)

		#		# Needed so he is not hurt every frame the player is colliding with the lethal item
		#		self.hitted.append(collidedItem.owner)
		#		collidedItem.hitting.append(self)