Exemple #1
0
 public void Draw(SpriteBatch spriteBatch, Trooper trooper, List<Vector2> levelPositions)
 {
     foreach (var levelPosition in levelPositions.Where(p => Vector2.DistanceSquared(p, trooper.Position) <= trooper.Time * trooper.Time ))
     {
         DrawDistancePosition(spriteBatch, levelPosition, Vector2.DistanceSquared(levelPosition, trooper.Position), trooper.GetDistanceGrade(levelPosition));
     }
 }
Exemple #2
0
 private void DrawBullets(SpriteBatch spriteBatch, Trooper trooper)
 {
     foreach (var bullet in trooper.Weapon.GetAliveBullets())
     {
         _bulletView.Draw(spriteBatch, bullet);
     }
 }
Exemple #3
0
        public Bullet(Vector2 centerPosition,  Trooper target, int damage)
        {
            _startPosition = centerPosition;
            CurrentPosition = centerPosition;
            _targetPosition = target.CenterPosition;
            _direction = _targetPosition - CurrentPosition;
            _direction.Normalize();
            _target = target;
            IsAlive = true;
            _damage = damage;

            _age = 0;
        }
Exemple #4
0
        internal void Draw(SpriteBatch spriteBatch, GameTime gameTime, Trooper trooper,  List<Vector2> levelPositions)
        {
            DestinationRectangle = new Rectangle(Camera.TransformX(trooper.Position.X),
                    Camera.TransformY(trooper.Position.Y)
                    , Camera.TransformSizeX(trooper.Width)
                    , Camera.TransformSizeY(trooper.Height));

             //   spriteBatch.Draw(GameObjectTexture, new Vector2(camera.TransformX(trooper.Position.X), camera.TransformY(trooper.Position.Y)), null, Color.White, trooper.FaceDirection, origin:
            //camera.Transform(new Vector2(trooper.Width / 2,trooper.Height / 2)), effects: SpriteEffects.None, layerDepth: 0);
            //    spriteBatch.Draw(GameObjectTexture, DestinationRectangle, Color.White);

            DrawTrooper(spriteBatch, trooper, gameTime);
            DrawBullets(spriteBatch, trooper);

            if (trooper.Current)
            {
                DrawTileMark(spriteBatch, trooper);
                if(!trooper.IsControlledByComputer && !trooper.IsMoving)
                    _movementView.Draw(spriteBatch, trooper, levelPositions);
            }
        }
Exemple #5
0
        private void DrawTrooper(SpriteBatch spriteBatch, Trooper trooper, GameTime gameTime)
        {
            Vector2 origin = new Vector2(Camera.TransformSizeX(trooper.Width/2), Camera.TransformSizeY(trooper.Height/2));

            int x = DestinationRectangle.X + Camera.TransformSizeX(trooper.Width/2);
            int y = DestinationRectangle.Y + Camera.TransformSizeY(trooper.Height/2);
            spriteBatch.Draw(GameObjectTexture, new Rectangle(x, y, DestinationRectangle.Width, DestinationRectangle.Height),
                             GetTrooperSpriteSourceRectangle(trooper), Color.White, trooper.FaceDirection, origin,
                             SpriteEffects.None, 0);

            // left side - health
            var sourceRectangle = new Rectangle(0, 0, 2, _tileMark.Height);
            var leftDesinationRectangle = new Rectangle(DestinationRectangle.X, DestinationRectangle.Y, 2,
                                                        Convert.ToInt32(DestinationRectangle.Height * trooper.HealthPercent));
            spriteBatch.Draw(_tileMark, leftDesinationRectangle, sourceRectangle, Color.White);

            // right side - health
            sourceRectangle = new Rectangle(_tileMark.Height - 2, 0, 2, _tileMark.Height);
            // spriteBatch.Draw(_tileMark, DestinationRectangle, sourceRectangle, Color.White);
            var rightDesinationRectangle = new Rectangle(DestinationRectangle.X + _tileMark.Height - 9, DestinationRectangle.Y, 2,
                                                        Convert.ToInt32(DestinationRectangle.Height * trooper.HealthPercent));
            spriteBatch.Draw(_tileMark, rightDesinationRectangle, sourceRectangle, Color.White);
        }
