Exemple #1
0
 public void InitializeNewBall()
 {
     Center   = new Vector2(kBallX, kBallY);
     Velocity = new Vector2(XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity),
                            XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity));
     AddToAutoDrawSet();
 }
        public new void SetAppWindowPixelDimension(bool fullScreen, int widthInPixel, int heightInPixel)
        {
            XNACS1Base.SetAppWindowPixelDimension(fullScreen, widthInPixel, heightInPixel);

            MouseDevice.setWindowWidth(GraphicsDeviceManager.DefaultBackBufferWidth);
            MouseDevice.setWindowHeight(GraphicsDeviceManager.DefaultBackBufferHeight);
        }
Exemple #3
0
        public static List <Color> randomColorSet(int count)
        {
            // get a random and unique subset of the available colors

            List <int> range  = Enumerable.Range(0, colorCount).ToList();
            List <int> sample = new List <int>();

            // set up the indexes in the sample list
            for (int i = 0; i < count; i++)
            {
                int choice = XNACS1Base.RandomInt(range.Count);
                sample.Add(range.ElementAt(choice));
                range.RemoveAt(choice);
            }

            // get the colors from the indexes in the sample list
            List <Color> colors = new List <Color>();

            foreach (int i in sample)
            {
                colors.Add(colorPicker(i));
            }

            return(colors);
        }
Exemple #4
0
        public Debris(Hero hero, List <Enemy> enemies, float minX, float maxX)
        {
            float padding = size;

            float randomX = XNACS1Base.RandomFloat(minX + padding, maxX - padding);
            float randomY = XNACS1Base.RandomFloat(GameWorld.bottomEdge + padding, GameWorld.topEdge - padding);

            texture = new XNACS1Rectangle(new Vector2(randomX, randomY), size, size);

            switch (XNACS1Base.RandomInt(3))
            {
            case 0:
                texture.Texture = "Beak";
                break;

            case 1:
                texture.Texture = "Window";
                break;

            case 2:
                texture.Texture = "Wing2";
                texture.Width   = texture.Height * 1.8f;
                break;
            }

            obstacle = new Obstacle(hero, enemies, texture.Center, texture.Width * .9f, texture.Height * .9f);
        }
Exemple #5
0
        private Vector2 GetRandomWorldPosition()
        {
            float x = XNACS1Base.World.WorldDimension.X * XNACS1Base.RandomFloat(0.02f, 0.48f);
            float y = XNACS1Base.World.WorldDimension.Y * XNACS1Base.RandomFloat(0.02f, 0.48f);

            return(new Vector2(x, y));
        }
Exemple #6
0
 public HeroObject()
 {
     Radius  = 2f;
     CenterX = XNACS1Base.RandomFloat(XNACS1Base.World.WorldMin.X, XNACS1Base.World.WorldMax.X);
     CenterY = XNACS1Base.RandomFloat(XNACS1Base.World.WorldMin.Y, XNACS1Base.World.WorldMax.Y);
     Color   = new Color(1f, 0.8f, 0.8f);
 }
Exemple #7
0
        private void fillPlatform(int offset, float leftEdge, bool continuous)
        {
            // set up platform
            float Ypos = ((offset * 1f) / Stargate.GATE_COUNT) * GameWorld.topEdge;

            if (continuous)
            {
                float    Xpos     = leftEdge + (Stargate.width / 2);
                Obstacle obstacle = new Obstacle(hero, enemies, new Vector2(Xpos, Ypos), Stargate.width + mask, height);
                obstacles.Add(obstacle);
            }
            else
            {
                // randomly fill platform
                float    width = Stargate.width / SEGMENT_COUNT;
                Obstacle obstacle;
                int      consecutiveChance = 10;
                bool     platform          = true;
                for (int i = 0; i < SEGMENT_COUNT; i++)
                {
                    if (platform)
                    {
                        float Xpos = (width * 0.5f) + leftEdge + (i * width);
                        obstacle = new Obstacle(hero, enemies, new Vector2(Xpos, Ypos), width + mask, height);
                        obstacles.Add(obstacle);
                    }
                    consecutiveChance -= 2;
                    if (XNACS1Base.RandomInt(consecutiveChance) == 0)
                    {
                        platform          = !platform;
                        consecutiveChance = 10;
                    }
                }
            }
        }
