Exemplo n.º 1
0
 def in_sight(p1, p2):
     """returns True if the straight path from p1 to p2 has no obstacle"""
     path = bresenham(p1, p2)
     for c in path:
         x, y = c.pair()
         if self.data[x + 128 * (127 - y)] is WALL or self.special_data[x + 128 * (127 - y)] is FINISH:
             return False
     return True
Exemplo n.º 2
0
 def in_sight(p1, p2):
     """returns True if the straight path from p1 to p2 has no obstacle"""
     path = bresenham(p1, p2)
     for c in path:
         x, y = c.pair()
         if self.data[x + 128 * (127 - y)] is WALL or self.special_data[
                 x + 128 * (127 - y)] is FINISH:
             return False
     return True
Exemplo n.º 3
0
	def update(self, dt):
		track = self.race.track
		current_position = self.position
		if not self.target is None:
			target_direction = (self.target.position - self.position).angle()
			direction_variation = ((target_direction - self.direction + math.pi) % (2*math.pi)) - math.pi
			if direction_variation > self.turn * dt:
				direction_variation = self.turn * dt
			elif direction_variation < -self.turn * dt:
				direction_variation = -self.turn * dt
			self.direction += direction_variation
		move = self.get_direction_vector() * self.speed * dt
		new_position = current_position + move
		path = bresenham(current_position, new_position)
		for i, c in enumerate(path):
			if track.type(c, hit=True) in [WALL, DEEP]:
			# the shell hits a wall or a hole and disappears
				return self.remove()
		self.set_position(new_position)
		self.check_collisions()
Exemplo n.º 4
0
 def update(self, dt):
     track = self.race.track
     current_position = self.position
     if not self.target is None:
         target_direction = (self.target.position - self.position).angle()
         direction_variation = (
             (target_direction - self.direction + math.pi) %
             (2 * math.pi)) - math.pi
         if direction_variation > self.turn * dt:
             direction_variation = self.turn * dt
         elif direction_variation < -self.turn * dt:
             direction_variation = -self.turn * dt
         self.direction += direction_variation
     move = self.get_direction_vector() * self.speed * dt
     new_position = current_position + move
     path = bresenham(current_position, new_position)
     for i, c in enumerate(path):
         if track.type(c, hit=True) in [WALL, DEEP]:
             # the shell hits a wall or a hole and disappears
             return self.remove()
     self.set_position(new_position)
     self.check_collisions()
Exemplo n.º 5
0
	def update(self, dt):
		track = self.race.track
		current_position = self.position
		move = self.get_direction_vector() * self.speed * dt
		new_position = current_position + move
		path = bresenham(current_position, new_position)
		for i, c in enumerate(path):
			if track.type(c, hit=True) is WALL:
			# the shell bounces
				if c[0] != path[i-1][0]: # vertical wall
					self.direction = -self.direction + math.pi
				else: # horizontal wall
					self.direction = -self.direction
				new_position = current_position # don't move
				self.set_speed(self.speed - 15.) # slow down after each bounce
				if self.speed <= 40:
					return self.remove() # if the shell becomes too slow it disappears
				break
			elif track.type(new_position) is DEEP:
			# the shell disappears
				return self.remove()
		self.set_position(new_position)
		self.check_collisions()
Exemplo n.º 6
0
 def move(self, new_position):
     """move the car"""
     path = bresenham(self.position, new_position)
     for i, c in enumerate(path):
         if not self.state.aerial:  # a flying car can move over anything
             if self.race.track.type(c, hit=True) is WALL:
                 # hit a wall
                 if i == 0:
                     # car is stuck in a wall
                     return self.lakitu()
                 else:
                     # the car bounces against the wall
                     if path[i - 1][0] != c[0]:
                         self.set_speed(Vector(-0.5 * self.speed.x, 0.5 * self.speed.y))
                     else:
                         self.set_speed(Vector(0.5 * self.speed.x, -0.5 * self.speed.y))
                     new_position = self.position  # do not move
                 break
             if not self.state.jump:
                 if self.race.track.type(c) is DEEP:
                     # car is in a hole
                     return self.lakitu()
                 if self.racer.item is ITEMS[0] and self.race.track.type(c, special=True) is ITEM:
                     # the car touched an item block
                     block = self.race.track.item_blocks[(c[0], c[1])]  # find the block that was touched
                     if not block.delay:
                         block.activate()
                         self.racer.get_item()
                 if self.race.track.type(c) is JUMP:
                     # touch a bumper
                     if self.speed.norm() < 100:
                         self.set_speed(self.speed.normalize(100.0))
                     self.state.change(aerial=1.0)
                 if self.race.track.type(c) is BOOST and self.speed.norm() < 300.0:
                     # touch a booster
                     self.set_speed(self.speed.normalize(300.0))
     self.set_position(new_position)
Exemplo n.º 7
0
 def move(self, new_position):
     """move the car"""
     path = bresenham(self.position, new_position)
     for i, c in enumerate(path):
         if not self.state.aerial:  # a flying car can move over anything
             if self.race.track.type(c, hit=True) is WALL:
                 # hit a wall
                 if i == 0:
                     # car is stuck in a wall
                     return self.lakitu()
                 else:
                     # the car bounces against the wall
                     if path[i - 1][0] != c[0]:
                         self.set_speed(Vector(-.5 * self.speed.x, .5 * self.speed.y))
                     else:
                         self.set_speed(Vector(.5 * self.speed.x, -.5 * self.speed.y))
                     new_position = self.position  # do not move
                 break
             if not self.state.jump:
                 if self.race.track.type(c) is DEEP:
                     # car is in a hole
                     return self.lakitu()
                 if self.racer.item is ITEMS[0] and self.race.track.type(c, special=True) is ITEM:
                     # the car touched an item block
                     block = self.race.track.item_blocks[(c[0], c[1])]  # find the block that was touched
                     if not block.delay:
                         block.activate()
                         self.racer.get_item()
                 if self.race.track.type(c) is JUMP:
                     # touch a bumper
                     if self.speed.norm() < 100:
                         self.set_speed(self.speed.normalize(100.))
                     self.state.change(aerial=1.)
                 if self.race.track.type(c) is BOOST and self.speed.norm() < 300.:
                     # touch a booster
                     self.set_speed(self.speed.normalize(300.))
     self.set_position(new_position)
Exemplo n.º 8
0
 def update(self, dt):
     track = self.race.track
     current_position = self.position
     move = self.get_direction_vector() * self.speed * dt
     new_position = current_position + move
     path = bresenham(current_position, new_position)
     for i, c in enumerate(path):
         if track.type(c, hit=True) is WALL:
             # the shell bounces
             if c[0] != path[i - 1][0]:  # vertical wall
                 self.direction = -self.direction + math.pi
             else:  # horizontal wall
                 self.direction = -self.direction
             new_position = current_position  # don't move
             self.set_speed(self.speed - 15.)  # slow down after each bounce
             if self.speed <= 40:
                 return self.remove(
                 )  # if the shell becomes too slow it disappears
             break
         elif track.type(new_position) is DEEP:
             # the shell disappears
             return self.remove()
     self.set_position(new_position)
     self.check_collisions()