Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            #region Animations update

            List <UInt32> pairsToBeRemoved = new List <UInt32>();
            foreach (KeyValuePair <UInt32, List <AnimUnitMove> > kvp in _creatureAnimations)
            {
                AnimUnitMove current = kvp.Value.Last();
                current.Update();
                if (current.Expired())
                {
                    kvp.Value.RemoveAt(kvp.Value.Count - 1);
                    if (kvp.Value.Count == 0)
                    {
                        pairsToBeRemoved.Add(kvp.Key);
                    }
                }
            }
            foreach (UInt32 key in pairsToBeRemoved)
            {
                _creatureAnimations.Remove(key);
            }

            for (int i = 0; i < _animations.Count; ++i)
            {
                _animations[i].Update();
                if (_animations[i].Expired())
                {
                    _animations.RemoveAt(i);
                    --i;
                }
            }

            #endregion
        }
Beispiel #2
0
        private void DrawCreatures(SpriteBatch spriteBatch)
        {
            int tilesize = Constants.TileSize;
            int offset   = tilesize / 4;

            // CREATURES
            foreach (KeyValuePair <UInt32, Creature> kvp in _currentMap.Menagerie)
            {
                Creature  tenant            = kvp.Value;
                Texture2D tenantBitmap      = _creatures[(sbyte)tenant.MyBitmap];
                Int32     i                 = tenant.PositionGet().X;
                Int32     j                 = tenant.PositionGet().Y;
                Int16     visibilityTracker = _currentMap.MyVisibilityTracker.VisibilityCheck(tenant.PositionGet(), _myGame.PlayerTeam);
                Vector2   pos               = new Vector2(i * tilesize + (j % 2) * (tilesize / 2), j * tilesize - j * offset) + _screenAnchor;
                Rectangle rectHex           = ZoomTransform(new Rectangle((int)pos.X, (int)pos.Y, tilesize, tilesize));
                Rectangle rectCreature      = ZoomTransform(new Rectangle((int)pos.X, (int)pos.Y, tenantBitmap.Width, tenantBitmap.Height));

                if (tenant != null && (tenant.Team == _myGame.PlayerTeam || visibilityTracker > 0))
                {
                    // if the tenant is selected, draw selection box
                    if (_myInterface.SelectedCreature == tenant)
                    {
                        spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexRed], rectHex, Color.White);
                    }

                    // if the tenant is an enemy and within range of a friendly selected creature, draw an indication
                    if (_myInterface.SelectedCreature != null && _myInterface.SelectedCreature.Team == _myGame.PlayerTeam &&
                        tenant.Team != _myGame.PlayerTeam && _myInterface.SelectedCreature.GetAttackRange() >=
                        StaticMathFunctions.DistanceBetweenTwoCoordsHex(_myInterface.SelectedCreature.PositionGet(), tenant.PositionGet()))
                    {
                        spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexRed], rectHex, Color.Red);
                    }

                    // If there is an active animation for the creature, draw it.
                    if (_creatureAnimations.ContainsKey(tenant.UniqueID))
                    {
                        List <AnimUnitMove> currentStack = _creatureAnimations[tenant.UniqueID];
                        AnimUnitMove        current      = currentStack.Last();
                        current.Draw(spriteBatch, _screenAnchor, Color.White, _zoom);
                    }
                    // Otherwise, draw static sprite of the creature.
                    else
                    {
                        spriteBatch.Draw(_creatures[(sbyte)tenant.MyBitmap], rectCreature, Color.White);

                        //HP bar:
                        float   hpRatio     = (float)tenant.GetHP() / (float)tenant.GetHPMax();
                        Vector2 barLocation = pos;
                        barLocation.X += 3 * Constants.TileSize / 4;
                        barLocation.Y += (1 - hpRatio) * Constants.TileSize;
                        Color drawColor = Color.Lerp(Color.Red, Color.Green, hpRatio);
                        drawColor.A = 64;
                        spriteBatch.Draw(_particles[(sbyte)SpriteParticle.ParticlePixel], ZoomTransform(new Rectangle((int)barLocation.X,
                                                                                                                      (int)barLocation.Y, Constants.TileSize / 12, (int)(hpRatio * Constants.TileSize))), drawColor);
                    }
                }
            }
        }