示例#1
0
 public AI(ContentManager cm, SpriteBatch screenSpriteBatch)
     : base(cm, screenSpriteBatch)
 {
     Catapult = new Catapult(cm, screenSpriteBatch,
                     "Textures/Catapults/Red/redIdle/redIdle",
                     new Vector2(600, 332), SpriteEffects.FlipHorizontally, true, false);
 }
示例#2
0
 public AI(ContentManager cm, SpriteBatch screenSpriteBatch)
     : base(cm, screenSpriteBatch)
 {
     Catapult = new Catapult(cm, screenSpriteBatch,
                             "Textures/Catapults/Red/redIdle/redIdle",
                             new Vector2(600, 332), SpriteEffects.FlipHorizontally, true, false);
 }
示例#3
0
        public override void Update(GameTimerEventArgs gameTime)
        {
            // Check if it is time to take a shot
            if (!IsActive && App.g_isTwoHumanPlayers)
            {
                //we are checking here for any new message from remote user
                msg = MoveMessage.GetCurrentInstance();
                if (msg.Type.Equals("SHOT"))
                {
                    remoteFirstSample     = Vector2.Zero;
                    Catapult.ShotVelocity = (float)Convert.ToDouble(msg.ShotVelocity);
                    Catapult.ShotAngle    = (float)Convert.ToDouble(msg.ShotAngle);
                    Catapult.CurrentState = CatapultState.Firing;
                    ResetDragState();
                }
                else if (msg.Type.Equals("DRAGGING"))
                {
                    // If drag just began save the sample for future
                    // calculations and start Aim "animation"
                    remoteCurrentSample   = new Vector2();
                    remoteCurrentSample.X = (float)Convert.ToDouble(msg.X);
                    remoteCurrentSample.Y = (float)Convert.ToDouble(msg.Y);
                    if (Vector2.Zero == remoteFirstSample)
                    {
                        remoteFirstSample     = remoteCurrentSample;
                        Catapult.CurrentState = CatapultState.Aiming;
                    }

                    // save the current gesture sample
                    remotePrevSample = remoteCurrentSample;

                    // calculate the delta between first sample and current
                    // sample to present visual sound on screen
                    Vector2 delta = remotePrevSample -
                                    remoteFirstSample;
                    Catapult.ShotStrength = delta.Length() / maxDragDelta;

                    Catapult.ShotVelocity = MinShotVelocity +
                                            Catapult.ShotStrength * (MaxShotVelocity - MinShotVelocity);

                    if (delta.Length() > 0)
                    {
                        Catapult.ShotAngle =
                            MathHelper.Clamp((float)Math.Asin(-delta.Y / delta.Length()),
                                             MinShotAngle, MaxShotAngle);
                    }
                    else
                    {
                        Catapult.ShotAngle = MinShotAngle;
                    }

                    float baseScale = 0.001f;
                    arrowScale = baseScale * delta.Length();
                    isDragging = true;
                }
            }

            Catapult.Update(gameTime);
        }
示例#4
0
 public override void Draw(GameTimerEventArgs gameTime)
 {
     if (isDragging)
     {
         DrawGuide();
         DrawDragArrow(arrowScale);
     }
     Catapult.Draw(gameTime);
 }
示例#5
0
        public override void Initialize()
        {
            arrow    = contentManager.Load <Texture2D>("Textures/HUD/arrow");
            guideDot = contentManager.Load <Texture2D>("Textures/HUD/guideDot");

            Catapult.Initialize();

            guideProjectile =
                new Projectile(contentManager, spriteBatch, null,
                               "Textures/Ammo/rock_ammo", Catapult.ProjectileStartPosition,
                               Catapult.GroundHitOffset, playerSide == PlayerSide.Right,
                               Catapult.Gravity);
        }
示例#6
0
        public override void Update(GameTimerEventArgs gameTime)
        {
            // Check if it is time to take a shot

            if (Catapult.CurrentState == CatapultState.Aiming &&
                !Catapult.AnimationRunning)
            {
                // Fire at a random strength and angle
                float shotVelocity =
                    random.Next((int)MinShotVelocity, (int)MaxShotVelocity);
                float shotAngle = MinShotAngle +
                                  (float)random.NextDouble() * (MaxShotAngle - MinShotAngle);

                Catapult.ShotStrength = (shotVelocity / MaxShotVelocity);
                Catapult.ShotVelocity = shotVelocity;
                Catapult.ShotAngle    = shotAngle;
            }
            Catapult.Update(gameTime);
        }
示例#7
0
        public Human(ContentManager cm, SpriteBatch screenSpriteBatch, PlayerSide playerSide)
            : base(cm, screenSpriteBatch)
        {
            contentManager = cm;
            string idleTextureName = "";

            this.playerSide = playerSide;

            if (playerSide == PlayerSide.Left)
            {
                catapultPosition = new Vector2(140, 332);
                idleTextureName  = "Textures/Catapults/Blue/blueIdle/blueIdle";
            }
            else
            {
                catapultPosition = new Vector2(600, 332);
                spriteEffect     = SpriteEffects.FlipHorizontally;
                idleTextureName  = "Textures/Catapults/Red/redIdle/redIdle";
            }

            Catapult = new Catapult(cm, screenSpriteBatch,
                                    idleTextureName, catapultPosition, spriteEffect,
                                    playerSide == PlayerSide.Left ? false : true, true);
        }
示例#8
0
 public override void Draw(GameTimerEventArgs gameTime)
 {
     // Draw related catapults
     Catapult.Draw(gameTime);
 }
示例#9
0
 public override void Initialize()
 {
     //Initialize randomizer
     random = new Random();
     Catapult.Initialize();
 }
示例#10
0
        public Human(ContentManager cm, SpriteBatch screenSpriteBatch, PlayerSide playerSide)
            : base(cm, screenSpriteBatch)
        {
            contentManager = cm;
            string idleTextureName = "";
            this.playerSide = playerSide;

            if (playerSide == PlayerSide.Left)
            {
                catapultPosition = new Vector2(140, 332);
                idleTextureName = "Textures/Catapults/Blue/blueIdle/blueIdle";
            }
            else
            {
                catapultPosition = new Vector2(600, 332);
                spriteEffect = SpriteEffects.FlipHorizontally;
                idleTextureName = "Textures/Catapults/Red/redIdle/redIdle";
            }

            Catapult = new Catapult(cm, screenSpriteBatch,
                                    idleTextureName, catapultPosition, spriteEffect,
                                    playerSide == PlayerSide.Left ? false : true, true);
        }