def main(): cast = {} cast["cycles"] = [] cycle_x = 0 for _ in range(constants.NUM_CYCLES): trail = [] cycle_x += round(constants.MAX_X / (constants.NUM_CYCLES + 1)) position = Point(cycle_x, constants.CYCLE_Y) velocity = Point(0, constants.CYCLE_SPEED) cycle = Cycle(position, velocity, constants.CYCLE_IMAGE) trail.append(cycle) for j in range(1, constants.TRAIL_LENGTH + 1): if j == 1: k = constants.CYCLE_IMG_SCALE else: k = constants.TRAIL_IMG_SCALE position = Point(cycle_x, constants.CYCLE_Y - (j * k)) velocity = cycle.get_velocity() segment = Segment(position, velocity, constants.TRAIL_IMAGE) trail.append(segment) cast["cycles"].append(trail) obstacles = [] while len(obstacles) <= constants.NUM_OBST: x = random.randint(0 + constants.OBST_WIDTH, constants.MAX_X - constants.OBST_WIDTH) y = random.randint(0 + constants.OBST_HEIGHT, constants.MAX_Y - constants.OBST_HEIGHT) obstacle = Obstacle(x, y) for trail in cast["cycles"]: cycle = trail[0] if not obstacle.collides_with_sprite(cycle): if obstacles: for other in obstacles: if not obstacle.collides_with_sprite(other): obstacles.append(obstacle) else: obstacles.append(obstacle) cast["obstacles"] = obstacles script = {} input_service = InputService() output_service = OutputService() control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handles_collisions_action = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handles_collisions_action] script["output"] = [draw_actors_action] director = Director(cast, script, input_service) director.setup() arcade.run()
def main(): cast = {} cast["cycles"] = [] cycle_x = 0 for _ in range(constants.NUM_CYCLES): cycle_x += round(constants.MAX_X/(constants.NUM_CYCLES + 1)) cycle = Cycle(cycle_x, constants.CYCLE_Y, constants.CYCLE_IMAGE) cast["cycles"].append(cycle) """ TRAIL LOGIC """ cast["obstacles"] = [] while len(cast["obstacles"]) <= constants.NUM_OBST: x = random.randint(0 + constants.OBST_WIDTH ,constants.MAX_X - constants.OBST_WIDTH) y = random.randint(0 + constants.OBST_HEIGHT ,constants.MAX_Y - constants.OBST_HEIGHT) obstacle = Obstacle(x, y) for cycle in cast["cycles"]: if not obstacle.collides_with_sprite(cycle): if cast["obstacles"]: for other in cast["obstacles"]: if not obstacle.collides_with_sprite(other): cast["obstacles"].append(obstacle) else: cast["obstacles"].append(obstacle) script = {} input_service = InputService() output_service = OutputService() control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handles_collisions_action = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handles_collisions_action] script["output"] = [draw_actors_action] director = Director(cast,script,input_service) director.setup() arcade.run()
def main(): cast = {} cast["cycles"] = [] cast["obstacles"] = arcade.SpriteList() cycle_x = 0 for i in range(constants.NUM_CYCLES): trail = [] cycle_x += round(constants.MAX_X / (constants.NUM_CYCLES + 1)) position = Point(cycle_x, constants.CYCLE_Y) velocity = Point(0, constants.CYCLE_SPEED) if i == 0: img = constants.CYCLE_IMAGE else: img = constants.AI_IMAGE cycle = Cycle(position, velocity, img) trail.append(cycle) light_trail = arcade.SpriteList() trail.append(light_trail) cast["cycles"].append(trail) cast["obstacles"].append(cycle) script = {} input_service = InputService() output_service = OutputService() control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handles_collisions_action = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handles_collisions_action] script["output"] = [draw_actors_action] director = Director(cast, script, input_service) director.setup() arcade.run()
def main(): cast = {} cast["cycles"] = [] cycle_x = 0 for _ in range(constants.NUM_CYCLES): trail = [] cycle_x += round(constants.MAX_X / (constants.NUM_CYCLES + 1)) position = Point(cycle_x, constants.CYCLE_Y) velocity = Point(0, constants.CYCLE_SPEED) cycle = Cycle(position, velocity, constants.CYCLE_IMAGE) trail.append(cycle) light_trail = arcade.SpriteList() trail.append(light_trail) cast["cycles"].append(trail) """ obstacles = [] for i in range(constants.NUM_OBST): if i % 4 == 0: x1 = 0 x2 = constants.MAX_X / 2 y1 = constants.MAX_Y / 2 y2 = constants.MAX_Y elif i % 4 == 1: x1 = constants.MAX_X / 2 x2 = constants.MAX_X y1 = constants.MAX_Y / 2 y2 = constants.MAX_Y elif i % 4 == 2: x1 = constants.MAX_X / 2 x2 = constants.MAX_X y1 = 0 y2 = constants.MAX_Y / 2 elif i % 4 == 3: x1 = 0 x2 = constants.MAX_X / 2 y1 = 0 y2 = constants.MAX_Y / 2 x = random.randint(x1 + constants.OBST_WIDTH, x2 - constants.OBST_WIDTH) y = random.randint(y1 + constants.OBST_HEIGHT, y2 - constants.OBST_HEIGHT) obstacle = Obstacle(x, y) for trail in cast["cycles"]: cycle = trail[0] if not obstacle.collides_with_sprite(cycle): obstacles.append(obstacle) cast["obstacles"] = obstacles """ script = {} input_service = InputService() output_service = OutputService() control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handles_collisions_action = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handles_collisions_action] script["output"] = [draw_actors_action] director = Director(cast, script, input_service) director.setup() arcade.run()
def on_mouse_press(self, _x, _y, _button, _modifiers): """If mouse is pressed, start the game.""" director = Director(self._cast, self._script, self._input) director.setup() self.window.show_view(director)