Exemplo n.º 1
0
 def __init__(self, x, y):
     shape = Xudia.Graphic('+')
     hitbox = Hitbox(self, 4, 3)
     super().__init__(Vec2D(x, y), shape, hitbox)
     self.init_input(Xudia.input)
     self.velocity = Vec2D(0, 0)
     self.direction = Vec2D(0, 0)
     self.speed = 1
Exemplo n.º 2
0
	def draw(self, graphic, pos, size):
		pos = Vec2D(int(pos.x), int(pos.y))
		size = Vec2D(int(size.x), int(size.y))
		graphic, pos, size = Renderer.get_visible(graphic, pos, size)
		try:
			for i, l in enumerate(graphic):
				self.screen.addstr(pos.y + i, pos.x, l)
		except curses.error:
			pass
Exemplo n.º 3
0
 def onfire(self):
     b = None
     if self.direction == 1:
         b = Bullet(self.position.x + 4, self.position.y + 1,
                    Vec2D(self.direction, 0))
     elif self.direction == -1:
         b = Bullet(self.position.x - 1, self.position.y + 1,
                    Vec2D(self.direction, 0))
     else:
         return
     Xudia.scene.add_entity(b)
     Xudia.collision.add_collidable(
         b, Xudia.scene.enemy,
         lambda: Xudia.scene.remove_entity(Xudia.scene.enemy))
Exemplo n.º 4
0
	def get_visible(graphic, pos, size):
		# the whole graphic isn't visible
		if pos.y >= curses.LINES or pos.x >= curses.COLS:
			return [], pos, Vec2D(0, 0)
		if pos.y + size.y <= 0 or pos.x + size.x <= 0:
			return [], pos, Vec2D(0, 0)

		# partially hidden up or down
		if len(graphic) > curses.LINES - pos.y:
			graphic = graphic[:curses.LINES - pos.y]
		if pos.y < 0:
			graphic = graphic[-pos.y:]
			pos.y = 0

		# partially hidden left or right
		if len(graphic[0]) > curses.COLS - pos.x:
			for i in range(len(graphic)):
				graphic[i] = graphic[i][:curses.COLS - pos.x]
		if pos.x < 0:
			for i in range(len(graphic)):
				graphic[i] = graphic[i][-pos.x:]
			pos.x = 0
		
		return graphic, pos, Vec2D(len(graphic[0]), len(graphic))
Exemplo n.º 5
0
	def begin(self):
		self.enemy = Entity(
			Vec2D(Xudia.renderer.width-10, Xudia.renderer.height/2),
			Xudia.Graphic('<<==\n|===\n<<=='),
			None

		)
		hitbox = Hitbox(self.enemy, 4, 3)
		self.enemy.hitbox = hitbox
		
		self.add_entity(self.enemy)

		self.add_entity(Ship(Xudia.renderer.width/2, Xudia.renderer.height/2))
		
		self.add_entity(FPS())

		Xudia.input.add_listener('q', Xudia.engine.stop)
Exemplo n.º 6
0
	def __init__(self, x=0, y=0):
		super().__init__(Vec2D(x, y), Xudia.Graphic(''), None)
		self.lastCall = 0
Exemplo n.º 7
0
 def __init__(self, x, y, velocity):
     hitbox = Hitbox(self, 1, 1)
     super().__init__(Vec2D(x, y), Xudia.Graphic('+'), hitbox)
     self.velocity = velocity
     self.life = 60
Exemplo n.º 8
0
 def onkeyleft(self):
     self.velocity = Vec2D(-self.speed, 0)
     if self.direction != -1:
         self.steer(-1)
Exemplo n.º 9
0
 def onkeydown(self):
     self.velocity = Vec2D(0, self.speed)
Exemplo n.º 10
0
 def onkeyright(self):
     self.velocity = Vec2D(self.speed, 0)
     if self.direction != 1:
         self.steer(1)
Exemplo n.º 11
0
 def onkeyup(self):
     self.velocity = Vec2D(0, -self.speed)
Exemplo n.º 12
0
 def update(self):
     self.move_by(self.velocity)
     self.velocity = Vec2D(0, 0)
Exemplo n.º 13
0
 def get_size(shape):
     size = Vec2D(0, 0)
     size.y = len(shape.split('\n'))
     size.x = len(shape.split('\n')[0])
     return size