Exemplo n.º 1
0
        } // PickUp()

        #endregion

        #region Body_OnCollision
        /// <summary>
        /// Body_OnCollision, Checks collision between Player and the Pickup.
        /// Heals the Tank 20 Hitpoints
        /// </summary>
        /// <param name="fixtureA">Pickup fixture</param>
        /// <param name="fixtureB">player fixture</param>
        /// <param name="contact">contact</param>
        /// <returns>false, don't collide on pickup</returns>
        public bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            // if we have some valid userdata
            if (fixtureB.Body.UserData != null)
            {
                // if this fixture is the player
                //if (fixtureB.Body.UserData.ToString() == "player" && fixtureA.Body.UserData.ToString() == "pickup")
                if ((fixtureB.Body.UserData.ToString() == "player" || fixtureB.Body.UserData.ToString() == "wheel") && fixtureA.Body.UserData.ToString() == "pickup")
                {
                    // and if we are not already picked up by the player
                    if (pickedUp == false)
                    {
                        // pickup this
                        pickedUp          = true;
                        fixtureA.UserData = "disable";
                        Sound.Play(Sound.Sounds.PickUp);
                        FadeUp.AddTextMessage("+" + GameSettings.PickupHeal, FadeUp.TextTypes.Heal, fixtureB.Body.Position);
                        HealthBar.SetHeal(GameSettings.PickupHeal);
                        fixtureA.Body.Dispose();
                        PickUps.Remove(this);

                        // don't collide at first time
                        return(false);
                    } // if (pickedUp == false)
                }     // if ("player")
            }         // if (UserData != null )
            //else collide with the environment
            return(true);
        } // Body_OnCollision
Exemplo n.º 2
0
        bool shot_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body.UserData != null)
            {
                // if EnemyTower gets hit by player shot
                if (fixtureB.Body.UserData.ToString() == "enemyTower" &&
                    fixtureA.Body.UserData.ToString() == "s")
                {
                    //FadeUp.AddTextMessage("-" + GameSettings.PlayerDamage, FadeUp.TextTypes.Damage, fixtureB.Body.Position);
                    fixtureA.Body.UserData = "disable";     // Disable user Shot!
                    fixtureB.Body.UserData = "damage";      // but save the damage the tower will receive
                }

                // if flying enemy gets hit by player shot
                if (fixtureB.Body.UserData.ToString() == "enemy" &&
                    fixtureA.Body.UserData.ToString() == "s")
                {
                    //FadeUp.AddTextMessage("-" + GameSettings.PlayerDamage, FadeUp.TextTypes.Damage, fixtureB.Body.Position);
                    fixtureA.Body.UserData = "disable";     // Disable user Shot!
                    fixtureB.Body.UserData = "damage";
                }

                // Disable Player Shots if they collide with the levelparts
                if (fixtureB.Body.UserData.ToString() == "physictexture" &&
                    fixtureA.Body.UserData.ToString() == "s")
                {
                    fixtureA.Body.UserData = "disable";     // disable damage for this shot
                }

                // if the player gets shot by EnemyTowers
                if (fixtureB.Body.UserData.ToString() == "player" &&
                    fixtureA.Body.UserData.ToString() == "enemyShot")
                {
                    FadeUp.AddTextMessage("-" + GameSettings.TowerDamage, FadeUp.TextTypes.Damage, fixtureB.Body.Position);
                    fixtureB.Body.UserData = "getroffen";   // Enable damage
                    fixtureA.Body.UserData = "disable";     // disable damage for this shot
                }

                // Disable enemy Shots if they collide with the levelparts
                if (fixtureB.Body.UserData.ToString() == "physictexture" &&
                    fixtureA.Body.UserData.ToString() == "enemyShot")
                {
                    fixtureA.Body.UserData = "disable";     // disable damage for this shot
                }

                // Disable player Shots if they collide with the Triggers
                else if (fixtureB.Body.UserData.ToString() == "trigger" &&
                         fixtureA.Body.UserData.ToString() == "s")
                {
                    return(false);
                }

                else if (fixtureB.Body.UserData.ToString() == "trigger" &&
                         fixtureA.Body.UserData.ToString() == "disable")
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        }     // NavigateToActor(actor)

        #endregion

        #region Update
        /// <summary> Update Enemy behavior and shots by player </summary>
        public override void Update()
        {
            // Handle damage taken from the player
            if (body.UserData.ToString() == "damage")
            {
                // substract hitpoints
                HitPoints    -= GameSettings.PlayerDamage;
                body.UserData = "enemy";                // reset userdata to enemy and receive no more damage from this shot!

                // case when enemy is dead, TODO: Play killed animation and dispose then.
                if (HitPoints <= 0)
                {
                    // receive Score
                    GameSettings.HighScore += (uint)GameSettings.EnemyScore;
                    FadeUp.AddTextMessage("+ " + GameSettings.EnemyScore, FadeUp.TextTypes.Score, body.Position);

                    body.UserData = "disable";
                    body.Dispose();
                    Delete();
                } // if (HitPoints <= 0)
            }     //  if ("damage")


            // Meelee range!  Distance based Collision Check between player's radius and enemy's radius
            if (Vector2.Distance(GameDemo1.vehicle.Position, Position) < GameDemo1.vehicle.Radius + Radius)
            {
                // Only explode once
                if (exploded == false)
                {
                    FadeUp.AddTextMessage("- " + GameSettings.EnemyDamage, FadeUp.TextTypes.Damage, GameDemo1.vehicle.Body.Position);
                    HealthBar.SetDamage(GameSettings.EnemyDamage);
                    exploded = true;
                }

                // if we are exploded and did the Damage, Delete the enemy!
                if (exploded)
                {
                    body.Dispose();
                    Delete();
                }

                ChangeState(EnemyState.Dead);
                //health.Active = true;
            }
            // Distance based Collision Check between player's radius and enemy's sightradius
            else if (Vector2.Distance(GameDemo1.vehicle.Position, Position) < GameDemo1.vehicle.Radius + SightRadius)
            {
                // if we are not Dead!
                if (State != EnemyState.Dead)
                {
                    ChangeState(EnemyState.SeekPlayer); // Change state to seek player
                }
            }


            base.Update();
        } // Update()
