コード例 #1
0
 public virtual void GotShoot(Weapon w)
 {
     if (ID != w.createdPlayerID)                               //test if the weapon is from the player and decrease the Health
     {
         Health -= w.damage;
         //decrease movement (implement later)
     }
 }
コード例 #2
0
 public virtual void GotShoot(Weapon w)
 {
     if (ID != w.createdPlayerID)                               //test if the weapon is from the player and decrease the Health
     {
         Health -= w.damage;
         CurrentSpeed = (CurrentSpeed * 0.9f);
     }
 }
コード例 #3
0
 public Player(string uName, BaseShip _ship, Weapon _weapon)
 {
     UserName = uName;
     Ship = _ship;
     Weapon = _weapon;
     Ship.weapon = Weapon;
     isActive = true;
 }
コード例 #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>(@"SpriteFont\MessgaeFont");

            _textureShip = Content.Load<Texture2D>(@"Assets\Textures\Ships\msShip");
            _textureWeapon = Content.Load<Texture2D>(@"Assets\Textures\Weapons\missle");

            _ms_textureS = Content.Load<Texture2D>(@"Assets\Textures\Ships\msShip");
            _ms_textureW = Content.Load<Texture2D>(@"Assets\Textures\Weapons\missle");

            _tc_textureS = Content.Load<Texture2D>(@"Assets\Textures\Ships\tcShip");
            _tc_textureW = Content.Load<Texture2D>(@"Assets\Textures\Weapons\laser");

            _ah_textureS = Content.Load<Texture2D>(@"Assests\Textures\Ships\AH_Ship");
            _ah_textureW = Content.Load<Texture2D>(@"Assets\Textures\Weapons\bomb");


            testWeapon = new Weapon("0", _textureWeapon, 20f, Vector2.Zero, Vector2.Zero, 0f, 20);
            testShip = new BaseShip("0", _textureShip, 5.0f);

            //ms_weapon = new MS_weapon("0", _textureWeapon, 20f, Vector2.Zero, Vector2.Zero, 0f, 20);
            ms_ship = new MS_ship("0", _textureShip, 7.0f);
            //ms_ship.weapon = ms_weapon;
            testShip.weapon = testWeapon;


            TC_ship = new TC_ship("2", _tc_textureS, 6.0f);

            AH_ship = new AH_Ship("3", _ah_textureS, 5.0f);

            // TODO: use this.Content to load your game content here
        }
コード例 #5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            newState = Keyboard.GetState();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            newWeapon = testShip.ShipUpdate(newState, oldState); //update the ship and if the ship fired return a new projectile 


            if (newWeapon != null)
            {
                Weapons.Add(newWeapon);
            }

            if (Weapons.Count > 0)
            {
                foreach (Weapon item in Weapons)
                {
                    item.WeaponUpdate();
                }
            }

            ms_ship.ShipUpdate(newState, oldState);



            #region Collision

            foreach (var item in Weapons)
            {
                if (item.IsVisible)
                {
                    foreach (var ene in Enemies)
                    {
                        if (item.CollisiionDetection(ene.Ship.Rectangle)) //check if bullet hits any enemy
                        {
                            if (item.createdPlayerID != ene.Ship.Id)    //if the ID if the enemy is the same as the bullet
                            {
                                ene.Ship.GotShoot(item);                //ship got hit
                                item.IsVisible = false;                 //disable bullet
                                DestroyWeapons.Add(item);               //destroy bullet at the end (to clear the ram
                                if (!ene.Ship.IsVisible)                //check if ship get destroied 
                                    ene.isActive = false;               //deactivate the ship                               !!!!!!!!!!!!!!!! TO DO <-- !!!!!!!!!!!!!!!!!
                            }
                        }
                    }
                    if (item.Rectangle.Intersects(testPlayer.Ship.Rectangle))    //check if playership got hit by the Weapon
                    {
                        testPlayer.Ship.GotShoot(item);                         //ship got hit
                        item.IsVisible = false;                                 //disable the weapon
                        DestroyWeapons.Add(item);
                    }
                }
            }

            foreach (var item in Projectiles)
            {
                if (testPlayer.Ship.CollisiionDetection(item.Rectangle))    //check if any consumables hit player ship
                {
                    GotCollected.Add(item);
                    item.IsVisible = false;
                    testPlayer.Ship.CollectPickup(item);
                }

                foreach (var ene in Enemies)
                {
                    if (ene.Ship.CollisiionDetection(item.Rectangle))
                    {
                        ene.Ship.CollectPickup(item);
                        item.IsVisible = false;
                        GotCollected.Add(item);
                    }
                }
            }

            #endregion
            

            oldState = newState;

            base.Update(gameTime);
        }
コード例 #6
0
        public virtual Weapon ShipUpdate(KeyboardState newState, KeyboardState oldState)
        {


            #region Movement

            if (newState.IsKeyDown(Keys.W) && _position.Y > 32)         //handle vertical movement
            {
                moveVector += new Vector2(0, -CurrentSpeed);
                newFireDirection += new Vector2(0, -1);                    //the direction to fire
            }
            else if (newState.IsKeyDown(Keys.S) && _position.Y < 736)
            {
                moveVector += new Vector2(0, CurrentSpeed);
                newFireDirection += new Vector2(0, 1);
            }


            if (newState.IsKeyDown(Keys.A) && _position.X > 32)         //handle horizontal movement
            {
                moveVector += new Vector2(-CurrentSpeed, 0);
                newFireDirection += new Vector2(-1, 0);
            }
            else if (newState.IsKeyDown(Keys.D) && _position.X < 1252)
            {
                moveVector += new Vector2(CurrentSpeed, 0);
                newFireDirection += new Vector2(1, 0);
            }

            #endregion

            if (oldState != newState && newState.IsKeyDown(Keys.H) && weapon != null) //test if the player wants to shoot
                firedWeapon = Shoot(weapon.createdPlayerID, weapon.speed);
            else firedWeapon = null;

            if (newState.IsKeyDown(Keys.W) || newState.IsKeyDown(Keys.S) || newState.IsKeyDown(Keys.D) || newState.IsKeyDown(Keys.A))
            {
                //change some vars only if you moved at the same time
                angle = GetAngle();
                currentFireDirection = newFireDirection;
                newFireDirection = Vector2.Zero;
                _position += (moveVector * GetWeight());
            }

            moveVector = Vector2.Zero;

            return firedWeapon;
        }