コード例 #1
0
ファイル: game.py プロジェクト: Toofifty/prototype
def init():
    particle.init()

    render.add_screen_sprites(cursor, cursor.hover_text)

    map.load_map("2")

    camera.init(map.width(), map.height())
コード例 #2
0
    def __init__(self,):
        super(TestScene1, self).__init__()

        self.render_sys = RenderSystem()
        self.player_move_sys = PlayerMovementSystem()
        self.player_animation_sys = PlayerAnimationSystem()
        self.fps_text_sys = FpsTextSystem("Terminus.ttf", self.fps)
        self.collision_sys = CollisionDetectionSystem()
        self.event_sys = EventSystem()
        self.camera_sys = CameraSystem()

        # Test Map
        tiles_list = load_map("tallmap.tmx", "mg")
        for tile in tiles_list:
            self.render_sys.register(tile)

            if tile.is_collidable:
                self.collision_sys.register(tile)

            self.camera_sys.register(tile)

        # Test Player
        self.player = SewerMan((40, 40))
        self.render_sys.register(self.player)
        self.player_animation_sys.register(self.player)
        self.player_move_sys.register(self.player)
        self.collision_sys.register(self.player)
        self.event_sys.register(
            self.player,
            [
                "up_pressed",
                "down_pressed",
                "left_pressed",
                "right_pressed",
                "up_released",
                "down_released",
                "left_released",
                "right_released",
            ],
        )
        self.camera_sys.register(self.player)

        # multiple entities
        for i in range(6, 6 * 2 + 1, 6):
            player = SewerMan((i * 10, 40))
            self.render_sys.register(player)
            self.player_animation_sys.register(player)
            self.player_move_sys.register(player)
            self.collision_sys.register(player)
            self.camera_sys.register(player)

        # Test Fps Text
        self.fps_text = Text((5, 5), (0, 0, 255))
        self.render_sys.register(self.fps_text)
        self.fps_text_sys.register(self.fps_text)

        self.cam = Camera(WIN_WIDTH, WIN_HEIGHT, WIN_WIDTH / 2, WIN_HEIGHT / 2, 7.5, 7.5)
        self.camera_sys.register_camera(self.cam)
        self.render_sys.register_camera(self.cam)
        self.cam.follow(self.player)
コード例 #3
0
ファイル: adventure.py プロジェクト: dawran6/adventure
def main():
    load_map()
    drop_gold()
    update()
    while True:
        pressedkey = getch().lower()
        if pressedkey == 'q':
            clear()
            sys.exit(0)
        elif pressedkey == 'w':
            go(MOVE['UP'])
        elif pressedkey == 'a':
            go(MOVE['LEFT'])
        elif pressedkey == 's':
            go(MOVE['DOWN'])
        elif pressedkey == 'd':
            go(MOVE['RIGHT'])
コード例 #4
0
ファイル: world.py プロジェクト: arximboldi/jagsat
def create_game (cfg):
    """
    Creates a game from a ConfNode containing the following childs:
      - player-X: with X \in [0, 5], contains the properties for
        player number X. See create_player.
      - map: Contains the path to the map file.
    """
    
    players = []
    for i in range (0, 6):
        pcfg = cfg.child ('player-' + str (i))
        if pcfg.child ('enabled').value:
            players.append (create_player (pcfg))

    map_ = load_map (cfg.child ('map').value)
    
    world = World (map_, players)
    world.use_on_attack = cfg.child ('use-on-attack').value
    world.use_on_move   = cfg.child ('use-on-move').value
    world.name          = cfg.name
    
    return world
コード例 #5
0
    def __init__(
        self,
        map,
        robot_controller,
        init_position=None,
        steering_noise=0.01,
        color_noise=10,
        sonar_noise=0.1,
        distance_noise=0.001,
        forward_steering_drift=0,
        measurement_noise=0.2,
        speed=5.0,
        turning_speed=0.4 * pi,
        execution_cpu_time_limit=10.0,
        simulation_time_limit=10.0,
        simulation_dt=0.0,
        frame_dt=0.1,
        gps_delay=2.0,
        collision_threshold=50,
        iteration_write_frequency=1000,
        command_line=True,
        print_robot=True,
        seed=777,
        print_logger=False,
        accepted_commands=[TURN, MOVE, BEEP, FINISH, SENSE_COLOR],
    ):
        """
            Construct KrakrobotSimulator instancew

            :param steering_noise - variance of steering in move
            :param distance_noise - variance of distance in move
            :param measurement_noise - variance of measurement (GPS??)
            :param map - map for the robot simulator representing the maze or file to map
            :param init_position - starting position of the Robot (can be moved to map class) [x,y,heading]
            :param speed - distance travelled by one move action (cannot be bigger than 0.5, or he could traverse the walls)
            :param simulation_time_limit - limit in ms for whole robot execution (also with init)
            :param collision_threshold - maximum number of collisions after which robot is destroyed
            :param simulation_dt -  controlls simulation calculation intensivity
            :param frame_dt - save frame every dt
            :param robot - RobotController class that will be simulated in run procedure
        """

        if type(map) is str:
            self.map = load_map(map)
            for row in self.map["board"]:
                logger.info(row)
        else:
            self.map = map

        self.iteration_write_frequency = iteration_write_frequency

        self.collision_threshold = collision_threshold

        if init_position is not None:
            self.init_position = tuple(init_position)
        else:
            for i in xrange(self.map["N"]):
                for j in xrange(self.map["M"]):
                    if self.map["board"][i][j] == MAP_START_POSITION:
                        self.init_position = (i + 0.5, j + 0.5, 0)

        self.speed = speed
        self.seed = seed
        self.turning_speed = turning_speed
        self.simulation_dt = simulation_dt
        self.frame_dt = frame_dt
        self.robot_controller = robot_controller
        self.print_robot = print_robot
        self.print_logger = print_logger
        self.accepted_commands = accepted_commands

        self.command_line = command_line

        self.sonar_time = SONAR_TIME
        self.gps_delay = gps_delay
        self.light_sensor_time = LIGHT_SENSOR_TIME

        self.simulation_time_limit = simulation_time_limit
        self.execution_cpu_time_limit = execution_cpu_time_limit

        self.goal_threshold = 0.5  # When to declare goal reach

        self.color_noise = color_noise
        self.sonar_noise = sonar_noise
        self.distance_noise = distance_noise
        self.forward_steering_drift = forward_steering_drift
        self.measurement_noise = measurement_noise
        self.steering_noise = steering_noise
        self.reset()

        # TODO: Disable logger printing when needed
        if self.print_logger:
            logger.propagate = True
        else:
            logger.propagate = False

        for i in xrange(self.map["N"]):
            for j in xrange(self.map["M"]):
                if self.map["board"][i][j] == MAP_GOAL:
                    self.goal = (i, j)