Exemple #8
0
        public Vector2 updateRoom(Hero hero)
        {
            walls.UpdateWallCollisionWithHero(hero);
            XNACS1Base.EchoToTopStatus("num of enemy" + activeEnemies);
            for (int i = 0; i < myEnemies.Length; i++)
            {
                myEnemies[i].UpdateEnemy(hero, walls);
                walls.UpdateWallCollisionWithEnemy(myEnemies[i]);
            }
            //note to self: work on trigger
            if (XNACS1Base.GamePad.ButtonXClicked())
            {
                wand.Shoot(hero);
            }


            dropPos = wand.Update(myEnemies);
            if (dropPos.X > -1)
            {
                reduceActiveEnemies();
            }

            allDone = true;
            for (int i = 0; i < myEnemies.Length; i++)
            {
                if (!myEnemies[i].isBunny())
                {
                    allDone = false;
                }
            }


            if (key != null)
            {
                if (hero.Collided(key))
                {
                    openAllDoors();
                    key.RemoveFromAutoDrawSet();
                }

                if (myDoors[0].isOpen() && key != null)
                {
                    key.RemoveFromAutoDrawSet();
                }
            }
            Vector2 newRoom = new Vector2(-1f, -1f);

            for (int i = 0; i < numDoors; i++)
            {
                newRoom = myDoors[i].UpdateDoor(hero);

                if (newRoom.X > 0f)
                {
                    return(newRoom);
                }
            }

            return(newRoom);
        }
Exemple #9
0
 public MyBall() : base(new Vector2(kBallX, kBallY), 3f)
 {
     Velocity = new Vector2(XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity),
                            XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity));
     ShouldTravel = true;
     Color        = Color.Red;
     RemoveFromAutoDrawSet();
 }
Exemple #10
0
        private void ComputePositionAndVelocity()
        {
            // Change the speed without actually change velocity direction!!
            Speed = kPatrolSpeed * XNACS1Base.RandomFloat(0.8f, 1.2f); // speed has 20% randomness

            //toNextPosition.Normalize();
            // Velocity = speed * toNextPosition;
        }
Exemple #11
0
        private static Color randomStarColor()
        {
            int r = XNACS1Base.RandomInt(200, 256);
            int g = XNACS1Base.RandomInt(200, 256);
            int b = XNACS1Base.RandomInt(200, 256);

            return(new Color(r, g, b));
        }
Exemple #12
0
        public PowerUp(Hero hero, float minX, float maxX)
        {
            this.hero = hero;
            float padding = hero.getPosition().Width * 2;
            float randomX = XNACS1Base.RandomFloat(minX + padding, maxX - padding);
            float randomY = XNACS1Base.RandomFloat(GameWorld.bottomEdge + padding, GameWorld.topEdge - padding);

            box = new XNACS1Rectangle(new Vector2(randomX, randomY), width, width * 0.39f);
        }
Exemple #13
0
        private void ComputePositionAndVelocity()
        {
            Vector2 toNextPosition        = mTargetPosition - Center;          // this is the vector from Center to the next Position
            float   distantToNextPosition = toNextPosition.Length();
            float   speed = kPatrolSpeed * XNACS1Base.RandomFloat(0.8f, 1.2f); // speed has 20% randomness

            toNextPosition.Normalize();
            Velocity = speed * toNextPosition;
        }
Exemple #14
0
        /// <summary>
        /// Spawns a normal ball at the given position
        /// </summary>
        /// <param name="postion"></param>
        public void spawn(Vector2 position)
        {
            Vector2 direction = new Vector2(XNACS1Base.RandomFloat(-0.8f, 0.8f), -0.7f);

            if (direction != Vector2.Zero)
            {
                direction.Normalize();
            }
            spawn(position, direction);
        }
Exemple #15
0
        public void Update()
        {
            for (int x = 0; x < oPlayers.Count(); x++)
            {
                oPlayers[x].UpdateVictoryPoints(nLongestRoadOwner, nLargestArmyOwner);
                oPlayers[x].UpdateCardCount();
            }

            //XNACS1Base.EchoToTopStatus("statistics:" + oPlayers[0].nResourceCards[2] + "" + oPlayers[0].nResourceCards[3]);
            XNACS1Base.EchoToTopStatus("statistics:" + nCurrentPlayer);
        }
