Exemple #1
0
        public void Initialize()
        {
#if DEBUG
            AddPowerup(typeof(Flamethrower));
            AddPowerup(typeof(TimedSpeedBoost));
            AddPowerup(typeof(AdrenalinePickup));
            AddPowerup(typeof(FireChains));
            AddPowerup(typeof(DrillFast));
            AddPowerup(typeof(RocketBurst));
            Inventory.StorePowerup(new DrillTriple(this));
            Inventory.StorePowerup(new ShieldSlow(this));
            Inventory.StorePowerup(new ShieldDamage(this));
            Inventory.StorePowerup(new BombTimed(this));
            Inventory.StorePowerup(new BombSet(this));
            AddPowerup(typeof(RescuePowerup));
            if (this == RetroGame.getHeroes()[0])
            {
                AddPowerup(typeof(FireChains));
            }
#endif

            color        = NEW_HERO_COLORS[playerIndex];
            maskingColor = color;
            prisonerName = NEW_HERO_NAMES[playerIndex];
            prisonerID   = NEW_HERO_IDS[playerIndex];
            Prisoner.TAKEN_IDS[prisonerID] = true;
            History.RegisterReversible(this);
        }
Exemple #2
0
 public Hero(HeroSaveState saveState)
     : this(saveState.index)
 {
     color        = saveState.color;
     maskingColor = saveState.color;
     prisonerName = saveState.name;
     prisonerID   = saveState.id;
     Prisoner.TAKEN_IDS[prisonerID] = true;
     History.RegisterReversible(this);
     FreedPrisoners   = saveState.freedPrisoners;
     CollectedGems    = saveState.collectedGems;
     KilledEnemyCount = saveState.killedEnemyCount;
     HitByEnemyCount  = saveState.hitByEnemyCount;
 }
Exemple #3
0
        public Powerup AddPowerup(Type powerupType, bool automaticallySetPowerupIcon = true)
        {
            Powerup powerup = null;

            if (powerupType.IsSubclassOf(typeof(CoOpPowerup)))
            {
                //gets the other hero from the list of heroes (or just another hero if for some reason there are more than 2 heroes)
                Hero otherHero = null;
                foreach (Hero h in RetroGame.getHeroes())
                {
                    if (h != this)
                    {
                        otherHero = h;
                        break;
                    }
                }
                if (otherHero == null)
                {
                    return(null);
                }
                powerup = (Powerup)powerupType.GetConstructor(new Type[] { typeof(Hero), typeof(Hero) }).Invoke(new object[] { this, otherHero });
            }
            else
            {
                powerup = (Powerup)powerupType.GetConstructor(new Type[] { typeof(Hero) }).Invoke(new object[] { this });
            }

            if (Inventory.EquipPowerup(powerup, playerIndex, automaticallySetPowerupIcon))
            {
                Powerups.Add(powerup.GenericName, powerup);
                powerup.OnAddedToHero();
                if (powerup is IReversible)
                {
                    History.RegisterReversible((IReversible)powerup);
                }
                History.Clear();
            }
            return(powerup);
        }
