Пример #1
0
	def check_collision(self):
		board = self.board_vector()

		# Check collision of board with wall
		found = False
		if board.p1.x < 0:
			self.board.position.x = 0
			found = True
		elif board.p1.x > self.size[0]:
			self.board.position.x = self.size[0]
			found = True

		if found:
			vector = Vector(Point(0,0), self.board.direction)
			self.board.direction = vector.scale_absolute(3).vect
			return

		# Check collision of board with any obstacle
		found = False
		vector = Vector(Point(0,0), self.board.direction)
		cur = self.board.currently_on
		for ob in self.obstacles:
			if ob.check_collision(board.p1):
				if type(ob) == CircularObstacle:
					if cur == id(ob): break
					cur = self.board.speed()
					breaking = 1 - (ob.speed / 100)
					if cur * breaking > self.board.break_speed:
						self.board.direction = vector.scale_relative(breaking).vect

					self.board.currently_on = id(ob)
					break

				elif type(ob) == Boost:
					if cur == id(ob): break
					speed =  1 + float(ob.speed)/100
					if self.board.speed() * speed <= self.board.max_speed * 1.03:
						self.board.direction = vector.scale_relative(speed).vect

					self.board.currently_on = id(ob)
					break

				elif type(ob) == Rectangular:
					if cur == id(ob): break

					self.board.direction = vector.scale_absolute(1).vect

					self.board.currently_on = id(ob)
					break
		else:
			self.board.currently_on = False
Пример #2
0
	def on_tick(self):
		# Get the board vector
		board = self.board_vector().vect

		# Calculate the new direction
		player = self.player_vector().vect
		new_dir = board.transform(player)

		#You can not go backwards
		if new_dir.y < 0:
			new_dir.y = 0

		# You can only go a certain speed
		# and you are slowed down if above a certain speed
		vector = Vector(Point(0,0), new_dir)

		#scale = -1
		if vector.length() > self.break_speed:
			scale = float(vector.length()) - self.slowed
			new_dir = vector.scale_absolute(scale).vect

		if vector.length() > self.max_speed:
			# Jitter player
			change = random.uniform(-self.jitter, self.jitter) # * vector.length() / self.max_speed
			if abs(self.player + change) < self.max_lean:
				self.player += change

		new_pos = self.position.transform(new_dir)

		self.direction = new_dir
		self.position = new_pos
Пример #3
0
	def pump(self):
		if not self.pump_blocked:
			self.pump_blocked = True

			dir_vect = Vector(Point(0,0), self.direction)
			velocity = dir_vect.length()

			pump = self.pump_efficiency() * self.max_pump

			self.direction = dir_vect.scale_absolute(velocity + pump).vect