/// <summary>
        /// Adds an Ice Spike status animation linked to the Entity's position.
        /// </summary>
        /// <param name="statusAnims">The Entity's list of Status Animations.</param>
        /// <param name="pos">The Entity's position.</param>
        private void HandleFreezeEffect(CStatusAnimations statusAnims, CPosition pos)
        {
            CStatusAnimation newStatusAnim;
            Bitmap           bmp;
            Animation        anim;
            AnimationScript  animScript;
            float            xOffset;
            float            yOffset;

            if (pos.Width <= 21)
            {
                bmp = SwinGame.BitmapNamed("SmallIceSpike");
            }
            else
            {
                bmp = SwinGame.BitmapNamed("BigIceSpike");
            }

            xOffset = (pos.Width / 2) - (bmp.CellWidth / 2);
            yOffset = pos.Height - bmp.CellHeight;

            anim       = SwinGame.CreateAnimation("Freeze", SwinGame.AnimationScriptNamed("IceSpikeAnim"));
            animScript = SwinGame.AnimationScriptNamed("IceSpikeAnim");

            newStatusAnim = new CStatusAnimation(typeof(CFrozen), xOffset, yOffset, bmp, anim, animScript);

            statusAnims.Anims.Add(newStatusAnim);
        }
        /// <summary>
        /// Adds a Poison Cloud status animation linked to the Entity's position.
        /// </summary>
        /// <param name="statusAnims">The Entity's list of Status Animations.</param>
        /// <param name="pos">The Entity's position.</param>
        private void HandlePoisonEffect(CStatusAnimations statusAnims, CPosition pos)
        {
            CStatusAnimation newStatusAnim;
            Bitmap           bmp;
            Animation        anim;
            AnimationScript  animScript;
            float            xOffset;
            float            yOffset;

            if (pos.Width <= 21)
            {
                bmp = SwinGame.BitmapNamed("SmallPoisonCloud");
            }
            else
            {
                bmp = SwinGame.BitmapNamed("BigPoisonCloud");
            }

            xOffset = (pos.Width / 2) - (bmp.CellWidth / 2);
            yOffset = 0;

            anim       = SwinGame.CreateAnimation("Poison", SwinGame.AnimationScriptNamed("PoisonZoneAnim"));
            animScript = SwinGame.AnimationScriptNamed("PoisonZoneAnim");

            newStatusAnim = new CStatusAnimation(typeof(CPoison), xOffset, yOffset, bmp, anim, animScript);

            statusAnims.Anims.Add(newStatusAnim);
        }
        /// <summary>
        /// Creates an Entity with all Components of a Freeze Zone and adds it to the World.
        /// This Entity represents the Freeze Zone created when a Freezing Bullet reaches its target.
        /// </summary>
        /// <param name="pos">The position the Freeze Zone occupies.</param>
        public static void CreateFreezeZone(CPosition pos)
        {
            //Create Entity and add to world.
            ulong newEntity = _world.NextEntityID;

            /// <summary>
            /// Adjust position for Sprite size so Freeze Zone spawns at centre of bullet.
            /// </summary>
            float atX = pos.X - (FREEZE_ZONE_SIZE / 2);
            float atY = pos.Y - (FREEZE_ZONE_SIZE / 2);

            /// <summary>
            /// Creates a new Entity with just an Animation component to be processed by the Animation Rendering System.
            /// </summary>
            Bitmap          bmp        = SwinGame.BitmapNamed("FreezingBulletSplash");
            Animation       anim       = SwinGame.CreateAnimation("Splash", SwinGame.AnimationScriptNamed("FreezingBulletSplashAnim"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("FreezingBulletSplashAnim");

            CreateAnimationEntity(atX, atY, anim, bmp, animScript);

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CPlayerTeam());
            components.Add(new CPosition(pos.Centre.X - (FREEZE_ZONE_SIZE / 2), pos.Centre.Y - (FREEZE_ZONE_SIZE / 2), FREEZE_ZONE_SIZE));
            components.Add(new CCollidable());
            components.Add(new CAppliesDebuff());
            components.Add(new CFrozen(FREEZING_BULLET_FREEZE_DURATION, 0));

            _world.AddEntity(newEntity, components);
        }
        /// <summary>
        /// Creates an Entity with all Components of a Battering Ram unit for the Enemy team and adds it to the World.
        /// The unit represents the large units holding Battering Rams which attack the Player's Castle.
        /// </summary>
        /// <param name="x">The x coordinate where the Entity will be created.</param>
        /// <param name="y">The y coordinate where the Entity will be created.</param>
        public static void CreateBatteringRam(float x, float y)
        {
            //Create Entity and add to world.
            ulong newEntity = _world.NextEntityID;

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CEnemyTeam());
            components.Add(new CStatusAnimations());
            components.Add(new CPosition(x, y, BATTERING_RAM_WIDTH, BATTERING_RAM_HEIGHT));
            components.Add(new CVelocity(-BATTERING_RAM_SPEED, 0, BATTERING_RAM_SPEED));
            components.Add(new CHealth(BATTERING_RAM_HP));
            components.Add(new CAI(BATTERING_RAM_RANGE, BATTERING_RAM_COOLDOWN, AttackType.Melee, PlayerSystem.PLAYER_ENTITY_ID)); //Belongs to the Enemy team - targets the Castle by default
            components.Add(new CDamage(BATTERING_RAM_DAMAGE));
            components.Add(new CLoot(BATTERING_RAM_LOOT_VALUE));
            components.Add(new CCollidable());

            /// <summary>
            /// Details for Animation Component.
            /// </summary>
            Bitmap          bmp        = SwinGame.BitmapNamed("BatteringRam");
            Animation       anim       = SwinGame.CreateAnimation("Walk", SwinGame.AnimationScriptNamed("BatteringRamAnims"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("BatteringRamAnims");

            components.Add(new CAnimation(bmp, anim, animScript));

            _world.AddEntity(newEntity, components);
        }
        /// <summary>
        /// Creates an Entity with all Components of a Sword Man and adds it to the World.
        /// This represents the unit holding a sword in the game which attacks the Player's Castle.
        /// </summary>
        /// <param name="x">The x coordinate where the Entity will be created.</param>
        /// <param name="y">The y coordinate where the Entity will be created.</param>
        public static void CreateSwordMan(float x, float y)
        {
            //Create Entity and add to world
            ulong newEntity = _world.NextEntityID;

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CEnemyTeam());
            components.Add(new CStatusAnimations());
            components.Add(new CPosition(x, y, SWORD_MAN_WIDTH, SWORD_MAN_HEIGHT));
            components.Add(new CVelocity(-SWORD_MAN_SPEED, 0, SWORD_MAN_SPEED));                                           //Is created moving towards the Castle.
            components.Add(new CHealth(SWORD_MAN_HP));
            components.Add(new CAI(SWORD_MAN_RANGE, SWORD_MAN_COOLDOWN, AttackType.Melee, PlayerSystem.PLAYER_ENTITY_ID)); //Sword Men are on Enemy team and target the Castle by default
            components.Add(new CDamage(SWORD_MAN_DAMAGE));
            components.Add(new CLoot(SWORD_MAN_LOOT_VALUE));
            components.Add(new CCollidable());

            /// <summary>
            /// Details for Animation Component.
            /// </summary>
            Bitmap          bmp        = SwinGame.BitmapNamed("SwordMan");
            Animation       anim       = SwinGame.CreateAnimation("Walk", SwinGame.AnimationScriptNamed("SwordManAnims"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("SwordManAnims");

            components.Add(new CAnimation(bmp, anim, animScript));

            _world.AddEntity(newEntity, components);
        }
        /// <summary>
        /// Creates an Entity with all Components of an Archer for the Enemy team and adds it to the World.
        /// This represents the unit holding a bow which attacks the Player's Castle.
        /// </summary>
        /// <param name="x">The x coordinate where the Entity will be created.</param>
        /// <param name="y">The y coordinate where the Entity will be created.</param>
        public static void CreateEnemyArcher(float x, float y)
        {
            //Create Entity and add to World.
            ulong newEntity = _world.NextEntityID;

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CEnemyTeam());
            components.Add(new CStatusAnimations());
            components.Add(new CPosition(x, y, ARCHER_WIDTH, ARCHER_HEIGHT));
            components.Add(new CVelocity(-ENEMY_ARCHER_SPEED, 0, ENEMY_ARCHER_SPEED));                                         //Is created moving towards the castle.
            components.Add(new CHealth(ENEMY_ARCHER_HP));
            components.Add(new CAI(ENEMY_ARCHER_RANGE, ENEMY_ARCHER_COOLDOWN, AttackType.Bow, PlayerSystem.PLAYER_ENTITY_ID)); //Belongs to the Enemy team - attacks the Castle by default.
            components.Add(new CBow(ENEMY_ARROW_SPEED, ENEMY_ARROW_DAMAGE));
            components.Add(new CLoot(ENEMY_ARCHER_LOOT_VALUE));
            components.Add(new CCollidable());

            /// <summary>
            /// Details for Animation Component.
            /// </summary>
            Bitmap          bmp        = SwinGame.BitmapNamed("ArcherMan");
            Animation       anim       = SwinGame.CreateAnimation("Walk", SwinGame.AnimationScriptNamed("ArcherManAnims"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("ArcherManAnims");

            components.Add(new CAnimation(bmp, anim, animScript));

            _world.AddEntity(newEntity, components);
        }
Exemple #7
0
 /// <summary>
 /// Creates skeleton for projectiles (i.e Animation, projectile speed, which unit it belongs to.)
 /// </summary>
 /// <param name="bitmap">Image for the projectile</param>
 /// <param name="animation">The animation script associated.</param>
 /// <param name="projectileSpeed">How fast the projectile fires.</param>
 /// <param name="unit">Unit.</param>
 public Projectile(string bitmap, string animation, float projectileSpeed, Unit unit)
 {
     this.unit = unit;
     this.projectileSpeed = projectileSpeed;
     sprite = SwinGame.CreateSprite (SwinGame.BitmapNamed (bitmap), SwinGame.AnimationScriptNamed(animation));
     SwinGame.SpriteStartAnimation (sprite, "fireball_cast");
     SwinGame.SpriteSetX (sprite, unit.getX()+10);
     SwinGame.SpriteSetY (sprite, unit.getY());
     SwinGame.SpriteSetDX (sprite, projectileSpeed);
 }
Exemple #8
0
        /// <summary>
        /// Defines what units need to be units and sets up essential features for each unit(e.g animation)
        /// </summary>
        /// <param name="bitmap">An image of the character</param>
        /// <param name="animation">The name of the animation used</param>
        /// <param name="movementSpeed">How fast the unit moves</param>
        /// <param name="dmg">How much dmg units output</param>
        /// <param name="enemy">If the unit is an enemy</param>
        /// <remarks>
        /// The enemy flag makes the <seealso cref="MovementDirection"/> redundant as this flag can be checked to dictate movement.
        /// </remarks>
        public Unit(string bitmap, string animation, float movementSpeed, float dmg, bool enemy)
        {
            this.movementSpeeed = movementSpeed;
            sprite = SwinGame.CreateSprite(SwinGame.BitmapNamed(bitmap), SwinGame.AnimationScriptNamed(animation));
            SwinGame.SpriteStartAnimation(sprite, "walking_loop");

            if (enemy)
            {
                SwinGame.SpriteSetX(sprite, Position.ENEMY_SPAWN_X);
                SwinGame.SpriteSetY(sprite, Position.ENEMY_SPAWN_Y);
            }
            else
            {
                SwinGame.SpriteSetX(sprite, Position.HERO_SPAWN_X);
                SwinGame.SpriteSetY(sprite, Position.HERO_SPAWN_Y);
            }

            SwinGame.SpriteSetDX(sprite, movementSpeed);
            this.dmg = dmg;
        }
        /// <summary>
        /// Creates an Entity with all the Components of a Poison Zone and adds it to the World.
        /// This Entity represents the Poison Zone the Player can create in the game.
        /// </summary>
        /// <param name="x">The x coordinate the Entity will be created at.</param>
        /// <param name="y">The y coordinate the Entity will be created at.</param>
        public static void CreatePoisonZone(float x, float y)
        {
            //Create Entity and add to world
            ulong newEntity = _world.NextEntityID;

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CPlayerTeam());
            components.Add(new CPosition(x - (POISON_ZONE_SIZE / 2), y - (POISON_ZONE_SIZE / 2), POISON_ZONE_SIZE));
            components.Add(new CPoison(POISON_ZONE_STRENGTH, POISON_ZONE_POISON_DURATION, 0));
            components.Add(new CLifetime(POISON_ZONE_LIFETIME));
            components.Add(new CAppliesDebuff());
            components.Add(new CCollidable());

            Bitmap          bmp        = SwinGame.BitmapNamed("PoisonZone");
            Animation       anim       = SwinGame.CreateAnimation("Poison", SwinGame.AnimationScriptNamed("PoisonZoneAnim"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("PoisonZoneAnim");

            components.Add(new CAnimation(bmp, anim, animScript));

            _world.AddEntity(newEntity, components);
        }
        /// <summary>
        /// Creates an Entity with all Components for an Explosion Man and adds it to the World.
        /// This Entity represents the exploding wizard the Player can purchase.
        /// </summary>
        public static void CreateExplosionMan()
        {
            //Create Entity and add to world
            ulong newEntity = _world.NextEntityID;

            /// <summary>
            /// Identifies the most populated Enemy Spatial Hash Cell. The Explosion man
            /// will be spawned at the centre of this cell.
            /// </summary>
            CollisionCheckSystem collChkSys = World.GetSystem <CollisionCheckSystem>();
            int     mostPopulatedCell       = collChkSys.EnemyCells.Aggregate((l, r) => l.Value.Count > r.Value.Count ? l : r).Key;
            Point2D pos = collChkSys.CentreOfCell(mostPopulatedCell);

            /// <summary>
            /// Adjust position for Sprite size so Explosion Man spawns at centre.
            /// </summary>
            float atX = pos.X - (EXPLOSION_MAN_SIZE / 2);
            float atY = pos.Y - (EXPLOSION_MAN_SIZE / 2);

            /// <summary>
            /// Animation details for Animation component.
            /// </summary>
            Bitmap          bmp        = SwinGame.BitmapNamed("ExplosionMan");
            Animation       anim       = SwinGame.CreateAnimation("Spawn", SwinGame.AnimationScriptNamed("ExplosionAnim"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("ExplosionAnim");

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CPlayerTeam());
            components.Add(new CPosition(atX, atY, EXPLOSION_MAN_SIZE));
            components.Add(new CAnimation(bmp, anim, animScript));
            components.Add(new CExplosionMan(mostPopulatedCell));

            _world.AddEntity(newEntity, components);
        }
        /// <summary>
        /// Creates an Entity with all Components of an Archer for the Player team and adds it to the World.
        /// This represents the unit holding a bow which the Player can buy to defend the Castle.
        /// </summary>
        /// <param name="x">The x coordinate where the Entity will be created.</param>
        /// <param name="y">The y coordinate where the Entity will be created.</param>
        public static void CreatePlayerArcher(float x, float y)
        {
            //Create Entity and add to world
            ulong newEntity = _world.NextEntityID;

            //Create components and pass to world to send to Systems
            List <Component> components = new List <Component>();

            components.Add(new CPlayerTeam());
            components.Add(new CPosition(x, y, ARCHER_WIDTH, ARCHER_HEIGHT));
            components.Add(new CAI(PLAYER_ARCHER_RANGE, PLAYER_ARCHER_COOLDOWN, AttackType.Bow));
            components.Add(new CBow(PLAYER_ARROW_SPEED, PLAYER_ARROW_DAMAGE));

            /// <summary>
            /// Details for Animation Component.
            /// </summary>
            Bitmap          bmp        = SwinGame.BitmapNamed("PlayerArcher");
            Animation       anim       = SwinGame.CreateAnimation("Still", SwinGame.AnimationScriptNamed("ArcherManAnims"));
            AnimationScript animScript = SwinGame.AnimationScriptNamed("ArcherManAnims");

            components.Add(new CAnimation(bmp, anim, animScript));

            _world.AddEntity(newEntity, components);
        }
Exemple #12
0
        public void GenerateBlock2()
        {
            List <ColorBlock> colorBlocks = new List <ColorBlock> ();
            BlockFactory      myFactory = new BlockFactory();
            int a = 12, b = 12;             //a for x position, b for y position of blocks

            while (b < 500)
            {
                for (int x = 0; x < 9; x++)
                {
                    for (int y = 0; y < 9; y++)
                    {
                        if (_blocks [x, y] == null || _blocks [x, y].Color == Color.Black)
                        {
                            colorBlocks.Add(_blocks [x, y]);
                            AddBlock(x, y, myFactory.CreateRandBlock(a, b));
                        }
                        else if (_blocks [x, y].Color == Color.Wheat)
                        {
                            colorBlocks.Add(_blocks [x, y]);
                            AddBlock(x, y, myFactory.CreateTimerBlock(a, b));
                        }
                        else if (_blocks [x, y].Color == Color.Grey)
                        {
                            colorBlocks.Add(_blocks [x, y]);
                            AddBlock(x, y, myFactory.CreateRainbowBlock(a, b));
                        }

                        //increment x position
                        a += 59;
                    }

                    //reset x position to 12 and increment y position
                    a  = 12;
                    b += 69;
                }
            }
            List <Sprite> _destroyedSprites = new List <Sprite> ();
            Sprite        sprite            = SwinGame.CreateSprite(SwinGame.BitmapNamed("destroyedani"), SwinGame.AnimationScriptNamed("destroyedanimation"));

            foreach (ColorBlock block in colorBlocks)
            {
                sprite = SwinGame.CreateSprite(SwinGame.BitmapNamed("destroyedani"), SwinGame.AnimationScriptNamed("destroyedanimation"));
                SwinGame.SpriteStartAnimation(sprite, "dematerialize");
                SwinGame.SpriteSetX(sprite, block.X - 20);
                SwinGame.SpriteSetY(sprite, block.Y - 15);
                _destroyedSprites.Add(sprite);
            }

            if (!sprite.AnimationHasEnded)
            {
                SwinGame.PlaySoundEffect(UIController.GameSound("explosion"));
                SwinGame.PauseTimer("timer");
            }

            do
            {
                //SwinGame.DrawAllSprites();
                foreach (Sprite _sprite in _destroyedSprites)
                {
                    SwinGame.DrawSprite(_sprite);
                }
                SwinGame.RefreshScreen(60);
                SwinGame.UpdateAllSprites();
            } while(!sprite.AnimationHasEnded);

            if (sprite.AnimationHasEnded && UIController.TimerPaused == false)
            {
                SwinGame.ResumeTimer("timer");
            }
        }
 public ZYPlayer()
 {
     _movement        = new ZYMovement();
     _holdingFoodName = "";
     _player          = SwinGame.CreateSprite(SwinGame.BitmapNamed(_image), SwinGame.AnimationScriptNamed("WalkingScript"));
 }
Exemple #14
0
        /// <summary>
        /// Creates a visual healing effect
        /// </summary>
        /// <returns>The effect.</returns>
        /// <param name="hero">Hero.</param>
        public Sprite createEffect(Unit hero)
        {
            Sprite sprite = SwinGame.CreateSprite(SwinGame.BitmapNamed("effectsBmp"), SwinGame.AnimationScriptNamed("healingScrpt"));

            SwinGame.SpriteStartAnimation(sprite, "healing_effect");
            SwinGame.SpriteSetX(sprite, hero.getX() - 70);
            SwinGame.SpriteSetY(sprite, hero.getY() - 80);
            return(sprite);
        }
Exemple #15
0
        private static void LoadSprites()
        {
            Sprite blueDiamond = SwinGame.CreateSprite(SwinGame.BitmapNamed("diamondblue"), SwinGame.AnimationScriptNamed("diamondanimation"));

            _Sprites.Add("blueDiamond", blueDiamond);

            Sprite redDiamond = SwinGame.CreateSprite(SwinGame.BitmapNamed("diamondred"), SwinGame.AnimationScriptNamed("diamondanimation"));

            _Sprites.Add("redDiamond", redDiamond);

            Sprite yellowDiamond = SwinGame.CreateSprite(SwinGame.BitmapNamed("diamondyellow"), SwinGame.AnimationScriptNamed("diamondanimation"));

            _Sprites.Add("yellowDiamond", yellowDiamond);

            Sprite greenDiamond = SwinGame.CreateSprite(SwinGame.BitmapNamed("diamondgreen"), SwinGame.AnimationScriptNamed("diamondanimation"));

            _Sprites.Add("greenDiamond", greenDiamond);

            Sprite timerBlock = SwinGame.CreateSprite(SwinGame.BitmapNamed("diamondtimer"), SwinGame.AnimationScriptNamed("diamondanimation"));

            _Sprites.Add("timerBlock", timerBlock);

            Sprite rainbowDiamond = SwinGame.CreateSprite(SwinGame.BitmapNamed("diamondrainbow"), SwinGame.AnimationScriptNamed("diamondanimation"));

            _Sprites.Add("rainbowDiamond", rainbowDiamond);

            SwinGame.SpriteStartAnimation(_Sprites["blueDiamond"], "spinningdiamond");
            SwinGame.SpriteStartAnimation(_Sprites["redDiamond"], "spinningdiamond");
            SwinGame.SpriteStartAnimation(_Sprites["yellowDiamond"], "spinningdiamond");
            SwinGame.SpriteStartAnimation(_Sprites["greenDiamond"], "spinningdiamond");
            SwinGame.SpriteStartAnimation(_Sprites["timerBlock"], "spinningdiamond");
            SwinGame.SpriteStartAnimation(_Sprites ["rainbowDiamond"], "spinningdiamond");
        }
Exemple #16
0
        /// <summary>
        /// Creates a firework sprite for the game ending.
        /// </summary>
        /// <returns>A sprite with the firework data</returns>
        public Sprite createFireWork()
        {
            Sprite sprite = SwinGame.CreateSprite(SwinGame.BitmapNamed("fireworksBmp"), SwinGame.AnimationScriptNamed("fireworksScrpt"));

            SwinGame.SpriteStartAnimation(sprite, "firework_start");
            SwinGame.SpriteSetX(sprite, rand.Next(10, 790));
            SwinGame.SpriteSetY(sprite, rand.Next(10, 250));
            return(sprite);
        }