private static GameTile[] CreateHomeTiles(float distance, float tileSize, float angle, int i, Vector2 tilePosition, float angleOffset, CanvasBitmap sprite, GameRace gameRace, GameTile previousTile, GameTile gameTile) { List <GameTile> homeTiles = new List <GameTile>(); GameTile previousHomeTile = CreateTile(sprite, tilePosition, tileSize, (bitmap, scale) => Scaler.ImgUniform(bitmap, scale), gameRace, previousTile); homeTiles.Add(previousHomeTile); for (int j = 1; j < 5; j++) { Vector2 homeTilePosition = new Vector2(MathF.Sin(angle * (i + j) + angleOffset) * (distance - (distance / 6) * (j)), MathF.Cos(angle * (i + j) + angleOffset) * (distance - (distance / 6) * (j))); previousHomeTile = CreateTile(sprite, homeTilePosition, tileSize, (bitmap, scale) => Scaler.ImgUniform(bitmap, scale), gameRace, previousHomeTile); homeTiles.Add(previousHomeTile); } homeTiles[homeTiles.Count - 1].nextTile = gameTile; return(homeTiles.ToArray()); }
//public static bool MoveToGameTile(int diceResult, GamePiece gamePiece) //{ // if (gamePiece.isAvailableMove) // { // for (int i = 0; i < diceResult; i++) // Calls the change tile funk or each number on the dice // { // //await Task.Delay(400); // ChangeTile(gamePiece, diceResult);// Changes tile the amount of times the loop goes. // if (diceResult - 1 == i) // { // CheckIfHitGamePiece(gamePiece); // gamePiece.isAvailableMove = false; // return true; // } // } // return true; // } // else // { // return false; // } //} /// <summary> /// Tries to move the piece /// </summary> /// <param name="tileSpeed">Speed in coordinates per second to move the piece</param> /// <returns>If it successfully moved</returns> public static bool TryMovingPiece(float tileSpeed) { bool aPieceIsMoving = false; foreach (GamePiece piece in GameEngine.gamePieces) { if (piece.tile != piece.moveToTile && piece.moveToTile != null) { aPieceIsMoving = true; GameTile nextTile = piece.tile.GetNextTile(piece.race); // if the piece is closer than the threshold snapp to the tile if (Vector2Math.Magnitude(nextTile.Position - piece.Position) < 5) { piece.Position = nextTile.Position; piece.tile = nextTile; if (piece.tile == piece.moveToTile) { CheckIfHitGamePiece(piece); Wormhole.CheckIfHitWormhole(piece); if (piece.moveToTile.GetNextTile(piece.race) == null) { Done(piece); } } } else { piece.Position += Vector2Math.Normalized(nextTile.Position - piece.Position) * tileSpeed * (float)GameEngine.GameCanvas.TargetElapsedTime.TotalSeconds; } break; } } return(aPieceIsMoving); }
/// <summary> /// Creates all of the game tiles /// </summary> /// <param name="sprites">a reference to the GameEngine sprites</param> /// <returns></returns> public static GameTile[] CreateGameTiles(Dictionary <string, CanvasBitmap> sprites) // this should be cleaned up { const int gameTileCount = 12 * 4; const int homeLocation = gameTileCount / 8; const int redHome = 1; const int greenHome = homeLocation * 2 + 1; const int yellowHome = homeLocation * 4; const int blueHome = homeLocation * 6; float baseLocation = 800; float distance = 900; float tileSize = 1; float angle = 360.0f / gameTileCount * MathF.PI / 180.0f; float angleOffset = 45 * MathF.PI / 180; List <GameTile> gameTiles = new List <GameTile>(); GameTile previousTile = null; GameTile[] homeTiles = null; GameTile blackhole = CreateTile(sprites["blackhole"], Vector2.Zero, 0.3f, (bitmap, scale) => Scaler.ImgUniform(bitmap, scale), GameRace.None, null); for (int i = 0; i < gameTileCount; i++) { Vector2 tilePosition = new Vector2(MathF.Sin(angle * i + angleOffset) * distance, MathF.Cos(angle * i + angleOffset) * distance); switch (i) { case redHome: homeTiles = CreateHomeTiles(distance, tileSize, angle, i, tilePosition, angleOffset, sprites["redTile"], (GameRace)1, previousTile, blackhole); gameTiles.AddRange(homeTiles); previousTile = homeTiles[0]; break; case greenHome: homeTiles = CreateHomeTiles(distance, tileSize, angle, i, tilePosition, angleOffset, sprites["greenTile"], (GameRace)2, previousTile, blackhole); gameTiles.AddRange(homeTiles); previousTile = homeTiles[0]; break; case yellowHome: homeTiles = CreateHomeTiles(distance, tileSize, angle, i, tilePosition, angleOffset, sprites["yellowTile"], (GameRace)3, previousTile, blackhole); gameTiles.AddRange(homeTiles); previousTile = homeTiles[0]; break; case blueHome: homeTiles = CreateHomeTiles(distance, tileSize, angle, i, tilePosition, angleOffset, sprites["blueTile"], (GameRace)4, previousTile, blackhole); gameTiles.AddRange(homeTiles); previousTile = homeTiles[0]; break; default: previousTile = CreateTile(sprites["whiteTile"], tilePosition, tileSize, (bitmap, scale) => Scaler.ImgUniform(bitmap, scale), 0, previousTile); gameTiles.Add(previousTile); break; } } gameTiles[0].previousTile = gameTiles[gameTiles.Count - 1]; CreateBaseTile(sprites["redBase"], gameTiles, new Vector2(baseLocation, baseLocation), (GameRace)1, redHome); CreateBaseTile(sprites["greenBase"], gameTiles, new Vector2(baseLocation, -baseLocation), (GameRace)2, greenHome + 4); CreateBaseTile(sprites["yellowBase"], gameTiles, new Vector2(-baseLocation, -baseLocation), (GameRace)3, yellowHome + 8); CreateBaseTile(sprites["blueBase"], gameTiles, new Vector2(-baseLocation, baseLocation), (GameRace)4, blueHome + 12); gameTiles.Add(blackhole); return(gameTiles.ToArray()); }
public GameTile(Drawable drawable, GameRace raceHome, GameTile previousTile) { this.drawable = drawable; this.raceHome = raceHome; this.previousTile = previousTile; }
private static GameTile CreateTile(CanvasBitmap image, Vector2 position, float imageScale, Drawable.Scale scalerMethood, GameRace gameRace, GameTile previousTile) { Drawable newTile = new Drawable(image, position, imageScale, scalerMethood); GameEngine.drawables.Add(newTile); return(new GameTile(newTile, gameRace, previousTile)); }
/// <summary> /// Creates a single game piece and the drawable that it needs to be drawn /// </summary> /// <param name="race">The race of the player</param> /// <param name="sprite">The prite used for the game pieces</param> /// <param name="offsetPosition">The position to place the pieces when at baseTile</param> /// <returns>The created game piece</returns> private static GamePiece CreateGamePiece(GameRace race, CanvasBitmap sprite, Vector2 offsetPosition, GameTile baseTile) { Drawable draw = new Drawable(sprite, baseTile.Position + offsetPosition, 1, (bitmap, scale) => Scaler.ImgUniform(bitmap, scale)); GameEngine.drawables.Add(draw); return(new GamePiece(race, offsetPosition, baseTile, draw)); }
/// <summary> /// Creates all of the necesairy game pieces for a player /// </summary> /// <param name="race">The race of the player</param> /// <param name="sprite">The prite used for the game pieces</param> /// <param name="offset">The distance from the center of the baseTile to place the pieces when at baseTile</param> /// <returns>The created game pieces</returns> public static GamePiece[] CreateGamePieces(GameRace race, CanvasBitmap sprite, float offset, GameTile baseTile) { GamePiece[] gamePieces = { CreateGamePiece(race, sprite, new Vector2(offset, offset), baseTile), CreateGamePiece(race, sprite, new Vector2(-offset, -offset), baseTile), CreateGamePiece(race, sprite, new Vector2(offset, -offset), baseTile), CreateGamePiece(race, sprite, new Vector2(-offset, offset), baseTile) }; return(gamePieces); }