Esempio n. 1
0
 private void SetupPlayer(IContentHelper contentHelper)
 {
     player = new Player();
     player.LoadContent(contentHelper);
     currentWeapon = new Weapon(weaponStartPosition, player);
     currentWeapon.LoadContent(contentHelper);
 }
        public Action <TimeSpan, IBasePlayer> GetTimedAction(BaseEnemy enemy, IBasePlayer player, BaseVerticalShooter.GameModel.IBaseMap gameMap)
        {
            var action = new Action <TimeSpan, IBasePlayer>((t, p) =>
            {
                if (enemy.State == CharacterState.Alive)
                {
                    if (accumulatedTime > Milestones.Last().End)
                    {
                        accumulatedTime = TimeSpan.FromSeconds(0);
                    }

                    var milestone    = GetCurrentMilestone();
                    this.RoutineType = milestone.RoutineType;

                    var milestoneExists = (milestone.Start != milestone.End);
                    if (milestoneExists && milestone.RoutineType == RoutineType.Walk)
                    {
                        Walk(enemy, gameMap, t);
                    }

                    accumulatedTime = accumulatedTime.Add(t);
                    enemy.CheckReload();
                }
            });

            return(action);
        }
Esempio n. 3
0
 public override void UpdateDirection(IBasePlayer player, IBaseMap gameMap)
 {
     if (wasHit)
     {
         Direction    = new Vector2(0, 1);
         PixelsPerSec = 10;
     }
     else
     {
         if (isDescending)
         {
             Direction    = new Vector2(0, 1);
             PixelsPerSec = 1;
         }
         else
         {
             if (Position.X <= GameSettings.Instance.WindowTilesSize.X / 4)
             {
                 Direction = new Vector2(1, 0);
             }
             else if (Position.X >= (GameSettings.Instance.WindowTilesSize.X - GameSettings.Instance.WindowTilesSize.X / 4))
             {
                 Direction = new Vector2(-1, 0);
             }
         }
     }
 }
Esempio n. 4
0
 public PlayerBullet5(float damage, IBasePlayer player, Vector2 direction, float rotation, bool shouldPlaySound)
     : base(damage, player)
 {
     this.direction       = direction;
     this.rotation        = rotation;
     this.shouldPlaySound = shouldPlaySound;
 }
        public override void LoadContent(IContentHelper contentHelper)
        {
            player = new Player();
            player.LoadContent(contentHelper);

            base.LoadContent(contentHelper);
        }
Esempio n. 6
0
 public override EnemyBullet GetBullet(IBasePlayer player, IBaseMap gameMap)
 {
     bullet           = GetBulletByEnemyNumber();
     bullet.Direction = this.Direction;
     bullet.Owner     = this;
     this.Reloaded    = true;
     return(bullet);
 }
Esempio n. 7
0
 public PowerUp(Vector2 position, IBasePlayer player)
     : base()
 {
     Size           = new Vector2(2, 2);
     StartPosition  =
         Position   = position;
     this.player    = player;
     this.screenPad = BaseResolver.Instance.Resolve <IScreenPad>();
 }
 public PlayerBullet(float damage, IBasePlayer player)
     : base(damage)
 {
     Size        = new Vector2(1, 1);
     speed       = .4f;
     this.damage = damage;
     this.player = player;
     direction   = new Vector2(0, -1);
 }
        public virtual EnemyBullet GetBullet(IBasePlayer player, IBaseMap gameMap)
        {
            var bullet = new EnemyBullet(this.Position, 0);

            bullet.direction = this.Direction;
            bullet.Owner     = this;
            //this.Reloaded = false;
            return(bullet);
        }
Esempio n. 10
0
        public virtual EnemyBullet GetBullet(IBasePlayer player, IBaseMap gameMap)
        {
            var bullet       = new EnemyBullet2(this.Position + this.Size / 2, 0);
            var newDirection = new Vector2(player.Position.X - bullet.Position.X, (player.Position.Y + gameMap.ScrollRows) - bullet.Position.Y) + player.Size / 2;

            newDirection.Normalize();
            bullet.Direction = newDirection;
            reloaded         = false;
            return(bullet);
        }
Esempio n. 11
0
        public override EnemyBullet GetBullet(IBasePlayer player, IBaseMap gameMap)
        {
            var bullet       = new EnemyBullet2(this.Position, 0);
            var newDirection = new Vector2(player.Position.X - this.Position.X, (player.Position.Y + gameMap.ScrollRows) - this.Position.Y) + player.Size / 2;

            newDirection.Normalize();
            bullet.Direction = newDirection;
            bullet.Owner     = this;
            this.Reloaded    = false;
            return(bullet);
        }
