Beispiel #1
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));
        }
Beispiel #2
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);
 }
Beispiel #3
0
 public void InitializeNewBall()
 {
     Center   = new Vector2(kBallX, kBallY);
     Velocity = new Vector2(XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity),
                            XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity));
     AddToAutoDrawSet();
 }
Beispiel #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);
        }
Beispiel #5
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;
        }
Beispiel #6
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();
 }
Beispiel #7
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);
        }
Beispiel #8
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;
        }
Beispiel #9
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);
        }
Beispiel #10
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;
        }
Beispiel #11
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);
        }
Beispiel #12
0
        public void UpdateEnemyPatrolState(WallSet wall)
        {
            float ran = XNACS1Base.RandomFloat(-20f, 20.0f);

            if (ran < 5)
            {
                UpdateEnemyLeftRightDir(wall);
            }
            else
            {
                UpdateEnemyUpDownDir(wall);
            }
        }
        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);
        }
Beispiel #14
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();
        }
Beispiel #15
0
        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();
            }
        }
Beispiel #16
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();
            }
        }
Beispiel #17
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();
            }
        }
Beispiel #18
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();
            }
        }
Beispiel #19
0
 private float randomPosition()
 {
     return(XNACS1Base.RandomFloat(Background.height));
 }