public static RobotConveyAction GetConvey(FlatDirection dir) { switch (dir) { case FlatDirection.North: default: { return(ConveyNorth); } case FlatDirection.East: { return(ConveyEast); } case FlatDirection.South: { return(ConveySouth); } case FlatDirection.West: { return(ConveyWest); } } }
public void PickTile(Tile tile, FlatDirection direction) { // Try to switch to an existing slot first for (int i = 0; i < m_sidebarLevels.Length; ++i) { var level = m_sidebarLevels[i]; if (level.Tiles[TileCoordinates.Zero] == tile) { m_selection = i; SetTileRotation(direction); StoreSettings(); RequestRebuild(); return; } } // Otherwise, change the current slot var sideBarLevel = m_sidebarLevels[m_selection]; sideBarLevel.Tiles.SetTile( TileCoordinates.Zero, tile, direction, false ); sideBarLevel.Tiles.Compress(); SetTileRotation(direction); StoreSettings(); }
public bool SetTile(TileCoordinates coordinates, Tile tile, FlatDirection direction = FlatDirection.North, bool notifyNeighbours = true) { var oldTile = GetTile(coordinates); var oldDirection = oldTile.GetDirection(m_level, coordinates); if (tile != oldTile || direction != oldDirection) { int oldSubState = oldTile.GetSubState(m_level, coordinates); ExpandToFit(coordinates); SetTileInternal(coordinates, tile, direction, 0); if (m_latestTimeStamp > 0.0f) { var change = new TileChange(); change.Type = TileChangeType.Tile; change.TimeStamp = m_latestTimeStamp; change.Coordinates = coordinates; change.OldTile = oldTile; change.OldDirection = oldDirection; change.OldSubState = oldSubState; m_history.Push(change); } if (notifyNeighbours) { tile.NotifyNeighboursChanged(m_level, coordinates); } return(true); } return(false); }
public static Side ToSide(this FlatDirection dir, FlatDirection forwardDir) { switch (forwardDir) { case FlatDirection.North: default: { return((Side)dir); } case FlatDirection.East: { return((Side)dir.RotateLeft()); } case FlatDirection.South: { return((Side)dir.Rotate180()); } case FlatDirection.West: { return((Side)dir.RotateRight()); } } }
public static Direction ToDirection(this Side side, FlatDirection forwardDir) { switch (forwardDir) { case FlatDirection.North: default: { return((Direction)side); } case FlatDirection.East: { return((Direction)ROTATE_RIGHT[(int)side]); } case FlatDirection.South: { return((Direction)ROTATE_180[(int)side]); } case FlatDirection.West: { return((Direction)ROTATE_LEFT[(int)side]); } } }
private bool PickTile(out Tile o_tile, out FlatDirection o_pickedDirection) { if (Dialog == null && !m_menuButton.TestMouse() && !m_saveButton.TestMouse() && !m_testButton.TestMouse() && m_titleText.TestMouse() < 0 && !m_tileSelect.TestMouse()) { var ray = BuildRay(Game.Screen.MousePosition, 100.0f); // Raycast against level TileCoordinates levelHitCoords; Direction levelHitSide; float levelHitDistance; bool levelHit = Level.RaycastTiles(ray, out levelHitCoords, out levelHitSide, out levelHitDistance); if (levelHit) { var baseCoords = Level.Tiles[levelHitCoords].GetBase(Level, levelHitCoords); o_tile = Level.Tiles[baseCoords]; o_pickedDirection = o_tile.GetDirection(Level, baseCoords); return(true); } } o_tile = default(Tile); o_pickedDirection = default(FlatDirection); return(false); }
public bool CanEnterOnSide(Robot.Robot robot, TileCoordinates coordinates, FlatDirection side, bool ignoreMovingObjects) { if (GetIncline(robot.Level, coordinates, side.Opposite()) <= 0 && IsSolidOnSide(robot.Level, coordinates, side.ToDirection())) { return(false); } if (IsOccupiedByNonVacatingRobot(robot.Level, coordinates, side, robot, ignoreMovingObjects)) { return(false); } var belowCoords = coordinates.Below(); var belowTile = robot.Level.Tiles[belowCoords]; if (belowTile.IsConveyor(robot.Level, belowCoords)) { var conveyor = (Conveyor)belowTile.GetEntity(robot.Level, belowCoords); var conveyorDirection = belowTile.GetDirection(robot.Level, belowCoords); if (conveyor.CurrentMode == ConveyorMode.Forwards) { return(side != conveyorDirection); } else if (conveyor.CurrentMode == ConveyorMode.Reverse) { return(side != conveyorDirection.Opposite()); } } return(true); }
public void Init(ILevel level, TileCoordinates coordinates, FlatDirection direction) { level.Tiles.GetState(coordinates).Direction = direction; for (int i = 1; i < m_height; ++i) { level.Tiles.SetTile(coordinates.Move(Direction.Up, i), Tiles.Extension, direction, false); } OnInit(level, coordinates); }
public RobotState( Robot robot, int seed, TileCoordinates position, FlatDirection direction, TurnDirection turnPreference, RobotAction action ) : this(robot, seed, position, direction, turnPreference, action, 0.0f, 0, position) { }
private void SetTileInternal(TileCoordinates coordinates, Tile tile, FlatDirection direction, int subState) { Tile oldTile = m_tiles[coordinates.X - m_xOrigin, coordinates.Y - m_yOrigin, coordinates.Z - m_zOrigin]; oldTile.Shutdown(m_level, coordinates); m_tiles[coordinates.X - m_xOrigin, coordinates.Y - m_yOrigin, coordinates.Z - m_zOrigin] = tile; SetSubStateInternal(coordinates, subState); tile.Init(m_level, coordinates, direction); m_geometryNeedsRebuild = true; }
public void SetTile(Tile tile, FlatDirection direction) { if (tile != Tile || direction != Direction) { Unhide(); m_subLevel.Tiles.SetTile( m_subLevel.Tiles.Origin, tile, direction, false ); Hide(); } }
public static Matrix4 BuildTransform(TileCoordinates coordinates, FlatDirection direction) { if (direction != FlatDirection.North) { return (Matrix4.CreateTranslation(-0.5f, 0.0f, -0.5f) * Matrix4.CreateRotationY(direction.ToYaw()) * Matrix4.CreateTranslation((float)coordinates.X + 0.5f, (float)coordinates.Y * 0.5f, (float)coordinates.Z + 0.5f)); } else { return (Matrix4.CreateTranslation((float)coordinates.X, (float)coordinates.Y * 0.5f, (float)coordinates.Z)); } }
public static FlatDirection Rotate(this FlatDirection dir, TurnDirection turnDir) { switch (turnDir) { case TurnDirection.Left: { return(dir.RotateLeft()); } case TurnDirection.Right: default: { return(dir.RotateRight()); } } }
public static int GetWalkIncline(Robot robot, TileCoordinates position, FlatDirection direction) { var level = robot.Level; var here = position; var below = here.Below(); int incline = Math.Min(level.Tiles[below].GetIncline(level, below, direction), 0); if (incline < 0 && !CanEnter(robot, here.Move(direction).Move(Direction.Up, incline), direction, false)) { incline = 0; } var destination = here.Move(direction).Move(Direction.Up, incline); incline += level.Tiles[destination].GetIncline(level, destination, direction); return(incline); }
public int GetIncline(ILevel level, TileCoordinates coordinates, FlatDirection side) { var baseCoords = GetBase(level, coordinates); int baseIncline; var baseTile = level.Tiles[baseCoords]; var dir = baseTile.GetDirection(level, baseCoords); Side localSide = side.ToSide(dir); switch (localSide) { case Side.Front: default: { baseIncline = baseTile.m_forwardIncline; break; } case Side.Right: { baseIncline = baseTile.m_rightIncline; break; } case Side.Left: { baseIncline = -baseTile.m_rightIncline; break; } case Side.Back: { baseIncline = -baseTile.m_forwardIncline; break; } } int height = baseTile.Height; int location = coordinates.Y - baseCoords.Y; if (location >= height - Math.Abs(baseIncline)) { return(baseIncline); } return(0); }
private void StoreSettings() { var palette = new string[SIDEBAR_ROWS]; var directions = new FlatDirection[SIDEBAR_ROWS]; for (int i = 0; i < SIDEBAR_ROWS; ++i) { var level = m_sidebarLevels[i]; var tile = level.Tiles[TileCoordinates.Zero]; palette[i] = tile.Path; directions[i] = tile.GetDirection(level, TileCoordinates.Zero); } m_settings.EditorPalette = palette; m_settings.EditorDirections = directions; m_settings.EditorSelection = m_selection; m_settings.EditorPage = m_palettePage; m_settings.Save(); }
public Robot.Robot CreateRobot(ILevel level, TileCoordinates coordinates, FlatDirection direction, RobotAction action) { return(new Robot.Robot( coordinates, direction, m_colour, m_immobile, m_required, action, m_guiColour, m_turnPreference, RobotModel, (m_robotAnimSet != null ? AnimSet.Get(m_robotAnimSet) : null), (m_robotSoundSet != null ? SoundSet.Get(m_robotSoundSet) : null), m_robotLightColour, m_robotLightRadius, Tile.RenderPass, Tile.CastShadows )); }
public Robot(TileCoordinates position, FlatDirection direction, string colour, bool immobile, bool required, RobotAction initialAction, Vector3 guiColour, TurnDirection turnPreference, Model model, AnimSet animations, SoundSet sounds, Vector3?lightColour, float?lightRadius, RenderPass renderPass, bool castShadows) { m_colour = colour; m_immobile = immobile; m_required = required; m_spawnAction = initialAction; m_spawnPosition = position; m_spawnDirection = direction; m_turnPreference = turnPreference; if (lightColour.HasValue && lightRadius.HasValue) { m_lightColour = lightColour.Value; m_light = new PointLight(Vector3.Zero, lightColour.Value, lightRadius.Value); } m_modelInstance = new ModelInstance(model, Matrix4.Identity); m_animations = animations; m_sounds = sounds; m_guiColour = guiColour; m_renderPass = renderPass; m_castShadows = castShadows; }
private void SetTileRotation(FlatDirection direction) { var sideBarLevel = m_sidebarLevels[m_selection]; sideBarLevel.Tiles.SetTile( TileCoordinates.Zero, sideBarLevel.Tiles[TileCoordinates.Zero], direction, false ); for (int i = 0; i < m_paletteLevels.Length; ++i) { var level = m_paletteLevels[i]; level.Tiles.SetTile( TileCoordinates.Zero, level.Tiles[TileCoordinates.Zero], direction ); } }
private RobotState( Robot robot, int seed, TileCoordinates position, FlatDirection direction, TurnDirection turnPreference, RobotAction action, float timeStamp, int walkIncline, TileCoordinates teleportDestination ) { Robot = robot; Level = robot.Level; RandomSeed = seed; Position = position; Direction = direction; TurnPreference = turnPreference; Action = action; TimeStamp = timeStamp; WalkIncline = walkIncline; TeleportDestination = teleportDestination; }
public static FlatDirection Rotate180(this FlatDirection dir) { return((FlatDirection)OPPOSITE[(int)dir]); }
public TileCoordinates Move(FlatDirection dir, int distance) { return(new TileCoordinates(X + dir.GetX() * distance, Y, Z + dir.GetZ() * distance)); }
public static FlatDirection Opposite(this FlatDirection dir) { return((FlatDirection)OPPOSITE[(int)dir]); }
public static float ToYaw(this FlatDirection dir) { float halfPi = (float)Math.PI * 0.5f; return(-(float)dir * halfPi); }
public TileCoordinates Move(FlatDirection dir) { return(new TileCoordinates(X + dir.GetX(), Y, Z + dir.GetZ())); }
public TurntableState(TurntableMode mode, FlatDirection direction, float timeStamp) { Mode = mode; Direction = direction; TimeStamp = timeStamp; }
public RobotConveyAction(FlatDirection direction) { m_direction = direction; }
public FallingTile(Tile tile, TileCoordinates coordinates, FlatDirection direction) : base(tile, coordinates) { m_direction = direction; }
public override void OnSteppedOn(ILevel level, TileCoordinates coordinates, Robot.Robot robot, FlatDirection direction) { if (m_colour == null || robot.Colour == m_colour) { switch (m_type) { case ButtonType.Momentary: case ButtonType.Latch: { if (!IsPowered(level, coordinates)) { SetPowered(level, coordinates, true, true); if (m_soundPath != null) { level.Audio.PlaySound(m_soundPath); } } break; } case ButtonType.Directional: { OnDirectionalStepOnOff(level, coordinates, direction); break; } case ButtonType.Toggle: { SetPowered(level, coordinates, !IsPowered(level, coordinates), true); if (m_soundPath != null) { level.Audio.PlaySound(m_soundPath); } break; } } } }
private void OnDirectionalStepOnOff(ILevel level, TileCoordinates coordinates, FlatDirection direction) { var tileDirection = level.Tiles[coordinates].GetDirection(level, coordinates); if (direction == (m_inverted ? tileDirection.Opposite() : tileDirection)) { if (IsPowered(level, coordinates)) { SetPowered(level, coordinates, false, true); if (m_soundPath != null) { level.Audio.PlaySound(m_soundPath); } } } else if (direction == (m_inverted ? tileDirection : tileDirection.Opposite())) { if (!IsPowered(level, coordinates)) { SetPowered(level, coordinates, true, true); if (m_soundPath != null) { level.Audio.PlaySound(m_soundPath); } } } }