Exemplo n.º 4
0
        } // BombingEnemy(setPosition, setHitPoints)

        #endregion

        #region Update
        /// <summary> Update shots by player and player hitpoints</summary>
        public override void Update()
        {
            // Handle damage taken from the player
            if (body.UserData.ToString() == "damage")
            {
                // substract hitpoints
                HitPoints    -= GameSettings.PlayerDamage;
                body.UserData = "enemy";                // reset userdata to enemy and receive no more damage from this shot!

                // case when enemy is dead, TODO: Play killed animation and dispose then.
                if (HitPoints <= 0)
                {
                    // receive Score
                    GameSettings.HighScore += (uint)GameSettings.BombingEnemyScore;
                    FadeUp.AddTextMessage("+ " + GameSettings.BombingEnemyScore, FadeUp.TextTypes.Score, body.Position); //GameDemo1.vehicle.Body.Position);
                    Sound.Play(Sound.Sounds.Explosion);
                    GameDemo1.particleManager.AddExplosion(body.Position);


                    body.UserData = "disable";
                    Delete();

                    // also spawn a pickup
                    new PickUp("AI/health", body.Position, 2.0f);

                    //body.Dispose();
                } // if (HitPoints <= 0)
            }     //  if ("damage")

            // throw bombs if the player's position and the enemy's position is lesser than the player's radius and the enemy's sightradius
            if (Vector2.Distance(GameDemo1.vehicle.Position, Position) < GameDemo1.vehicle.Radius + SightRadius)
            {
                TimeSinceShot += (float)GameDemo1.GameTime.ElapsedGameTime.TotalMilliseconds; //TotalSeconds; //Zeit seit letztem Update dazuaddieren
                if (TimeSinceShot >= ShotTimer)                                               //Wenn die vergangene Zeit größer ist als der Timer, do...
                {
                    Shot shot = new Shot(true);
                    shot.isBomb            = true;
                    shot.shotBody.Position = PositionSim + new Vector2(0, 3);   // add a little offset
                    Shots.Add(shot);

                    TimeSinceShot -= ShotTimer; // Resette den Timer.
                } // if (TimeSinceShot >= ShotTimer)
            } // if (Vector2.Distance)

            // loop all shots
            for (int i = 0; i < Shots.Count; i++)
            {
                // Draw particles every fourth frame (performance)
                if (loopCount % 4 == 0)
                {
                    loopCount = 0;
                    GameDemo1.particleManager.AddEnemyBombParticles(Shots[i].shotBody);
                }

                // remove disabled user Shots
                if (Shots[i].shotBody.UserData.ToString() == "disable")
                {
                    GameDemo1.particleManager.AddExplosion(Shots[i].shotBody.Position);
                    Sound.Play(Sound.Sounds.Explosion);

                    Shots[i].shotBody.Dispose();
                    Shots.Remove(Shots[i]);
                }   // for if
            } // for (i < Shots.Count)


            // count the update loops
            loopCount++;

            // Update actor
            base.Update();
        } // Update()