Exemple #16
0
        protected override void NewParticle(XNACS1Particle particle)
        {
            float theta = XNACS1Base.RandomFloat(0, (float)(2 * Math.PI));

            particle.CenterX = CenterX;
            particle.CenterY = CenterY;
            Vector2 randomVelocity = new Vector2(XNACS1Base.RandomFloat(-1, 1), XNACS1Base.RandomFloat(-1, 1));

            randomVelocity       *= 0.2f;
            particle.Velocity     = randomVelocity;
            particle.ShouldTravel = true;
        }
Exemple #17
0
        public void UpdateEnemyPatrolState(WallSet wall)
        {
            float ran = XNACS1Base.RandomFloat(-20f, 20.0f);

            if (ran < 5)
            {
                UpdateEnemyLeftRightDir(wall);
            }
            else
            {
                UpdateEnemyUpDownDir(wall);
            }
        }
        public Vector2 TurnEnemyToBunny()
        {
            if (CurrentState != EnemyState.Bunny)
            {
                CurrentState = EnemyState.Bunny;
                Height      /= 2;
                Width        = 2;
                Texture      = "flower";
                XNACS1Base.PlayACue("transform");
            }

            return(Center);
        }
Exemple #19
0
        public DyePack(Hero hero, float minX, float maxX, Color color)
        {
            this.hero = hero;

            float padding = hero.getPosition().Width * 2;

            float randomX = XNACS1Base.RandomFloat(minX + padding, maxX - padding);
            float randomY = XNACS1Base.RandomFloat(GameWorld.bottomEdge + padding, GameWorld.topEdge - padding);

            box         = new XNACS1Rectangle(new Vector2(randomX, randomY), 0.865f * height, height);
            box.Color   = color;
            box.Texture = getTexture(color);
        }
        private bool UpdateChaseHeroState(HeroObject hero, float distToHero)
        {
            bool caught = false;

            caught          = Collided(hero);
            mTargetPosition = hero.Center;

            if (caught || (mStateTimer < 0))
            {
                if (caught)
                {
                    hero.Caught();
                }

                Color = new Color(XNACS1Base.RandomFloat(0f, 0.4f),
                                  XNACS1Base.RandomFloat(0f, 0.4f),
                                  XNACS1Base.RandomFloat(0f, 0.4f));
                // now tansit out of current state ...
                Vector2 midPt = 0.5f * (XNACS1Base.World.WorldMax - XNACS1Base.World.WorldMin);
                if (CenterX > midPt.X)
                {
                    if (CenterY > midPt.Y)
                    {
                        mCurrentState   = PatrolState.TopRightRegion;
                        mTargetPosition = RandomTopRightPosition();
                    }
                    else
                    {
                        mCurrentState   = PatrolState.BottomRightRegion;
                        mTargetPosition = RandomBottomRightPosition();
                    }
                }
                else
                {
                    if (CenterY > midPt.Y)
                    {
                        mCurrentState   = PatrolState.TopLeftRegion;
                        mTargetPosition = RandomTopLeftPosition();
                    }
                    else
                    {
                        mCurrentState   = PatrolState.BottomLeftRegion;
                        mTargetPosition = RandomBottomLeftPosition();
                    }
                }
                mStateTimer = kStateTimer;
                ComputePositionAndVelocity();
            }
            return(caught);
        }
Exemple #21
0
        private int mStateTimer;                // interestingly, with "gradual" velocity changing, we cannot
                                                // guarantee that we will ever rich the mTargetPosition
                                                // (we may ended up orbiting the target), so we set a timer
                                                // when timer is up, we transit


        public PatrolObject()
        {
            Radius       = 0.7f;
            ShouldTravel = true;
            Color        = new Color(XNACS1Base.RandomFloat(0f, 0.4f),
                                     XNACS1Base.RandomFloat(0f, 0.4f),
                                     XNACS1Base.RandomFloat(0f, 0.4f));

            Center        = RandomTopLeftPosition();
            mCurrentState = PatrolState.TopLeftRegion;

            mTargetPosition = RandomTopRightPosition();
            ComputePositionAndVelocity();
        }
