class StandardBullet(Bullet):

	def __init__(self, x, y):
		self.ORIGINAL_WIDTH = 2 * windowManager.horizontalScale
		self.width = 2 * windowManager.horizontalScale
		self.ORIGINAL_HEIGHT = 15 * windowManager.verticalScale
		self.height = 15 * windowManager.verticalScale
		self.ORIGINAL_X = x - (self.width / 2)
		self.startX = x - (self.width / 2)
		self.ORIGINAL_Y = y
		self.startY = y
		self.physics = Physics(self.startX, self.startY)
		self.physics.maxSpeed = Vector(15*windowManager.horizontalScale, 15*windowManager.verticalScale)
		self.physics.weight = Vector(0, 0)
		self.physics.floorItSpeed = Vector(15*windowManager.horizontalScale, 15*windowManager.verticalScale)
		self.color = RGB(255, 0, 255) # Pink
		self.canvasItem = canvasManager.canvas.create_rectangle(self.physics.location.x,
																self.physics.location.y,
																self.physics.location.x+self.width,
																self.physics.location.y+self.height,
																fill=self.color.hex())
Example #2
0
class Ship(Entity):

	halfShipWidth = -1
	bulletPath = {Actions.UP : True,
				  Actions.DOWN : False,
				  Actions.LEFT: False,
				  Actions.RIGHT: False,

				  Actions.SPACE: False,
				  Actions.QUIT: False}
	bulletTimer = 0
	BULLET_WAIT_TIME = 5
	ORIGINAL_HALF_SHIP_WIDTH = 0 

	def __init__(self, x, y):
		self.ORIGINAL_WIDTH = 20
		self.width = 20
		self.ORIGINAL_HEIGHT = 20
		self.height = 20
		self.ORIGINAL_HALF_SHIP_WIDTH = self.width / 2
		self.halfShipWidth = self.width / 2
		self.ORIGINAL_X = x - self.halfShipWidth
		self.startX = x - self.halfShipWidth
		self.ORIGINAL_Y = y - 40
		self.startY = y - 40
		self.physics = Physics(self.startX, self.startY)
		self.color = RGB(0, 255, 0) # Green
		self.adjustHealthBy(0)
		self.canvasItem = canvasManager.canvas.create_polygon(self.physics.location.x,
															  self.physics.location.y,
															  self.physics.location.x+self.halfShipWidth,
															  self.physics.location.y-self.height,
															  self.physics.location.x+self.width,
															  self.physics.location.y,
															  fill=self.color.hex())

	# Override
	def calculateNewLocationBasedOnActions(self, requestedActions):
		if self.bulletTimer < self.BULLET_WAIT_TIME:
			self.bulletTimer += 1
		if requestedActions[Actions.SPACE]:
			if self.bulletTimer >= self.BULLET_WAIT_TIME:
				newBullet = StandardBullet(self.physics.location.x+self.halfShipWidth, self.physics.location.y-self.height)
				newBullet.bulletPath = self.bulletPath
				gameManager.bullets.append (newBullet)
				self.bulletTimer = 0
		return super(Ship, self).calculateNewLocationBasedOnActions(requestedActions)

	# Override
	def scale(self, horizontalScale, verticalScale):
		self.halfShipWidth = self.ORIGINAL_HALF_SHIP_WIDTH * horizontalScale
		super(Ship, self).scale(horizontalScale, verticalScale)

	# Override
	def drawElement(self):
		canvasManager.canvas.coords(self.canvasItem,
									self.physics.location.x,
									self.physics.location.y,
									self.physics.location.x+self.halfShipWidth,
									self.physics.location.y-self.height,
									self.physics.location.x+self.width,
									self.physics.location.y)