Exemplo n.º 5
0
        } // GetDetails()

        #endregion

        #region LoadContent
        /// <summary> Loads all Content </summary>
        public override void LoadContent()
        {
            base.LoadContent();
            World.Gravity = new Vector2(0f, 10f);

            HasCursor           = true; // Enable MouseCursor for aiming
            EnableCameraControl = true; // Enable the Camera
            HasVirtualStick     = false;


            fadeUp = new FadeUp();

            // Stop Music and Play the Game Music instead!
            Sound.StopMusic();
            Sound.Play(Sound.Sounds.GameMusic);

            //AnimatedObject animatedObject = new AnimatedObject(new Vector2(461, 2), 1.4f, new Animation("Enemies/Schnabelman", 5, 12, 0, 58, 3000, true));
            //AnimatedObject animatedObject2 = new AnimatedObject(new Vector2(240, 12), 0.75f, new Animation("Backgrounds/cogwheel", 4, 15, 0, 60, 3000, true));
            //AnimatedObject animatedObject3 = new AnimatedObject(new Vector2(368, 9), 7f, new Animation("Enemies/Tinman", 6, 13, 0, 71, 2000, true));
            StaticObject staticObject  = new StaticObject("Enemies/Elephant", new Vector2(240, 0f), 2.8f);
            StaticObject staticObject2 = new StaticObject("Enemies/stomper_housing", new Vector2(862f, 9f), 1f);
            StaticObject staticObject3 = new StaticObject("Enemies/tentontower", new Vector2(190f, 17f), 0.2f);

            //staticObject.Rotation = MathHelper.ToRadians(90);

            healthBar = new HealthBar(GameSettings.PlayerHitpoints);
            vehicle   = new Vehicle();
            vehicle.SetPosition(new Vector2(22.0f, 0.0f));


            // Create Level
            int     numSegments        = 1;//10;
            Vector2 levelStartPosition = new Vector2(30, 30);

            for (int i = 0; i < numSegments; i++)
            {
                PhysicTexture texture = new PhysicTexture(levelStartPosition, 0.1f, "Levels/island1_n", "Levels/island1_c");
                levelStartPosition.X += texture.Size.X;  //-1; // falls lücken entstehen
                PhysicTexture texture2 = new PhysicTexture(new Vector2(levelStartPosition.X + 19.89f, 47.1f), 0.1f, "Levels/island2_n", "Levels/island2_c");
                levelStartPosition.X += texture2.Size.X; //-1; // falls lücken entstehen
                PhysicTexture texture3 = new PhysicTexture(new Vector2(levelStartPosition.X + 16f, 43.6f), 0.1f, "Levels/island3_n", "Levels/island3_c");
                levelStartPosition.X += texture3.Size.X; // falls lücken entstehen
                PhysicTexture texture4 = new PhysicTexture(new Vector2(levelStartPosition.X + 13.5f, 42f), 0.1f, "Levels/island4_n", "Levels/island4_c");
                levelStartPosition.X += texture4.Size.X; // falls lücken entstehen
                PhysicTexture texture5 = new PhysicTexture(new Vector2(levelStartPosition.X + 5.8f, 43.1f), 0.1f, "Levels/island5_n", "Levels/island5_c");
                levelStartPosition.X += texture5.Size.X; //-1; // falls lücken entstehen
                PhysicTexture texture6 = new PhysicTexture(new Vector2(levelStartPosition.X + 16.3f, 49.5f), 0.1f, "Levels/island6_n", "Levels/island6_c");
                levelStartPosition.X += texture6.Size.X; //-1; // falls lücken entstehen
                PhysicTexture texture7 = new PhysicTexture(new Vector2(levelStartPosition.X + 16.3f, 49.5f), 0.1f, "Levels/island7_n", "Levels/island7_c");
                levelStartPosition.X += texture7.Size.X; //-1; // falls lücken entstehen
                PhysicTexture texture8 = new PhysicTexture(new Vector2(levelStartPosition.X + 16.3f, 50.6f), 0.1f, "Levels/island8_n", "Levels/island8_c");
                levelStartPosition.X += texture8.Size.X; //-1; // falls lücken entstehen
                PhysicTexture texture9 = new PhysicTexture(new Vector2(levelStartPosition.X + 34.3f, 27.62f), 0.1f, "Levels/island9_n", "Levels/island9_c");
                levelStartPosition.X += texture9.Size.X; //-1; // falls lücken entstehen


                physicTextures.Add(texture);
                physicTextures.Add(texture2);
                physicTextures.Add(texture3);
                physicTextures.Add(texture4);
                physicTextures.Add(texture5);
                physicTextures.Add(texture6);
                physicTextures.Add(texture7);
                physicTextures.Add(texture8);
                physicTextures.Add(texture9);
                //levelStartPosition.Y += 10f;
            }


            // Create Towers                          Position2D           HP   diffuseTexture  collisionTexture _c
            physicBreakables.Add(new PhysicBreakable(new Vector2(136, 17), GameSettings.HeavyTowerHitPoints, "Enemies/towerbig", "Enemies/towerbig_c", true));
            physicBreakables.Add(new PhysicBreakable(new Vector2(331, 1.5f), GameSettings.HeavyTowerHitPoints, "Enemies/towerbig", "Enemies/towerbig_c", true));
            //physicBreakables.Add(new PhysicBreakable(new Vector2(264, 19), GameSettings.HeavyTowerHitPoints, "Enemies/tower", "Enemies/tower_c", true));
            //physicBreakables.Add(new PhysicBreakable(new Vector2(344, 9), GameSettings.HeavyTowerHitPoints, "Enemies/tower", "Enemies/tower_c", true));
            //physicBreakables.Add(new PhysicBreakable(new Vector2(588, 32), GameSettings.HeavyTowerHitPoints, "Enemies/tower", "Enemies/tower_c", true));

            // Create Level (handles Actors updating and drawing + AI)
            level = new Level();



            // Create Triggers
            BreakableTrigger breakableTrigger = new BreakableTrigger(new Vector2(378, 12));
            EnemyTrigger     trigger          = new EnemyTrigger(new Vector2(150, 23));
            //EnemyTrigger trigger2 = new EnemyTrigger(new Vector2(242, 17));
            //EnemyTrigger trigger3 = new EnemyTrigger(new Vector2(306, 3));
            //  BreakableTrigger breakableTrigger2 = new BreakableTrigger(new Vector2(377, 8));


            // Create Eyes
            //Animation eyeAnimation = new Animation("Enemies/Eye", 4, 15, 0, 59, 5000, true);
            Eye eye  = new Eye(new Vector2(40, -8), 1.0f, new Animation("Enemies/Eye", 4, 15, 0, 59, 5000, true));
            Eye eye2 = new Eye(new Vector2(60, -4), 1.0f, new Animation("Enemies/Eye", 4, 15, 0, 59, 5000, true));
            Eye eye3 = new Eye(new Vector2(80, -1), 1.0f, new Animation("Enemies/Eye", 4, 15, 0, 59, 5000, true));
            Eye eye4 = new Eye(new Vector2(100, 3), 1.0f, new Animation("Enemies/Eye", 4, 15, 0, 59, 5000, true));

            // Create Bridges
            bridge1      = new Bridge(new Vector2(549.2f, -2f), 20f, new Vector2(0f, -10f));
            chainBridge1 = new ChainBridge(new Vector2(590.8f, -2.3f));
            trap         = new Trap();

            // Create Background
            CreateParallaxBG();

            // Create Particles
            particleManager = new ParticleSystemManager();

            Camera.MinRotation = -0.05f;
            Camera.MaxRotation = 0.05f;

            Camera.TrackingBody   = vehicle.Body;
            Camera.EnableTracking = true;
            // LoadContent()
        }
