コード例 #1
0
ファイル: Level.cs プロジェクト: BasicLich/MizJam1-5
 private void DrawCells(SpriteBatch spriteBatch)
 {
     foreach (var layer in layers)
     {
         for (int i = 0; i < Height; i++)
         {
             for (int j = 0; j < Width; j++)
             {
                 Cell cell = layer[i, j];
                 if (cell.ID == 0)
                 {
                     continue;
                 }
                 Vector2 origin = new Vector2(Global.SpriteWidth / 2, Global.SpriteHeight / 2);
                 spriteBatch.Draw(
                     game.Textures[TextureIDInterpreter.GetTextureID(cell.ID)],
                     new Rectangle(j * Global.SpriteWidth + (int)origin.X, i * Global.SpriteHeight + (int)origin.Y, Global.SpriteWidth, Global.SpriteHeight),
                     TextureIDInterpreter.GetSourceRectangle(cell.ID),
                     Color.White,
                     cell.Rotation,
                     origin,
                     (cell.FlippedHorizontally ? SpriteEffects.FlipHorizontally : SpriteEffects.None) | (cell.FlippedVertically ? SpriteEffects.FlipVertically : SpriteEffects.None),
                     0f);
             }
         }
     }
 }
コード例 #2
0
ファイル: Level.cs プロジェクト: BasicLich/MizJam1-5
        public void Attack(Point attackingUnit, Point defendingUnit)
        {
            Unit att = GetUnit(attackingUnit);
            Unit def = GetUnit(defendingUnit);

            ushort baseAtt = att.Stats[Stats.Attack];
            bool   isMagic = false;

            if (att.Stats[Stats.Magic] > baseAtt)
            {
                isMagic = true;
                baseAtt = att.Stats[Stats.Magic];
            }
            int diceResult = rand.Next(1, 7);

            RollDiceAnimation rollDiceAnimation = new RollDiceAnimation(game.RedDice, CellToWorld(att.Position).Add(0, Global.SpriteHeight), (ushort)diceResult, baseAtt, true);

            animationQueue.Add(rollDiceAnimation, null);

            int damage = baseAtt + diceResult;

            ushort baseDef = def.Defending ? (ushort)7 : (isMagic ? def.Stats[Stats.MagicDefense] : def.Stats[Stats.Defense]);

            diceResult = rand.Next(1, 7);

            rollDiceAnimation = new RollDiceAnimation(game.BlueDice, CellToWorld(def.Position).Add(0, Global.SpriteHeight), (ushort)diceResult, baseDef, true);
            animationQueue.Add(rollDiceAnimation, null);

            int defense = baseDef + diceResult;


            int res = Math.Max(0, damage - defense);

            animationQueue.Add(new AttackAnimation((ushort)res), null);

            if (def.Health <= res)
            {
                Sprite skull = new Sprite(game.Textures[3], Global.SpriteSize, TextureIDInterpreter.GetSourceRectangle(567), Global.Colors.Main1);

                DeathAnimation deathAnimation = new DeathAnimation(CellToWorld(def.Position).Add(1), def.GetSprite(game.Textures), CellToWorld(def.Position.Sub(0, 1)), skull);
                animationQueue.Add(deathAnimation, def);
                units[def.Position.Y, def.Position.X] = null;
            }
            else
            {
                def.Health -= (ushort)res;
            }

            att.Acted = true;

            UnselectUnit();
            UnselectTiles();
        }
コード例 #3
0
ファイル: Level.cs プロジェクト: BasicLich/MizJam1-5
        private void DrawUnits(SpriteBatch spriteBatch)
        {
            int animation = ((int)animationTimer) / 500 % 2;

            if (SelectedUnit != null)
            {
                int borderAnimation = ((int)animationTimer) / 100 % 4;
                spriteBatch.Draw(
                    game.SelectedUnitBorder,
                    new Rectangle(CellToWorld(SelectedUnit.Position), Global.SpriteSize),
                    new Rectangle(new Point(Global.SpriteWidth * borderAnimation, 0), Global.SpriteSize),
                    Color.White);
            }

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    Unit unit = units[i, j];
                    if (unit == null || unit.Hide)
                    {
                        continue;
                    }
                    Color color1 = Global.Colors.Accent3;
                    Color color2 = Global.Colors.Accent2;
                    if (unit.Enemy)
                    {
                        color1 = Global.Colors.Accent4;
                        color2 = Global.Colors.Accent1;
                    }
                    Color currColor = color1;
                    if (!unit.Acted && animation == 1)
                    {
                        currColor = color2;
                    }

                    Vector2 origin = new Vector2(Global.UnitWidth / 2, Global.UnitHeight / 2);

                    spriteBatch.Draw(
                        game.Textures[TextureIDInterpreter.GetTextureID(unit.ID)],
                        new Rectangle(j * Global.SpriteWidth + (int)origin.X + 1, i * Global.SpriteHeight + (int)origin.Y + 1, Global.SpriteWidth - 2, Global.SpriteHeight - 2),
                        TextureIDInterpreter.GetUnitSourceRectangle(unit.ID),
                        currColor,
                        unit.Rotation,
                        origin,
                        (unit.FlippedHorizontally ? SpriteEffects.FlipHorizontally : SpriteEffects.None) | (unit.FlippedVertically ? SpriteEffects.FlipVertically : SpriteEffects.None),
                        0f);
                }
            }
        }
コード例 #4
0
ファイル: Level.cs プロジェクト: BasicLich/MizJam1-5
        public void Defend(Point defendingUnit)
        {
            Unit unit = GetUnit(defendingUnit);

            unit.Defending = true;
            unit.Acted     = true;

            DefendAnimation defendAnimation = new DefendAnimation(game.Textures[1], CellToWorld(unit.Position.Sub(0, 1)), TextureIDInterpreter.GetSourceRectangle(231));

            animationQueue.Add(defendAnimation, null);

            UnselectUnit();
            UnselectTiles();
        }