Exemple #22
0
        public void Shoot(XNACS1Rectangle hero)
        {
            shot s = new shot(hero.Center, false);

            s.bullet.ShouldTravel = true;
            s.bullet.Velocity     = (XNACS1Base.GamePad.ThumbSticks.Right.X == 0 && XNACS1Base.GamePad.ThumbSticks.Right.Y == 0) ? new Vector2(hero.Texture == "pennyRight" ? 1 : -1, 0) : XNACS1Base.GamePad.ThumbSticks.Right;
            list.Add(s);
            XNACS1Base.PlayACue("spell");

            //shot s2 = new shot(hero.Center, false);
            //s2.bullet.ShouldTravel = true;
            //s2.bullet.Velocity = s.bullet.Velocity;
            //s2.bullet.VelocityY = 0.25f;
            //list.Add(s2);
        }
Exemple #23
0
        public static PowerUp randomPowerUp(Hero hero, float minX, float maxX)
        {
            switch (XNACS1Base.RandomInt(4))
            {
            case 0:
                return(new SpeedUp(hero, minX, maxX));

            case 1:
                return(new Ghost(hero, minX, maxX));

            case 2:
                return(new Invincibility(hero, minX, maxX));

            default:
                return(new Overload(hero, minX, maxX));
            }
        }
        public override void update()
        {
            // remove any dead enemies
            foreach (Enemy e in enemies.Where(enemy => !enemy.isAlive()))
            {
                e.remove();
            }
            enemies.RemoveAll(enemy => !enemy.isAlive());


            foreach (Enemy e in enemies)
            {
                e.update();
            }

            // prevent generating enemy
            if (GameWorld.Speed != 0)
            {
                newEnemyTimer.update();
            }

            //generate new enemy
            if (newEnemyTimer.isDone())
            {
                float   randomY  = XNACS1Base.RandomFloat(GameWorld.topEdge - 5, GameWorld.bottomEdge + 5);
                Vector2 position = new Vector2(GameWorld.rightEdge + 5, randomY);

                switch (XNACS1Base.RandomInt(0, 3))
                {
                case 1:
                    enemies.Add(new BrainEnemy(position, 7.5f, hero));
                    break;

                case 2:
                    enemies.Add(new RedBeamEnemy(position, 7.5f, hero));
                    break;

                default:
                    enemies.Add(new SpiderEnemy(position, 7.5f, hero));
                    break;
                }

                newEnemyTimer.reset();
            }
        }
Exemple #25
0
        public Vector2 TurnEnemyToBunny()
        {
            if (CurrentState != EnemyState.Bunny)
            {
                CurrentState = EnemyState.Bunny;
                Width        = 4.7f;
                Height       = 2.5f;
                SetTextureSpriteSheet("bunnySpriteSheet", 11, 2, 0);
                UseSpriteSheet = true;
                SetTextureSpriteAnimationFrames(0, 0, 10, 1, 5, SpriteSheetAnimationMode.AnimateForward);
                UseSpriteSheetAnimation = true;

                string[] cues = { "transform1", "transform2", "transform3", "transform4" };
                Random   r    = new Random();
                XNACS1Base.PlayACue(cues[r.Next(0, 4)]);
            }

            return(Center);
        }
        public bool updateLevel(XNACS1Lib.XNACS1Lib.GamePadSupport.AllButtonsOnGamePad pad,
                                XNACS1Lib.XNACS1Lib.GamePadSupport.ThumbSticksOnGamePad thumbs)
        {
            hero.UpdateHero(thumbs.Left);
            Vector2 newRoom = rooms[(int)currentRoom.X, (int)currentRoom.Y].updateRoom(hero);



            if (newRoom.X > -1)
            {
                unLoadRoom();
                currentRoom = newRoom;
                loadRoom();
            }


            XNACS1Base.EchoToTopStatus("Hero has " + hero.NumTimesCaught + " live(s)");
            return(false);
        }
