private void SetWantedDirection(PlayingPiece piece, Keys[] pressedKeys) { Vector2 direction = Vector2.Zero; //Console.WriteLine("SetWantedDirection() for " + piece.Role); Vector2 potentialTarget = Vector2.Zero; //Console.WriteLine("Keyspressed: "); foreach (Keys keyPressed in pressedKeys) { if (PlayerKeys[piece].Contains(keyPressed)) { direction += KeyDirections[keyPressed]; //Console.Write("[contained], " + KeyDirections[keyPressed]); potentialTarget += KeyDirections[keyPressed] * tileSize; } } //if both vertical and horizontal keys are pressed if (direction.X * direction.Y != 0) { direction.Y = 0; } potentialTarget = piece.Position + direction * tileSize; if (!TileIsClear(potentialTarget)) { direction = Vector2.Zero; } piece.Direction = direction; }
private void MovePiece(PlayingPiece piece, float elapsedMilliseconds) { //Vector2 directionToMove = new Vector2(Math.Sign(piece.Direction.X - piece.Position.X), Math.Sign(piece.Direction.Y - piece.Position.Y)); if (piece.Direction != Vector2.Zero) { Vector2 newPosition = GetNewPosition(piece, elapsedMilliseconds); Point index = GetIndexInArray(piece.Position); Tile currentTile = currentLevel.Tiles[index.X, index.Y]; Vector2 centerOfTilePlayerIsIn = currentTile.TileCenter; if (piece.Position != centerOfTilePlayerIsIn && centerOfTilePlayerIsIn.IsBetween(piece.Position, newPosition)) { if (currentTile.Type == TileType.Teleporter) { piece.Position = currentLevel.TeleporterTiles[currentTile].TileCenter; } else { piece.Position = centerOfTilePlayerIsIn; piece.Direction = Vector2.Zero; } } else { piece.Position = newPosition; } } }
private void SetRandomValidDirectionButNotPrevious(PlayingPiece clone) { bool newDirectionFound = false; int tries = 0; Vector2 newPosition = clone.Position + clone.Direction * tileSize; if (clone.Direction == Vector2.Zero || (clone.Direction != Vector2.Zero && !TileIsClear(newPosition))) { do { Vector2 direction = Directions.GetRandomDirection(); Vector2 alternateNewPosition = clone.Position + direction * tileSize; if (TileIsClear(alternateNewPosition)) { if (clone.PreviousDirection == (direction * -1) && tries < 20) { tries++; continue; } clone.Direction = direction; newDirectionFound = true; } } while (!newDirectionFound); } }
private void AddClone(PlayingPiece player) { if (clones.Count < maxSimultaneousClones && clonesLeft > 0) { clones.Add((PlayingPiece)player.Clone()); clonesLeft--; } }
public override object Clone() { PlayingPiece clone = new PlayingPiece(Game, Texture, Role, Speed); clone.Direction = this.Direction; clone.Points = this.Points; clone.ShadowOffset = this.ShadowOffset; clone.TextureOffset = this.TextureOffset; clone.Scale = this.Scale; clone.Position = this.Position; return(clone); }
private void SwitchRoles() { foreach (PlayingPiece piece in pieces) { piece.ToggleRole(); if (piece.Role == Role.Hunted) { piece.Speed = huntedSpeed; } else { piece.Speed = hunterSpeed; } piece.Texture = piece.Role == Role.Hunted ? white : black; } hunter = Adversary[hunter]; }
private void SetRandomValidDirection(PlayingPiece clone) { bool newDirectionFound = false; Vector2 newPosition = clone.Position + clone.Direction * tileSize; if (clone.Direction == Vector2.Zero || (clone.Direction != Vector2.Zero && !TileIsClear(newPosition))) { do { Vector2 direction = Directions.GetRandomDirection(); Vector2 alternateNewPosition = clone.Position + direction * tileSize; if (TileIsClear(alternateNewPosition)) { clone.Direction = direction; newDirectionFound = true; } } while (!newDirectionFound); } }
private void DoCollisionDetection() { PlayingPiece hunter = GetCurrentHunter(); for (int i = clones.Count - 1; i >= 0; i--) { PlayingPiece clone = clones[i]; if (Vector2.Distance(clone.Position, hunter.Position) < tileSize * .75) { //Clone Kill if (soundEffect.Count > 0) { soundEffect[random.Next(0, soundEffect.Count)].Play(0.5f, 0f, 0f); } pops.Add(new SmallPop(250, clone.Position)); clones.Remove(clone); } } if (Vector2.Distance(player1.Position, player2.Position) < tileSize * .8) { sound_monster.Play(); BeginLevel(); } if (!currentLevel.TeleportersOpen) { foreach (PlayingPiece piece in pieces) { if (Vector2.Distance(piece.Position, currentLevel.KeyTile.TileCenter) < tileSize * 0.8F) { currentLevel.KeyTile.Type = TileType.Open; sound_OpenTeleports.Play(); currentLevel.OpenTeleporters(); } } } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); //add spritebatch to services for use in GameSprite this.Services.AddService(typeof(SpriteBatch), spriteBatch); tile = Content.Load <Texture2D>("tile"); black = Content.Load <Texture2D>("black"); white = Content.Load <Texture2D>("white"); key = Content.Load <Texture2D>("key"); pop = Content.Load <Texture2D>("pop"); tex_introduction = Content.Load <Texture2D>("chasingdotstitle"); tex_winPlayer1 = Content.Load <Texture2D>("player1wins"); tex_winPlayer2 = Content.Load <Texture2D>("player2wins"); texture_draw = Content.Load <Texture2D>("draw"); texture_help = Content.Load <Texture2D>("help"); texture_ready = Content.Load <Texture2D>("ready"); player1 = new PlayingPiece(this, white, Role.Hunter, huntedSpeed); player2 = new PlayingPiece(this, black, Role.Hunted, hunterSpeed); pieces[0] = player1; pieces[1] = player2; foreach (PlayingPiece piece in pieces) { piece.Position = Vector2.One * -200; } hunter = player1; Adversary[player1] = player2; Adversary[player2] = player1; #region Sound SoundEffect introsong = Content.Load <SoundEffect>("Audio/HowlingTheme_intro"); sound_music_intro = introsong.CreateInstance(); soundEffect.Add(Content.Load <SoundEffect>("Audio/blub1")); soundEffect.Add(Content.Load <SoundEffect>("Audio/blub2")); soundEffect.Add(Content.Load <SoundEffect>("Audio/blub3")); SoundEffect music_a = Content.Load <SoundEffect>("Audio/HowlingTheme_A"); sound_music_a = music_a.CreateInstance(); sound_music_a.IsLooped = true; texture_credits = Content.Load <Texture2D>("credits"); sound_OpenTeleports = Content.Load <SoundEffect>("Audio/openteleports"); sound_monster = Content.Load <SoundEffect>("Audio/Monster"); #endregion player1.SetSizeInPixels(tileSize * .8F); player2.SetSizeInPixels(tileSize * .8F); // TODO: use this.Content to load your game content here debugFont = Content.Load <SpriteFont>("debugFont"); standardFont = Content.Load <SpriteFont>("standardFont"); bigFont = Content.Load <SpriteFont>("bigFont"); KeyDirections.Add(Keys.Up, Directions.Up); KeyDirections.Add(Keys.Down, Directions.Down); KeyDirections.Add(Keys.Left, Directions.Left); KeyDirections.Add(Keys.Right, Directions.Right); KeyDirections.Add(Keys.W, Directions.Up); KeyDirections.Add(Keys.S, Directions.Down); KeyDirections.Add(Keys.A, Directions.Left); KeyDirections.Add(Keys.D, Directions.Right); List <Keys> player1Keys = new List <Keys>(); player1Keys.Add(Keys.W); player1Keys.Add(Keys.A); player1Keys.Add(Keys.S); player1Keys.Add(Keys.D); PlayerKeys.Add(player1, player1Keys); List <Keys> player2Keys = new List <Keys>(); player2Keys.Add(Keys.Up); player2Keys.Add(Keys.Down); player2Keys.Add(Keys.Left); player2Keys.Add(Keys.Right); PlayerKeys.Add(player2, player2Keys); sound_music_intro.Play(); }
private Vector2 GetNewPosition(PlayingPiece piece, float elapsedMilliseconds) { return(piece.Position + piece.Direction * piece.Speed * gameSpeed * elapsedMilliseconds); }
private void AddPoints(PlayingPiece piece) { piece.Points += (int)pointsPerSecond; }