Exemplo n.º 6
0
        } // CreateBodyByList(list)

        #endregion

        #region Update
        /// <summary>
        /// Updates the PhysicBreakable
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns></returns>
        public void Update(GameTime gameTime)
        {
            // used in BreakableTrigger
            if (Animate)
            {
                // Bounce control constants
                float       bounce;
                const float BounceHeight = 0.18f;//0.18f;
                const float BounceRate   = 3.0f;
                //const float BounceSync = -0.75f;

                // Bounce along a sine curve over time.
                // Include the X coordinate so that neighboring gems bounce in a nice wave pattern ?
                double t = gameTime.TotalGameTime.TotalSeconds * BounceRate; //+ body.Position.X * BounceSync;
                bounce = (float)Math.Sin(t) * BounceHeight;                  // *ConvertUnits.ToSimUnits(_textureBodyXna.Height);// *32; //texture.Height;

                Vector2 position = body.Position;
                position.Y   -= bounce;
                body.Position = position;
            }

            if (body.UserData.ToString() == "damage")
            {
                hitpoints    -= GameSettings.PlayerDamage;
                body.UserData = "enemyTower";
            }

            // Is Shooting for the Tower allowed?
            for (int t = 0; t < GameDemo1.physicBreakables.Count; t++)
            {
                if (Vector2.Distance(GameDemo1.vehicle.Position, ConvertUnits.ToDisplayUnits(GameDemo1.physicBreakables[t].body.Position))
                    < GameDemo1.vehicle.Radius + GameDemo1.physicBreakables[t].AggroRange)
                {
                    GameDemo1.physicBreakables[t].MayFire = true;
                }
                else
                {
                    GameDemo1.physicBreakables[t].MayFire = false;
                }
            }

            // Break the Body if we have no more hitpoints and Start the Timer
            if (hitpoints <= 0 && _breakableBody != null)
            {
                _breakableBody.Break();
                disableLevelCollision = true;
                TimeBroken           += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (TimeBroken >= DeleteAfter)
            {
                Delete();

                if (WithCannon == true)
                {
                    cannon.Body.Dispose();

                    if (enemyShot != null)
                    {
                        enemyShot.shotBody.Dispose();
                    }
                }
                TimeBroken -= DeleteAfter;
            }

            if (_breakableBody != null && _broken != _breakableBody.Broken)
            {
                _reselect = _broken = true;
            }

            if (_reselect || _parts.Length == 0)
            {
                _parts = PhysicsGameScreen.World.BodyList.Where(
                    b => b.FixtureList.Any(
                        f => f.UserData is Guid && _infos.ContainsKey((Guid)f.UserData))
                    ).ToArray();

                // if we are broken, disable collision with level or car
                if (disableLevelCollision)
                {
                    foreach (Body b in _parts)
                    {
                        b.IgnoreCollisionWith(GameDemo1.vehicle.Body);
                        b.IgnoreCollisionWith(GameDemo1.vehicle.WheelBackBody);
                        b.IgnoreCollisionWith(GameDemo1.vehicle.WheelFrontBody);
                        b.IgnoreCollisionWith(GameDemo1.vehicle.cannon.Body);
                    }
                }

                // case when we are Destroyed
                if (_reselect == true)
                {
                    // Only explode if this are no background object. else vehicle gets raped too hard :(
                    if (Explode)
                    {
                        Vector2 explosionDirection = GameDemo1.vehicle.cannon.Body.Position - _breakableBody.MainBody.Position;
                        explosionDirection.Normalize();
                        new Explosion(_breakableBody.MainBody.Position + explosionDirection, 200);
                    }

                    // still play explosion sound, else it's too booring!
                    Sound.Play(Sound.Sounds.Explosion);
                    GameDemo1.particleManager.AddExplosion(body.Position);

                    // receive Score
                    GameSettings.HighScore += (uint)GameSettings.TowerScore;
                    FadeUp.AddTextMessage("+ " + GameSettings.TowerScore, FadeUp.TextTypes.Score, body.Position);

                    // Don't animate any more, causes errors!
                    Animate            = false;
                    body.IgnoreGravity = false; // Gravity enabled = better performance + look&feel!
                    if (WithCannon)             // drop a Pickup if this breakable has a cannon
                    {
                        new PickUp("AI/health", body.Position, 2.0f);
                    }
                }
                _reselect = false;
            }

            // Update cannon and shots if we are not broken
            if (!_broken && WithCannon == true)
            {
                if (enemyShot != null && enemyShot.shotBody.UserData.ToString() == "disable")
                {
                    enemyShot.shotBody.Dispose();
                    enemyShot = null;
                }

                cannon.Update();
                TimeSinceShot += (float)gameTime.ElapsedGameTime.TotalSeconds; //Zeit seit letztem Update dazuaddieren

                if (TimeSinceShot >= ShotTimer)                                //Wenn die vergangene Zeit größer ist als der Timer, do...
                {
                    TimeSinceShot = 0;

                    if (MayFire == true)
                    {
                        Sound.Play(Sound.Sounds.CannonShot);
                        GameDemo1.particleManager.AddEnemyCannonParticles(cannon.Body);
                        UpdateShot();
                    }
                }
            }
        } // Update(gameTime)