Exemple #27
0
        private void UpdateTopLeftState(HeroObject hero, float distToTarget)
        {
            DetectHero(hero); // check if we should transit to ChaseHero

            if ((mStateTimer < 0) || (distToTarget < 5f))
            {
                mStateTimer = (int)(kStateTimer * XNACS1Base.RandomFloat(0.8f, 1.2f)); // 20% randomness
                if (XNACS1Base.RandomFloat() > 0.5f)
                {
                    mCurrentState   = PatrolState.BottomLeftRegion;
                    mTargetPosition = RandomBottomLeftPosition();
                }
                else
                {
                    mCurrentState   = PatrolState.TopRightRegion;
                    mTargetPosition = RandomTopRightPosition();
                }
                ComputePositionAndVelocity();
            }
        }
Exemple #28
0
        private void UpdateBottomRightState()
        {
            Byte g = Color.G;

            g--;
            Color = new Color(Color.R, g, Color.B);
            if ((Center - mTargetPosition).Length() < 1f)
            {
                if (XNACS1Base.RandomFloat() > 0.5f)
                {
                    mCurrentState   = PatrolState.TopRightRegion;
                    mTargetPosition = RandomTopRightPosition();
                }
                else
                {
                    mCurrentState   = PatrolState.BottomLeftRegion;
                    mTargetPosition = RandomBottomLeftPosition();
                }
                ComputePositionAndVelocity();
            }
        }
Exemple #29
0
        private void UpdateTopLeftState(float distToTarget)
        {
            Byte r = Color.R;

            r++;
            Color = new Color(r, Color.G, Color.B);

            if ((mStateTimer < 0) || (distToTarget < 5f))
            {
                mStateTimer = (int)(kStateTimer * XNACS1Base.RandomFloat(0.8f, 1.2f)); // 20% randomness
                if (XNACS1Base.RandomFloat() > 0.5f)
                {
                    mCurrentState   = PatrolState.BottomLeftRegion;
                    mTargetPosition = RandomBottomLeftPosition();
                }
                else
                {
                    mCurrentState   = PatrolState.TopRightRegion;
                    mTargetPosition = RandomTopRightPosition();
                }
                ComputePositionAndVelocity();
            }
        }
Exemple #30
0
        public Vector2 updateRoom(Hero hero, int levelNum)
        {
            heroCaught = false;
            walls.UpdateWallCollisionWithHero(hero);

            for (int i = 0; i < myEnemies.Length; i++)
            {
                bool temp = myEnemies[i].UpdateEnemy(hero, walls);
                if (temp)
                {
                    heroCaught = temp;
                }

                walls.UpdateWallCollisionWithEnemy(myEnemies[i]);
            }

            walls.updateStatus(hero, levelNum);
            if ((XNACS1Base.GamePad.Triggers.Right > 0 && !triggerPressed) || XNACS1Base.GamePad.ButtonXClicked())
            {
                wand.Shoot(hero);
                triggerPressed = true;
            }

            if (XNACS1Base.GamePad.Triggers.Right == 0)
            {
                triggerPressed = false;
            }

            dropPos = wand.Update(myEnemies, walls);
            if (dropPos.X > -1)
            {
                reduceActiveEnemies();
            }

            //allDone = true;
            //for (int i = 0; i < myEnemies.Length; i++) {
            //    if (!myEnemies[i].isBunny())
            //        allDone = false;

            //}

            if (hasStairs == 1 && badGuy != null)
            {
                walls.updateWizardStats(badGuy);
                hasWon = badGuy.Update(hero, wand);


                if (hasWon)
                {
                    stairs.AddToAutoDrawSet();
                    stairs.available = true;
                    openAllDoors();
                }

                if (badGuy.heroHit)
                {
                    heroCaught = true;
                }
            }

            if (key != null)
            {
                if (hero.Collided(key))
                {
                    openAllDoors();
                    XNACS1Base.PlayACue("door_open");
                    key.RemoveFromAutoDrawSet();
                }

                if (myDoors[0].isOpen() && key != null)
                {
                    key.RemoveFromAutoDrawSet();
                    key = null;
                }
            }
            Vector2 newRoom = new Vector2(-1f, -1f);

            for (int i = 0; i < numDoors; i++)
            {
                newRoom = myDoors[i].UpdateDoor(hero);

                if (newRoom.X > 0f)
                {
                    return(newRoom);
                }
            }

            return(newRoom);
        }