Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
def main(screen):

    input_service = InputService(screen)
    output_service = OutputService(screen)
    director = Director(input_service, output_service)
    director.start_game()