Ejemplo n.º 1
0
	def parse(self):
		timesteps = self.contents.split("\n\n")
		self.timesteps = []
		i=1
		for ts in timesteps:
			table = Table(i) #let the rest default
			lines = ts.split("\n")
			del lines[0] #get rid of the timestep label
			for line in lines:
				segments = line.split(" ")
				try:
					puck = Puck(
						segments[0],
						segments[1],
						segments[2],
					) #let radius default
					puck.set_vx(segments[3])
					puck.set_vy(segments[4])
				except:
					continue

				table.set_puck(puck)
			timestep_instance = Timestep(table)
			self.timesteps.append(timestep_instance)
			i += 1
Ejemplo n.º 2
0
    def place_puck(self, x, y, vx=False, vy=False):
        table = self.get_table()

        p = Puck("candidate", x, y)
        if not self.can_place(p):
            print "ERROR: manually setting puck, overlapping pucks"
            return

        p.set_vx(vx)
        p.set_vy(vy)
        p.set_name(table.num_pucks() + 1)
        table.set_puck(p)
Ejemplo n.º 3
0
    def spawn_puck(self, velocity=False):
        table = self.get_table()

        candidate_x = random.random() * table.get_width()
        candidate_y = random.random() * table.get_height()

        p = Puck("candidate", candidate_x, candidate_y)
        while not self.can_place(p):
            candidate_x = random.random() * table.get_width()
            candidate_y = random.random() * table.get_height()

            p = Puck("candidate", candidate_x, candidate_y)
        if velocity:
            # -0.5 so that there's a chance they have a negative velocity
            p.set_velocity(Velocity(random.random() - 0.5, random.random() - 0.5))

        p.set_name(table.num_pucks() + 1)
        table.set_puck(p)