Esempio n. 12
0
        private void ExecuteTimedAction(Microsoft.Xna.Framework.GameTime gameTime, IBasePlayer player, Action <TimeSpan, IBasePlayer> action)
        {
            accumElapsedGameTime = accumElapsedGameTime.Add(gameTime.ElapsedGameTime);
            if (accumElapsedGameTime >= TimeSpan.FromMilliseconds(tickInMS))
            {
                var time = accumElapsedGameTime;

                action(time, player);
                accumElapsedGameTime = TimeSpan.FromSeconds(0);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// This will be called from all players that has the following statement executed:
 /// player.CardExchangeAnnouncement += AnnotatePlayersOfCardExchange;
 /// In each players Play() method there should be a callback to here, just to announce
 /// the card swap between two players. It should look like:
 /// CardExchangeAnnouncement?.Invoke(this, opponent, value, recieved);
 /// Where "this" identifies the current player, "opponent" the player that is asked for the cards
 /// "value" is the card value requested and "recieved" is the cards recieved from the opponent
 /// </summary>
 /// <param name="cardReciever">The player asking for a card</param>
 /// <param name="cardSender">The player being asked</param>
 /// <param name="cardValue">Card value asked for</param>
 /// <param name="returnResult">Collection of cards that is returned from cardSender</param>
 public void AnnotatePlayersOfCardExchange(IBasePlayer cardReciever, IBasePlayer cardSender, Values cardValue, IEnumerable <Card> returnResult)
 {
     // Tell every player that two players have asked for and handed over cards.
     // This is just to let all players know that a card swap has happened and what
     // cards where swapped.
     // ReturnResult is the cards that were handed over. cardValue is the value which was asked for.
     foreach (IBasePlayer player in players)
     {
         player.OtherPlayersPlayed(cardReciever, cardSender, cardValue, returnResult);
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Begins the game and creates the players.
        /// </summary>
        public void Run()
        {
            // Get players and initialize them with deck and opponents
            players = startMenu.Execute();

            foreach (IBasePlayer player in players)
            {
                // Assign the deck to each player so they could pull cards
                player.CurrentDeck = cardController;
                // Make sure each player gets aware of the opponents
                player.Opponents = players.Where(p => p.PlayerName != player.PlayerName);
                // Attach a callback delegate to each player to enable callback when cardswapping happens
                player.CardExchangeAnnouncementCallback += AnnotatePlayersOfCardExchange;
            }


            IBasePlayer winner = null;

            while (winner == null)
            {
                for (int current = 0; current < players.Count(); current++)
                {
                    IBasePlayer currentPlayer = players.ToArray()[current];

                    // If player has 0 cards on hand and deck has 0 cards left then skip to next player
                    // continue will continue with next value of the for loop
                    if (currentPlayer.CardsLeftOnHand == 0 && currentPlayer.CurrentDeck.CardsLeft == 0)
                    {
                        continue;
                    }

                    currentPlayer.Play();
                }

                if (AllPlayersOutOfCards(players))
                {
                    winner = players.OrderByDescending(p => p.OnTheTable.Count).First();
                    Console.WriteLine($"Winner is: {winner.PlayerName}");
                    Console.WriteLine($"OnTheHand: {winner.CardsLeftOnHand} cards");
                    Console.WriteLine($"OnTheTable: {winner.OnTheTable.Count} cards");

                    foreach (var player in players.OrderByDescending(p => p.OnTheTable.Count))
                    {
                        Console.WriteLine($"Player: {player.PlayerName}, {player.OnTheTable.Count} on the table, {player.CardsLeftOnHand} on the hand.");
                    }
                }
            }
        }
Esempio n. 15
0
        public override void UpdateDirection(IBasePlayer player, IBaseMap gameMap)
        {
            if ((this.Position.X / 2) == (int)(this.Position.X / 2) ||
                (this.Position.Y / 2) == (int)(this.Position.Y / 2))
            {
                var newDirection = new Vector2(player.Position.X - this.Position.X, (player.Position.Y + gameMap.ScrollRows) - this.Position.Y) + player.Size / 2;
                if (onWindowTicks / (changeDirectionInMS / tickInMS) % 2 == 0)
                {
                    newDirection = new Vector2(newDirection.X, 0);
                }
                else
                {
                    newDirection = new Vector2(0, newDirection.Y);
                }

                newDirection.Normalize();
                this.Direction = newDirection;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Begins the game and creates the players.
        /// </summary>
        public void Run()
        {
            // Get players and initialize them with deck and opponents
            players = sm.Execute();

            foreach (IBasePlayer player in players)
            {
                // Assign the deck to each player so they could pull cards
                player.CurrentDeck = deck;
                // Make sure each player gets aware of the opponents
                player.Opponents = players.Where(p => p.PlayerName != player.PlayerName);
                // Attach a callback delegate to each player to enable callback when cardswapping happens
                player.CardExchangeAnnouncement += AnnotatePlayersOfCardExchange;
            }


            IBasePlayer winner = null;

            while (winner == null)
            {
                for (int current = 0; current < players.Count(); current++)
                {
                    //TODO! Test for empty deck
                    //TODO! If empty deck, test for different player amount of cards in OnTheTable
                    IBasePlayer currentPlayer = players.ToArray()[current];
                    if (!currentPlayer.Play())
                    {
                        Console.WriteLine($"player {currentPlayer} is out");
                        players = players.Where(p => p.GetType().Name != currentPlayer.GetType().Name);
                        current--;
                    }
                    if (players.Count() == 1)
                    {
                        winner = players.ToArray()[0];
                        break;
                    }
                }
            }
            Console.WriteLine($"Winner is {winner}");
        }
Esempio n. 17
0
        public override void UpdateDirection(IBasePlayer player, IBaseMap gameMap)
        {
            if (State == CharacterState.Alive &&
                gameMap.State == MapState.Scrolling &&
                ((this.Position.X / 2) == (int)(this.Position.X / 2) ||
                 (this.Position.Y / 2) == (int)(this.Position.Y / 2)))
            {
                var target = new Vector2(player.Position.X >= GameSettings.Instance.WindowTilesSize.X / 2 ? 0 : GameSettings.Instance.WindowTilesSize.X, (player.Position.Y + gameMap.ScrollRows));

                var newDirection = new Vector2(target.X - this.Position.X, target.Y - this.Position.Y) + this.Size / 2;
                if (onWindowTicks / (changeDirectionInMS / tickInMS) % 2 == 0)
                {
                    newDirection = new Vector2(newDirection.X, 0);
                }
                else
                {
                    newDirection = new Vector2(0, newDirection.Y);
                }

                newDirection.Normalize();
                this.Direction = newDirection;
            }
        }
        public Action <TimeSpan, BaseVerticalShooter.GameModel.IBasePlayer> GetTimedAction(BaseEnemy bullet, IBasePlayer player, IBaseMap gameMap)
        {
            var action = new Action <TimeSpan, IBasePlayer>((t, p) =>
            {
                if (bullet.State == CharacterState.Alive)
                {
                    var candidateWindowPosition =
                        bullet.OnWindowPosition
                        + bullet.Direction * (float)t.TotalSeconds * bullet.PixelsPerSec;
                    //var mapCollisionType = bullet.CheckMapCollision(gameMap, candidateWindowPosition);
                    //if (mapCollisionType == CollisionType.None)
                    //{
                    bullet.OnWindowPosition = candidateWindowPosition;
                    //}
                    //else
                    //{
                    //    bullet.State = CharacterState.Dead;
                    //}
                }
            });

            return(action);
        }
Esempio n. 19
0
 void Start()
 {
     _basePlayer = GetComponent <PlayableCharacter>().player;
     CalculateAttributePoints();
     Debug.Log(ToString());
 }
Esempio n. 20
0
 public virtual void UpdateDirection(IBasePlayer player, IBaseMap gameMap)
 {
     this.player = player;
 }
Esempio n. 21
0
 void Awake()
 {
     player = BasePlayer.GetInstance();
 }
Esempio n. 22
0
        public Action <TimeSpan, BaseVerticalShooter.GameModel.IBasePlayer> GetTimedAction(BaseEnemy enemy, IBasePlayer player, IBaseMap gameMap)
        {
            var thisBullet = enemy as EnemyBullet;
            var action     = new Action <TimeSpan, IBasePlayer>((t, p) =>
            {
                if (thisBullet.Owner != null &&
                    ((BaseEnemy)thisBullet.Owner).State == CharacterState.Alive)
                {
                    if (thisBullet.State == CharacterState.Alive)
                    {
                        var range = (thisBullet.Owner.Size * GameSettings.Instance.MapTileWidth) / 2f;
                        thisBullet.RadPosition     += thisBullet.RevsPerSec * ((float)t.TotalMilliseconds / 1000f) * (2f * (float)Math.PI);
                        var candidateWindowPosition =
                            ((thisBullet.Owner.Position + thisBullet.Size - new Vector2(0, gameMap.ScrollRows))
                             * thisBullet.TileWidth)
                            + range * new Vector2((float)Math.Cos(thisBullet.RadPosition), -(float)Math.Sin(thisBullet.RadPosition));

                        thisBullet.Rotation = -thisBullet.RadPosition;

                        //var mapCollisionType = CheckMapCollision(gameMap, candidateWindowPosition);
                        //if (mapCollisionType == CollisionType.None)
                        //{
                        thisBullet.OnWindowPosition = candidateWindowPosition;
                        //}
                        //else
                        //{
                        //    this.State = CharacterState.Dead;
                        //}
                        ((BaseEnemy)thisBullet.Owner).Reloaded = false;
                    }
                }

                if (thisBullet.Owner != null &&
                    ((BaseEnemy)thisBullet.Owner).State
                    == CharacterState.Dead)
                {
                    thisBullet.State = CharacterState.Dead;
                }
            });

            return(action);
        }
Esempio n. 23
0
 public PlayerBullet1(float damage, IBasePlayer player)
     : base(damage, player)
 {
     Size = new Vector2(1, 1);
 }
Esempio n. 24
0
 void Start()
 {
     _player = GetComponent <PlayableCharacter>().player;
 }
Esempio n. 25
0
 public PlayerBullet4(float damage, IBasePlayer player)
     : base(damage, player)
 {
 }
Esempio n. 26
0
 public PlayerBullet6(float damage, IBasePlayer player)
     : base(damage, player)
 {
     speed     = 20f;
     screenPad = Resolver.Instance.Resolve <IScreenPad>();
 }