コード例 #1
0
ファイル: EnemyManager.cs プロジェクト: bensisa/MeowKun
        public static void UpdateColission(Player player, ExplosionManager VFX, GUI guiInfo)
        {
            //use the Rectangle's build-in interscect function to determine if
            //two objects are overlapping
            Rectangle rect1, rect2;

            //Only create the rectangle once for the player
            rect1 = new Rectangle(
                (int)player.Position.X,
                (int)player.Position.Y,
                player.Width, player.Height);

            //Do the collision between the player and the enemies
            for (int i = 0; i < enemiesType1.Count; i++)
            {
                rect2 = new Rectangle(
                    (int)enemiesType1[i].Position.X,
                    (int)enemiesType1[i].Position.Y,
                    enemiesType1[i].Width,
                    enemiesType1[i].Height);
                //Now determine if the two objects collide with each other
                if (rect1.Intersects(rect2))
                {
                    //Subtract the health from the player based on the enemy damage
                    player.Health -= enemiesType1[i].Damage;
                    //Since the enemy collided with the player destroy it
                    enemiesType1[i].Health = 0;
                    /// Show the explosion where the enemy was...
                    VFX.AddExplosion(enemiesType1[i].LocationEnemy);

                    guiInfo.SCORE = guiInfo.SCORE + 10;
                    //if the player health is less than zero then player must be destroyed
                    guiInfo.PlayerHP -= 25;

                    if (guiInfo.PlayerHP == 0 && guiInfo.LIVES > 0)
                    {
                        player.Active    = false;
                        guiInfo.LIVES   -= 1;
                        guiInfo.PlayerHP = 100;
                    }
                }
            }
        }
コード例 #2
0
ファイル: EnemyManager.cs プロジェクト: bensisa/MeowKun
        public void UpdateEnemies(GameTime gameTime, Player player, ExplosionManager VFX, GUI guiInfo)
        {
            //spawn a new enemy every 1.5 sec
            if (gameTime.TotalGameTime - previousSpawnTime > enemySpawnTime)
            {
                previousSpawnTime = gameTime.TotalGameTime;
                AddEnemy();
            }

            UpdateColission(player, VFX, guiInfo);
            //Update enemies
            for (int i = (enemiesType1.Count - 1); i >= 0; i--)
            {
                enemiesType1[i].Update(gameTime);
                if (enemiesType1[i].Active == false)
                {
                    enemiesType1.RemoveAt(i);
                }
            }
        }
コード例 #3
0
//====================================================================================================================================================================================================================

        public void UpdateManagerLaser(GameTime gameTime, Player p, ExplosionManager vfx, GUI guiInfo, SoundEffect effect)
        {
            //Save the previous state of the keyboard and game pad so we can determine single key/button presses
            previousGamePadState  = currentGamePadState;
            previousKeyboardState = currentKeyboardState;

            //Read the current state of the keyboard and gamepad and store it
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            currentKeyboardState = Keyboard.GetState();

            if (Keyboard.GetState().IsKeyDown(Keys.Space) || GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed)
            {
                FireLaser(gameTime, p);
                //effect.Play();
            }

            // update laserbeams
            for (var i = 0; i < laserBeams.Count; i++)
            {
                laserBeams[i].Update(gameTime);
                // Remove the beam when its deactivated or is at the end of the screen.
                if (!laserBeams[i].Active || laserBeams[i].Position.X > graphicsInfo.X)
                {
                    laserBeams.Remove(laserBeams[i]);
                }
            }

            // detect collisions between the player and all enemies.
            foreach (Enemy e in EnemyManager.enemiesType1)
            {
                //create a retangle for the enemy
                Rectangle enemyRectangle = new Rectangle(
                    (int)e.Position.X,
                    (int)e.Position.Y,
                    e.Width,
                    e.Height);

                // now see if this enemy collide with any laser shots
                foreach (Laser L in LaserManager.laserBeams)
                {
                    // create a rectangle for this laserbeam
                    laserRectangle = new Rectangle(
                        (int)L.Position.X,
                        (int)L.Position.Y,
                        L.Width,
                        L.Height);

                    // test the bounds of the laser and enemy
                    if (laserRectangle.Intersects(enemyRectangle))
                    {
                        // Show the explosion where the enemy was...
                        vfx.AddExplosion(e.Position);

                        // kill off the enemy
                        e.Health      = 0;
                        guiInfo.SCORE = guiInfo.SCORE + 10;
                        //record the kill
                        //TBA

                        // kill off the laserbeam
                        L.Active = false;

                        // record your score
                        //TBA
                    }
                }
            }
        }