def load_next_level(self): level_number = 2 self.cast = {} player = Player() self.cast['player'] = [player] items = Items() self.cast['items'] = [items] background = BackgroundMaker(self.cast) maps = MapMaker(self.cast, level_number) score = Score() self.cast["score"] = [score] self.script = {} self.output_services = OutputServices() self.input_service = InputServices(self.cast) self.gravity_engine = Gravity(self.cast) handle_collisions = DoCollisionsAction(self.cast, self) screen_scrolling = ScreenScrollAction() control_actors = ControlActorsAction(self.input_service, self.gravity_engine) do_outputs = DrawActorsAction(self.output_services, screen_scrolling) do_updates = DoUpdatesAction(self.gravity_engine) self.script["input"] = [control_actors] self.script["update"] = [ do_updates, handle_collisions, screen_scrolling ] self.script["output"] = [do_outputs]
def main(screen): # create the cast {key: tag, value: list} cast = {} # create paddle x = int(constants.MAX_X / 2) y = int(constants.MAX_Y - 2) position = Point(x, y) paddle = Actor() paddle.set_text("===========") paddle.set_position(position) cast["paddle"] = [paddle] # create bricks cast["brick"] = [] for x in range(5, 75): for y in range(2, 6): position = Point(x, y) brick = Actor() brick.set_text("*") brick.set_position(position) cast["brick"].append(brick) #create ball x = int(constants.MAX_X / 2) y = int(constants.MAX_Y / 2) position = Point(x, y) velocity = Point(1, -1) ball = Actor() ball.set_text("@") ball.set_position(position) ball.set_velocity(velocity) cast["ball"] = [ball] position = Point(0, 0) score = Actor() score.set_text(f"Score: ") score.set_position(position) score.set_velocity(position) cast["score"] = [score] # create the script {key: tag, value: list} script = {} input_service = InputService(screen) output_service = OutputService(screen) control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handle_collisions_acition = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handle_collisions_acition] script["output"] = [draw_actors_action] # start the game director = Director(cast, script) director.start_game()
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"] = [] 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 trail_img = constants.CYCLE_TRAIL bck = constants.CYCLE_DOWN lft = constants.CYCLE_LEFT rgt = constants.CYCLE_RIGHT opponent = "Blue Cycle" else: img = constants.AI_IMAGE trail_img = constants.AI_TRAIL bck = constants.AI_DOWN lft = constants.AI_LEFT rgt = constants.AI_RIGHT opponent = "Yellow Cycle" cycle = Cycle(position,velocity,img,opponent) cycle.set_trail(trail_img) cycle.store_img(bck,'bck') cycle.store_img(lft,'lft') cycle.store_img(rgt,'rgt') 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] window = arcade.Window(constants.MAX_X, constants.MAX_Y, "TRON") start_view = Instructions(cast,script,input_service) window.show_view(start_view) arcade.run()
def main(screen): # create the cast {key: tag, value: list} cast = {} x = int(constants.MAX_X / 2) y = int(constants.MAX_Y - 1) position = Point(x, y) paddle = Player() paddle.set_position(position) cast["paddle"] = [paddle] cast["brick"] = [] for x in range(5, 75): for y in range(2, 6): position = Point(x, y) brick = Brick() brick.set_text("*") brick.set_position(position) cast["brick"].append(brick) x = int(constants.MAX_X / 2) y = int(constants.MAX_Y / 2) position = Point(x, y) velocity = Point(1, -1) ball = Ball() ball.set_text("@") ball.set_position(position) ball.set_starting_position(position) ball.set_velocity(velocity) cast["ball"] = [ball] score = Score() score.set_position(Point(4, 0)) cast["score"] = [score] lives = Lives() lives.set_position(Point(67, 0)) cast["lives"] = [lives] # create the script {key: tag, value: list} script = {} input_service = InputService(screen) output_service = OutputService(screen) control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handle_collisions_acition = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handle_collisions_acition] script["output"] = [draw_actors_action] # start the game director = Director(cast, script) director.start_game()
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"] = [] cast["obstacles"] = [] 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) cast["cycles"].append(cycle) """ TRAIL LOGIC """ for _ in range(constants.NUM_OBST): """ CHECK FOR OBSTACLE OVERLAP """ obst_x = random.randint(0, constants.MAX_X) obst_y = random.randint(0, constants.MAX_Y) obstacle = Obstacle(obst_x, obst_y) 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) batter.setup() arcade.run()
def main(): # create the cast {key: tag, value: list} cast = {} cast["players"] = [] cast["players"].append(Player("left", True)) cast["players"].append(Player("right", False)) # create the script {key: tag, value: list} script = {} control_actors_action = ControlActorsAction() move_actors_action = MoveActorsAction() handle_collisions_action = HandleCollisionsAction() key_release_action = KeyReleaseActon() draw_actors_action = DrawActorsAction() script[Director.ON_KEY_PRESS] = [control_actors_action] script[Director.ON_KEY_RELEASE] = [key_release_action] script[Director.ON_UPDATE] = [move_actors_action, handle_collisions_action] script[Director.ON_DRAW] = [draw_actors_action] # start the game director = Director(constants.MAX_X, constants.MAX_Y) director.direct_scene(cast, script) 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 main(): # create the cast {key: tag, value: list} cast = {} # add the tower tower = TowerSprite() cast["tower"] = [tower] # add the zombies cast['zombies'] = arcade.SpriteList() # add the wall cast["walls"] = arcade.SpriteList() # add the bullets cast["bullets"] = [] # add the turret cast["turrets"] = arcade.SpriteList() # add the hero hero = Hero(cast) cast["hero"] = [hero] melee = Melee(cast) cast["melee"] = [melee] # add the score score = Score() cast["score"] = [score] # add the resource counter resource_counter = ResourceCounter(200,50) cast['resource_counter'] = [resource_counter] # add the magic cast['magicks'] = arcade.SpriteList() # add the resources cast['resources'] = arcade.SpriteList() # create the script {key: tag, value: list} script = {} input_service = ArcadeInputService() output_service = ArcadeOutputService() control_actors_action = ControlActorsAction(input_service) move_actors_action = MoveActorsAction() handle_collisions_action = HandleCollisionsAction() draw_actors_action = DrawActorsAction(output_service) window = arcade.Window(constants.MAX_X, constants.MAX_Y, "Towerz") start_screen = StartView(cast, script, input_service) handle_lose_or_win = HandleLoseOrWinAction(window, start_screen, script) script["input"] = [control_actors_action] script["update"] = [move_actors_action, handle_collisions_action, handle_lose_or_win] script["output"] = [draw_actors_action] # start the game window.show_view(start_screen) arcade.run()