Exemple #4
0
        public void createAndRemoveLevels()
        {
            List <Point> levelsWithHeroes = new List <Point>();

            foreach (Hero hero in heroes)
            {
                levelsWithHeroes.Add(new Point(hero.levelX, hero.levelY));
            }
            List <Point> levelsToHave   = new List <Point>();
            List <Point> levelsToRemove = new List <Point>();

            foreach (Hero hero in heroes)
            {
                int prevHeroLevelX = hero.prevLevelX;
                int prevHeroLevelY = hero.prevLevelY;
                int curHeroLevelX  = hero.levelX;
                int curHeroLevelY  = hero.levelY;

                if (curHeroLevelX < prevHeroLevelX) // hero transitioned left
                {
                    int indexX = curHeroLevelX + 2;
                    int indexY = curHeroLevelY;
                    if (indexX < MAX_LEVELS)
                    {
                        for (int i = -1; i <= 1; i++)
                        {
                            if (indexY + i < MAX_LEVELS && indexY + i >= 0)
                            {
                                levelsToRemove.Add(new Point(indexX, indexY + i));
                            }
                        }
                    }
                }
                else if (curHeroLevelX > prevHeroLevelX) // hero transitioned right
                {
                    int indexX = curHeroLevelX - 2;
                    int indexY = curHeroLevelY;
                    if (indexX >= 0)
                    {
                        for (int i = -1; i <= 1; i++)
                        {
                            if (indexY + i < MAX_LEVELS && indexY + i >= 0)
                            {
                                levelsToRemove.Add(new Point(indexX, indexY + i));
                            }
                        }
                    }
                }
                else if (curHeroLevelY < prevHeroLevelY) // hero transitioned up
                {
                    int indexX = curHeroLevelX;
                    int indexY = curHeroLevelY + 2;
                    if (indexY < MAX_LEVELS)
                    {
                        for (int i = -1; i <= 1; i++)
                        {
                            if (indexX + i < MAX_LEVELS && indexX + i >= 0)
                            {
                                levelsToRemove.Add(new Point(indexX + i, indexY));
                            }
                        }
                    }
                }
                else if (curHeroLevelY > prevHeroLevelY) // hero transitioned down
                {
                    int indexX = curHeroLevelX;
                    int indexY = curHeroLevelY - 2;
                    if (indexY >= 0)
                    {
                        for (int i = -1; i <= 1; i++)
                        {
                            if (indexX + i < MAX_LEVELS && indexX + i >= 0)
                            {
                                levelsToRemove.Add(new Point(indexX + i, indexY));
                            }
                        }
                    }
                }

                List <Level> surroundingLevels = new List <Level>();
                for (int xi = -1; xi <= 1; xi++)
                {
                    for (int yi = -1; yi <= 1; yi++)
                    {
                        int x = curHeroLevelX + xi;
                        int y = curHeroLevelY + yi;
                        if (x < 0 || y < 0 || x >= MAX_LEVELS || y >= MAX_LEVELS)
                        {
                            continue;
                        }
                        levelsToHave.Add(new Point(x, y));
                        surroundingLevels.Add(levels[x, y]);
                        //clear all registered levels in History
                        if (!levelsWithHeroes.Contains(new Point(x, y)) && History.IsRegistered(levels[x, y]))
                        {
                            History.UnRegisterReversible(levels[x, y]);
                        }
                    }
                }
                LevelsSurroundingHero[hero] = surroundingLevels;
            }
            foreach (Point p in levelsToRemove)
            {
                if (!levelsToHave.Contains(p))
                {
                    removeLevel(p.X, p.Y);
                }
            }
            List <Point> levelsToUpdateBorderWallColors = new List <Point>();

            foreach (Point p in levelsToHave)
            {
                if (levels[p.X, p.Y] == null)
                {
                    createRandomLevelAt(p.X, p.Y);
                    foreach (Point newP in new Point[] { p, new Point(p.X + 1, p.Y), new Point(p.X, p.Y + 1), new Point(p.X + 1, p.Y + 1) })
                    {
                        if (!levelsToUpdateBorderWallColors.Contains(newP))
                        {
                            levelsToUpdateBorderWallColors.Add(newP);
                        }
                    }
                }
            }
            foreach (Point p in levelsToUpdateBorderWallColors)
            {
                if (p.X > 0 && p.Y > 0 && levels[p.X, p.Y] != null)
                {
                    if (levels[p.X - 1, p.Y] != null)
                    {
                        levels[p.X, p.Y].updateLeftBorderColors();
                    }
                    if (levels[p.X, p.Y - 1] != null)
                    {
                        levels[p.X, p.Y].updateTopBorderColors();
                    }
                    if (levels[p.X - 1, p.Y] != null && levels[p.X, p.Y - 1] != null && levels[p.X - 1, p.Y - 1] != null)
                    {
                        levels[p.X, p.Y].updateCornerBorderColors();
                    }
                }
            }
            foreach (Hero hero in heroes)
            {
                if (!History.IsRegistered(levels[hero.levelX, hero.levelY]))
                {
                    History.RegisterReversible(levels[hero.levelX, hero.levelY]);
                }
            }
        }