Exemple #6
0
 private void DrawTileMark(SpriteBatch spriteBatch, Trooper trooper)
 {
     Rectangle? sourceRectangle = new Rectangle(2, 0, _tileMark.Height -4, _tileMark.Height);
     spriteBatch.Draw(_tileMark, DestinationRectangle, sourceRectangle, Color.White);
 }
Exemple #7
0
 private Rectangle? GetTrooperSpriteSourceRectangle(Trooper trooper)
 {
     int x = 0;
     if (trooper.GetType() == typeof (ComputerControlledTrooper))
         x = 20;
     return new Rectangle(x, 0, GameObjectTexture.Height, GameObjectTexture.Height);
 }
Exemple #8
0
 public void Fire(float faceDirection, Vector2 centerPosition, Trooper target)
 {
     _bullets.Add(new Bullet(centerPosition, target, CalculateDamage(centerPosition, target.CenterPosition, Dice.Roll())));
 }
Exemple #9
0
        private void UpdateWhoIsCurrent(Trooper trooper)
        {
            for (int i = 0; i < _troopers.Count(t => t.IsAlive); i++)
            {
                if (_troopers.Where(t => t.IsAlive).OrderByDescending(t => t.Speed).ElementAt(i).Current)
                {
                    _troopers.Where(t => t.IsAlive).OrderByDescending(t => t.Speed).ElementAt(i).Current = false;
                    _troopers.Where(t => t.IsAlive).OrderByDescending(t => t.Speed).ElementAt(i + 1 == _troopers.Count(t => t.IsAlive)? 0: i+1).Current = true;
                    return;
                }
            }

            //trooper.Current = false;
            //GetNextTrooper().Current = true;
            //SetNextActiveTrooper();
        }
Exemple #10
0
        private void UpdatePlayerControlledTrooper(GameTime gameTime, bool mouseClicked, Trooper trooper,
                                                   bool buildingIsBetweenCursorAndCurrentTrooper)
        {
            trooper.Update(gameTime, _cursor.CenterPosition, _cursor.Position,
                           !_cursor.BlockedByBuilding && !buildingIsBetweenCursorAndCurrentTrooper && mouseClicked &&
                           GetPlayerControlledTroopers().Count(t => t.Position.Equals(_cursor.Position)) == 0,
                           _cursor.MarksEnemyTrooper && !buildingIsBetweenCursorAndCurrentTrooper);
            if (_cursor.MarksEnemyTrooper)
            {
                trooper.ShootingTarget = GetTrooperOnPosition(_cursor.Position);
            }

            CheckForMedikits(trooper);

            CheckForAmmo(trooper);
        }
Exemple #11
0
 private void CheckForMedikits(Trooper trooper)
 {
     if (_mediKits.Count(m => m.Position.Equals(trooper.Position) && !m.IsTaken) > 0)
     {
         _mediKits.Find(m => m.Position.Equals(trooper.Position)).IsTaken = true;
         trooper.Heal();
     }
 }
Exemple #12
0
        private void CheckForAmmo(Trooper trooper)
        {
            if (_ammoClips.Count(a => a.Position.Equals(trooper.Position) && !a.IsTaken) > 0)
            {
                var ammoClip = _ammoClips.Find(a => a.Position.Equals(trooper.Position));
                ammoClip.IsTaken = true;
                trooper.AddAmmo(ammoClip.NumberOfBullets);

                if (_ammoClips.Count(a => !a.IsTaken) == 0)
                {
                    foreach (var ammo in _ammoClips.Where(a => !a.Position.Equals(trooper.Position)))
                    {
                        ammo.IsTaken = false;
                    }
                }
            }
        }