/// <summary> /// Erzeugt eine neue Instanz der <see cref="Track"/> Klasse. /// </summary> /// <param name="width">Die Breite des Tracks.</param> /// <param name="height">Die Höhe des Tracks.</param> /// <param name="goalPosition">Die Position des Ziels.</param> public Track(string name, int width, int height, Point goalPosition) { Name = name; Tiles = new TrackTile[width, height]; this.goalPosition = goalPosition; }
/// <summary> /// Lädt die Tiles einer Zeile der Eingabedatei. /// </summary> /// <param name="line">Die Eingabezeile.</param> /// <param name="tilesPerLine">Die Anzahl der Tiles in einer Zeile.</param> /// <param name="lineNumber">Die dazugehörige Zeilennummer.</param> /// <returns>Das geladene Array von <see cref="TrackTile"/>s.</returns> /// <exception cref="FormatException">Die Zeile darf nicht leer sein, muss genau so lang sein wie vorgesehen und darf nur Werte aus <see cref="TrackTile"/> enthalten.</exception> private static TrackTile[] GetTilesFromLine(string line, int tilesPerLine, int lineNumber) { if (line.Length == 0) { throw new FormatException("The file must not contain empty lines."); } if (line.Length != tilesPerLine) { throw new FormatException($"Line {lineNumber + 1} contains a deviating amount of tiles."); } var tilesForThisLine = new TrackTile[tilesPerLine]; for (var x = 0; x < line.Length; x++) { var tileTypeAsString = line.Substring(x, 1); int tileTypeAsInt; if (!int.TryParse(tileTypeAsString, NumberStyles.HexNumber, CultureInfo.CurrentCulture.NumberFormat, out tileTypeAsInt) || !Enum.IsDefined(typeof(TrackTile), tileTypeAsInt)) { throw new FormatException($"Line {lineNumber} contains a not supported tile identifier {tileTypeAsString}."); } var tileType = (TrackTile)tileTypeAsInt; if (tileType != default(TrackTile)) { tilesForThisLine[x] = tileType; } } return(tilesForThisLine); }
public static Data GenerateTrack(Mesh trackFloor, Mesh trackWall, Transform floorT) { if (trackFloor == null || trackWall == null) { return null; } GameObject genData = new GameObject("DATA"); Data data = genData.AddComponent<Data>(); genData.SetActive(false); data.dataParent = genData; data.sectionsObject = new GameObject("Sections"); data.sectionsObject.transform.parent = data.dataParent.transform; data.tilesObject = new GameObject("Tiles"); data.tilesObject.transform.parent = data.dataParent.transform; data.wallTilesObject = new GameObject("Wall Tiles"); data.wallTilesObject.transform.parent = data.dataParent.transform; GenerateTrackData gen = new GenerateTrackData(); gen.rebuildMesh(trackFloor); //gen.rebuildMesh(trackWall); // Vector3[] verts = trackFloor.vertices; TrackTile[] tiles = new TrackTile[2]; int[] tris = trackFloor.triangles; TrackTile[] mappedFloor = new TrackTile[tris.Length]; Vector3[] normals = trackFloor.normals; gen.createTiles(tris, verts, mappedFloor, floorT, data); gen.createSections(normals, verts, tiles, floorT, data); //gen.createRacingLine(); gen.createCheckpoints(); int sectionCount = data.sections.Count; for (int i = 0; i < sectionCount; ++i) { if (i == sectionCount - 1) data.sections[i].next = data.sections[0]; else data.sections[i].next = data.sections[i + 1]; } // //for (int i = 0; i < mappedFloor.Length; i++) //gen.tilesMapped.Add(mappedFloor[i]); // add mapped tiles to gendata data.mappedTiles = mappedFloor; // update data objects to reflect amount of data they hold data.tilesObject.name = string.Format("Tiles ({0})", data.tiles.Count); data.wallTilesObject.name = string.Format("Wall Tiles ({0})", data.tiles.Count); data.sectionsObject.name = string.Format("Sections ({0})", data.sections.Count); return data; }
/// <summary> /// Erzeugt eine neue Instanz der <see cref="Track"/> Klasse. /// </summary> /// <param name="width">Die Breite des Tracks.</param> /// <param name="height">Die Höhe des Tracks.</param> /// <param name="goalPosition">Die Position des Ziels.</param> public Track(string name, string key, int width, int height, Point goalPosition) { Name = name; Key = key; Tiles = new TrackTile[width, height]; this.goalPosition = goalPosition; }
public void SelectTrack(TrackTile selected) { Selected = selected; hasChoosenTrack = true; //Debug.Log(selected.name); if (FindObjectOfType <MapDisplay>().tileTracksIndex > 0) { Place(); } }
public void IsGoalTile_TileIsRoad() { //Arrange TrackTile myTile = TrackTile.Road; //Act bool result = myTile.IsGoalTile(); //Assert Assert.AreEqual(false, result); }
public void IsGoalTile_TileIsGoal() { //Arrange var myTile = new TrackTile(); myTile = TrackTile.GoalLeft; //Act bool result = myTile.IsGoalTile(); //Assert Assert.AreEqual(true, result); }
/// <summary> /// Lädt die Tiles einer Zeile der Eingabedatei. /// </summary> /// <param name="line">Die Eingabezeile.</param> /// <param name="tilesPerLine">Die Anzahl der Tiles in einer Zeile.</param> /// <param name="lineNumber">Die dazugehörige Zeilennummer.</param> /// <returns>Das geladene Array von <see cref="TrackTile"/>s.</returns> /// <exception cref="FormatException">Die Zeile darf nicht leer sein, muss genau so lang sein wie vorgesehen und darf nur Werte aus <see cref="TrackTile"/> enthalten.</exception> private static TrackTile[] GetTilesFromLine(string line, int tilesPerLine, int lineNumber) { if (line.Length == 0) { throw new FormatException("The file must not contain empty lines."); } if (line.Length != tilesPerLine) { throw new FormatException($"Line {lineNumber + 1} contains a deviating amount of tiles."); } var tilesForThisLine = new TrackTile[tilesPerLine]; for (var x = 0; x < line.Length; x++) { var tileTypeAsString = line.Substring(x, 1); int tileTypeAsInt; if (!int.TryParse(tileTypeAsString, out tileTypeAsInt) || !Enum.IsDefined(typeof(TrackTile), tileTypeAsInt)) { throw new FormatException($"Line {lineNumber} contains a not supported tile identifier {tileTypeAsString}."); } var tileType = (TrackTile)tileTypeAsInt; if (tileType != default(TrackTile)) { tilesForThisLine[x] = tileType; } } return tilesForThisLine; }
/// <summary> /// Erzeugt eine neue Instanz der <see cref="Track"/> Klasse. /// </summary> /// <param name="width">Die Breite des Tracks.</param> /// <param name="height">Die Höhe des Tracks.</param> public Track(int width, int height) { Tiles = new TrackTile[width, height]; }
public static Track LoadFromTxt(Stream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } using (StreamReader sr = new StreamReader(stream, Encoding.ASCII)) { if (sr.EndOfStream) { throw new FormatException("The file must not be empty."); } // reading the first line is outside the loop to calculate the size for the list string line = sr.ReadLine(); int tilesPerLine = line.Length; List<TrackTile[]> tiles = new List<TrackTile[]>((int)Math.Ceiling((float)stream.Length / line.Length)); for (int y = 0; ; y++, line = sr.ReadLine()) { if (line.Length == 0) { throw new FormatException("The file must not contain empty lines."); } if (line.Length != tilesPerLine) { throw new FormatException(string.Format("Line {0} contains a deviating amount of tiles.", y + 1)); } TrackTile[] tilesForThisLine = new TrackTile[tilesPerLine]; for (int x = 0; x < line.Length; x++) { string tileTypeAsString = line.Substring(x, 1); int tileTypeAsInt; if (!int.TryParse(tileTypeAsString, out tileTypeAsInt) || !Enum.IsDefined(typeof(TrackTile), tileTypeAsInt)) { throw new FormatException(string.Format("Line {0} contains a not supported tile identifier {1}.", y, tileTypeAsString)); } TrackTile tileType = (TrackTile)tileTypeAsInt; if (tileType != default(TrackTile)) { tilesForThisLine[x] = tileType; } } tiles.Add(tilesForThisLine); if (sr.EndOfStream) { break; } } Track result = new Track(tilesPerLine, tiles.Count); { int y = 0; foreach (TrackTile[] curTiles in tiles) { for (int x = 0; x < tilesPerLine; x++) { result.Tiles[x, y] = curTiles[x]; } y++; } } return result; } }
// Update is called once per frame void Update() { //if (racingLine == null) //racingLine = new TrackTile[RaceSettings.trackData.trackData.tilesMapped.Count]; if (cpHit.crash) ClearRacingLine(); RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit, 100.0f, 1 << LayerMask.NameToLayer("Track"))) { TrackTile newTile = TileFromTriangleIndex(hit.triangleIndex, RaceSettings.trackData.trackData.tiles); if (newTile != currentTile) { TrackTile start = new TrackTile(); start.position = transform.position; //racingLine[newTile.index] = start; Point p = new Point(); p.index = start.index; p.point = start.position; racingLine.Add(p); //Debug.DrawLine(racingLine[currentTile.index].position, racingLine[newTile.index].position, Color.cyan); currentTile = newTile; //Debug.Log(currentTile.index); } // Pintar la linea de carrea actual for (int i=0; i < racingLine.Count - 1; i++) { Point next = FindNextTile(racingLine, i + 1); if (racingLine[i] != null && next != null) Debug.DrawLine(racingLine[i].point, next.point, Color.magenta); } // Pintar la mejor linea de carrera for (int i = 0; i < bestLine.Count - 1; i++) { Debug.DrawLine(bestLine[i].point, bestLine[i + 1].point, Color.black); } // Guardar linea de carrera if (ship.currentLap != lap) { // Si el tiempo de la vuelta actual es el mejor if (ship.bestLap < bestLap) { XmlSerializer serializer = new XmlSerializer(typeof(PointContainer)); Debug.Log(Application.dataPath); FileStream stream = new FileStream(Application.dataPath + "/racinline.xml", FileMode.Create); PointContainer pc = new PointContainer(); pc.Points = racingLine; serializer.Serialize(stream, pc); stream.Close(); Debug.Log("FIN!" + racingLine.Count); bestLine = racingLine; bestLap = ship.bestLap; } lap = ship.currentLap; ClearRacingLine(); } } }
private void DrawTile(DrawingContext context, TrackTile type, int x, int y, Dictionary <TileType, ImageBrush> mapping) { bool left; bool upper; bool lower; bool right; bool upperLeft; bool upperRight; bool lowerLeft; bool lowerRight; if (type == TrackTile.Road) { left = game.Track.GetTileByIndex(x - 1, y).HasFlag(TrackTile.Road); upper = game.Track.GetTileByIndex(x, y - 1).HasFlag(TrackTile.Road); lower = game.Track.GetTileByIndex(x, y + 1).HasFlag(TrackTile.Road); right = game.Track.GetTileByIndex(x + 1, y).HasFlag(TrackTile.Road); upperLeft = game.Track.GetTileByIndex(x - 1, y - 1).HasFlag(TrackTile.Road); upperRight = game.Track.GetTileByIndex(x + 1, y - 1).HasFlag(TrackTile.Road); lowerLeft = game.Track.GetTileByIndex(x - 1, y + 1).HasFlag(TrackTile.Road); lowerRight = game.Track.GetTileByIndex(x + 1, y + 1).HasFlag(TrackTile.Road); } else { left = game.Track.GetTileByIndex(x - 1, y) == type; upper = game.Track.GetTileByIndex(x, y - 1) == type; lower = game.Track.GetTileByIndex(x, y + 1) == type; right = game.Track.GetTileByIndex(x + 1, y) == type; upperLeft = game.Track.GetTileByIndex(x - 1, y - 1) == type; upperRight = game.Track.GetTileByIndex(x + 1, y - 1) == type; lowerLeft = game.Track.GetTileByIndex(x - 1, y + 1) == type; lowerRight = game.Track.GetTileByIndex(x + 1, y + 1) == type; } #region Upper Left ImageBrush cell00 = mapping[TileType.Center]; if (!left) { if (!upper) { // konvexe linke ecke cell00 = mapping[TileType.UpperLeftConvex]; } else { // linke kante cell00 = mapping[TileType.Left]; } } else { if (!upper) { // obere Kante cell00 = mapping[TileType.Upper]; } else if (!upperLeft) { // linke konkave Ecke cell00 = mapping[TileType.UpperLeftConcave]; } } context.DrawRectangle(cell00, null, new Rect(x * Track.CELLSIZE, y * Track.CELLSIZE, Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion #region Upper Right ImageBrush cell10 = mapping[TileType.Center]; if (!right) { if (!upper) { // konvexe linke ecke cell10 = mapping[TileType.UpperRightConvex]; } else { // linke kante cell10 = mapping[TileType.Right]; } } else { if (!upper) { // obere Kante cell10 = mapping[TileType.Upper]; } else if (!upperRight) { // linke konkave Ecke cell10 = mapping[TileType.UpperRightConcave]; } } context.DrawRectangle(cell10, null, new Rect((x * Track.CELLSIZE) + (Track.CELLSIZE / 2), y * Track.CELLSIZE, Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion #region Lower Right ImageBrush cell11 = mapping[TileType.Center]; if (!right) { if (!lower) { // konvexe linke ecke cell11 = mapping[TileType.LowerRightConvex]; } else { // linke kante cell11 = mapping[TileType.Right]; } } else { if (!lower) { // obere Kante cell11 = mapping[TileType.Lower]; } else if (!lowerRight) { // linke konkave Ecke cell11 = mapping[TileType.LowerRightConcave]; } } context.DrawRectangle(cell11, null, new Rect((x * Track.CELLSIZE) + (Track.CELLSIZE / 2), (y * Track.CELLSIZE) + (Track.CELLSIZE / 2), Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion #region Lower Left ImageBrush cell01 = mapping[TileType.Center]; if (!left) { if (!lower) { // konvexe linke ecke cell01 = mapping[TileType.LowerLeftConvex]; } else { // linke kante cell01 = mapping[TileType.Left]; } } else { if (!lower) { // obere Kante cell01 = mapping[TileType.Lower]; } else if (!lowerLeft) { // linke konkave Ecke cell01 = mapping[TileType.LowerLeftConcave]; } } context.DrawRectangle(cell01, null, new Rect(x * Track.CELLSIZE, (y * Track.CELLSIZE) + (Track.CELLSIZE / 2), Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion }
private void DrawTile(DrawingContext context, TrackTile type, int x, int y, Dictionary<TileType, ImageBrush> mapping) { bool left; bool upper; bool lower; bool right; bool upperLeft; bool upperRight; bool lowerLeft; bool lowerRight; if (type == TrackTile.Road) { left = game.Track.GetTileByIndex(x - 1, y).HasFlag(TrackTile.Road); upper = game.Track.GetTileByIndex(x, y - 1).HasFlag(TrackTile.Road); lower = game.Track.GetTileByIndex(x, y + 1).HasFlag(TrackTile.Road); right = game.Track.GetTileByIndex(x + 1, y).HasFlag(TrackTile.Road); upperLeft = game.Track.GetTileByIndex(x - 1, y - 1).HasFlag(TrackTile.Road); upperRight = game.Track.GetTileByIndex(x + 1, y - 1).HasFlag(TrackTile.Road); lowerLeft = game.Track.GetTileByIndex(x - 1, y + 1).HasFlag(TrackTile.Road); lowerRight = game.Track.GetTileByIndex(x + 1, y + 1).HasFlag(TrackTile.Road); } else { left = game.Track.GetTileByIndex(x - 1, y) == type; upper = game.Track.GetTileByIndex(x, y - 1) == type; lower = game.Track.GetTileByIndex(x, y + 1) == type; right = game.Track.GetTileByIndex(x + 1, y) == type; upperLeft = game.Track.GetTileByIndex(x - 1, y - 1) == type; upperRight = game.Track.GetTileByIndex(x + 1, y - 1) == type; lowerLeft = game.Track.GetTileByIndex(x - 1, y + 1) == type; lowerRight = game.Track.GetTileByIndex(x + 1, y + 1) == type; } #region Upper Left ImageBrush cell00 = mapping[TileType.Center]; if (!left) { if (!upper) { // konvexe linke ecke cell00 = mapping[TileType.UpperLeftConvex]; } else { // linke kante cell00 = mapping[TileType.Left]; } } else { if (!upper) { // obere Kante cell00 = mapping[TileType.Upper]; } else if (!upperLeft) { // linke konkave Ecke cell00 = mapping[TileType.UpperLeftConcave]; } } context.DrawRectangle(cell00, null, new Rect(x * Track.CELLSIZE, y * Track.CELLSIZE, Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion #region Upper Right ImageBrush cell10 = mapping[TileType.Center]; if (!right) { if (!upper) { // konvexe linke ecke cell10 = mapping[TileType.UpperRightConvex]; } else { // linke kante cell10 = mapping[TileType.Right]; } } else { if (!upper) { // obere Kante cell10 = mapping[TileType.Upper]; } else if (!upperRight) { // linke konkave Ecke cell10 = mapping[TileType.UpperRightConcave]; } } context.DrawRectangle(cell10, null, new Rect((x * Track.CELLSIZE) + (Track.CELLSIZE / 2), y * Track.CELLSIZE, Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion #region Lower Right ImageBrush cell11 = mapping[TileType.Center]; if (!right) { if (!lower) { // konvexe linke ecke cell11 = mapping[TileType.LowerRightConvex]; } else { // linke kante cell11 = mapping[TileType.Right]; } } else { if (!lower) { // obere Kante cell11 = mapping[TileType.Lower]; } else if (!lowerRight) { // linke konkave Ecke cell11 = mapping[TileType.LowerRightConcave]; } } context.DrawRectangle(cell11, null, new Rect((x * Track.CELLSIZE) + (Track.CELLSIZE / 2), (y * Track.CELLSIZE) + (Track.CELLSIZE / 2), Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion #region Lower Left ImageBrush cell01 = mapping[TileType.Center]; if (!left) { if (!lower) { // konvexe linke ecke cell01 = mapping[TileType.LowerLeftConvex]; } else { // linke kante cell01 = mapping[TileType.Left]; } } else { if (!lower) { // obere Kante cell01 = mapping[TileType.Lower]; } else if (!lowerLeft) { // linke konkave Ecke cell01 = mapping[TileType.LowerLeftConcave]; } } context.DrawRectangle(cell01, null, new Rect(x * Track.CELLSIZE, (y * Track.CELLSIZE) + (Track.CELLSIZE / 2), Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion }
/// <summary> /// Prueft ob der <see cref="TrackTile"/> ein Ziel-Type ist. /// </summary> /// <param name="tile">Der <see cref="TrackTile"/> der geprueft werden soll.</param> /// <returns><c>true</c>, wenn der <see cref="TrackTile"/> ein Ziel-Type ist, andernfalls <c>false</c>.</returns> internal static bool IsGoalTile(this TrackTile tile) { return(((int)tile & 12) == 12); // siehe TrackTile.cs }
private TrackSegment createSection(Vector3[] normals, Vector3[] verts, TrackTile[] tiles, Transform floorT, Data gen, int i, int index) { TrackSegment newSection = new TrackSegment(); newSection = gen.sectionsObject.AddComponent<TrackSegment>(); newSection.hideFlags = HideFlags.HideInInspector; tiles[0] = gen.tiles[i]; tiles[1] = gen.tiles[i + 1]; newSection.type = E_SEGMENTTYPE.NORMAL; newSection.tiles = tiles; newSection.index = index; // Establecer la posicion de la seccion Vector3 position1 = floorT.transform.TransformPoint(verts[tiles[0].indices[0]]); Vector3 position2 = floorT.transform.TransformPoint(verts[tiles[1].indices[1]]); Vector3 positionMid = (position1 + position2) / 2; newSection.position = positionMid; // Establecer la normal de la seccion Vector3 normal1 = floorT.transform.TransformDirection(normals[tiles[0].indices[0]]); Vector3 normal2 = floorT.transform.TransformDirection(normals[tiles[1].indices[1]]); Vector3 normalMid = (normal1 + normal2) / 2; newSection.normal = normalMid; return newSection; }
private void createSections(Vector3[] normals, Vector3[] verts, TrackTile[] tiles, Transform floorT, Data gen) { // Crear las secciones del circuito TrackSegment newSection; int index = 0; for (int i = 0; i < gen.tiles.Count - 1; i += 2) { tiles[0] = gen.tiles[i + 0]; tiles[1] = gen.tiles[i + 1]; // Crear la seccion y añadirla a lista de secciones newSection = createSection(normals, verts, tiles, floorT, gen, i, index); gen.sections.Add(newSection); tiles[0].segment = newSection; tiles[1].segment = newSection; gen.tiles[i].segment = newSection; gen.tiles[i + 1].segment = newSection; index++; } // Configurar las siguientes secciones de cada seccion for (int i = 0; i < gen.sections.Count; i++) { if (i == gen.sections.Count - 1) gen.sections[i].next = gen.sections[0]; else gen.sections[i].next = gen.sections[i + 1]; } }
private void createTiles(int[] tris, Vector3[] verts, TrackTile[] mappedFloor, Transform floorT, Data gen) { // Crear tiles TrackTile newTile; int index = 0; for (int i = 0; i < tris.Length - 3; i += 6) { // Crear tile y añadirla a lista de tiles newTile = createTile(tris, verts, floorT, i, index, gen); gen.tiles.Add(newTile); mappedFloor[i + 0] = newTile; mappedFloor[i + 1] = newTile; mappedFloor[i + 2] = newTile; mappedFloor[i + 3] = newTile; index++; } }
private TrackTile createTile(int[] tris, Vector3[] verts, Transform floorT, int i, int index, Data data) { // Crear una tile TrackTile newTile = new TrackTile(); newTile = data.sectionsObject.AddComponent<TrackTile>(); newTile.hideFlags = HideFlags.HideInInspector; // Añadir los indices de la tile newTile.indices = new int[4]; newTile.indices[0] = tris[i + 0]; newTile.indices[1] = tris[i + 1]; newTile.indices[2] = tris[i + 2]; newTile.indices[3] = tris[i + 5]; newTile.type = E_TILETYPE.NORMAL; newTile.index = index; // Posicion media de los vertices Vector3 position1 = floorT.TransformPoint(verts[tris[i]]); Vector3 position2 = floorT.TransformPoint(verts[tris[i + 1]]); Vector3 positionMid = (position1 + position2) / 2; newTile.position = positionMid; return newTile; }
public void Update(TimeSpan totalTime, TimeSpan elapsedTime) { //lenkung if (Player1.WheelLeft) { Player1.Direction -= (float)elapsedTime.TotalSeconds * 1000000; } if (Player1.WheelRight) { Player1.Direction += (float)elapsedTime.TotalSeconds * 1000000; } //beschleunigung und bremsen float targetSpeed = 0f; if (Player1.Acceleration) { targetSpeed += 100; } if (Player1.Break) { targetSpeed -= 50; } int cellX = (int)(Player1.Position.X / Track.CELLSIZE); int cellY = (int)(Player1.Position.Y / Track.CELLSIZE); cellX = Math.Min(Track.Tiles.GetLength(0) - 1, Math.Max(0, cellX)); cellY = Math.Min(Track.Tiles.GetLength(1) - 1, Math.Max(0, cellY)); TrackTile tile = Track.Tiles[cellX, cellY]; switch (tile) { case TrackTile.Dirt: targetSpeed *= 0.2f; break; case TrackTile.Sand: targetSpeed *= 0.4f; break; case TrackTile.Gras: targetSpeed *= 0.8f; break; case TrackTile.Road: targetSpeed *= 1f; break; default: break; } if (targetSpeed > Player1.Velocity) { Player1.Velocity += 80 * (float)elapsedTime.TotalSeconds * 10000; Player1.Velocity = Math.Min(targetSpeed, Player1.Velocity); } if (targetSpeed < Player1.Velocity) { Player1.Velocity -= 100 * (float)elapsedTime.TotalSeconds * 10000; Player1.Velocity = Math.Max(targetSpeed, Player1.Velocity); } //positionsveränderung float direction = (float)(Player1.Direction * Math.PI) / 180f; Vector velocity = new Vector( Math.Sin(direction) * Player1.Velocity * elapsedTime.TotalSeconds * 10000, -Math.Cos(direction) * Player1.Velocity * elapsedTime.TotalSeconds * 10000 ); Player1.Position += velocity; Debug.WriteLine($"Player1.Position={Player1.Position}"); }
private void DrawTile(DrawingContext context, TrackTile type, int x, int y, Dictionary<TileType, Rect> mapping) { bool left = game.Track.GetTileByIndex(x - 1, y) == type; bool upper = game.Track.GetTileByIndex(x, y - 1) == type; bool lower = game.Track.GetTileByIndex(x, y + 1) == type; bool right = game.Track.GetTileByIndex(x + 1, y) == type; bool upperLeft = game.Track.GetTileByIndex(x - 1, y - 1) == type; bool upperRight = game.Track.GetTileByIndex(x + 1, y - 1) == type; bool lowerLeft = game.Track.GetTileByIndex(x - 1, y + 1) == type; bool lowerRight = game.Track.GetTileByIndex(x + 1, y + 1) == type; #region Upper Left Rect cell00 = mapping[TileType.Center]; if (!left) { if (!upper) { // konvexe linke ecke cell00 = mapping[TileType.UpperLeftConvex]; } else { // linke kante cell00 = mapping[TileType.Left]; } } else { if (!upper) { // obere Kante cell00 = mapping[TileType.Upper]; } else if (!upperLeft) { // linke konkave Ecke cell00 = mapping[TileType.UpperLeftConcave]; } } tilesBrush.Viewbox = cell00; context.DrawRectangle(tilesBrush, null, new Rect(x * Track.CELLSIZE, y * Track.CELLSIZE, Track.CELLSIZE / 2, Track.CELLSIZE / 2)); #endregion }