示例#1
0
 //Actualitza la velocitat segons l'acceleració actual
 public void UpdateVelocity()
 {
     Velocity += Acceleration;
     if (VectorOps.ModuloVector(Velocity) > Velocity_Threshold)
     {
         Velocity = VectorOps.UnitVector(Velocity) * Velocity_Threshold;
     }
 }
示例#2
0
        //Aplica els efectes del fregament en el moviment
        public void UpdateFriction()
        {
            float VelocityModulo = VectorOps.ModuloVector(Velocity);

            VelocityModulo -= Friction;
            if (VelocityModulo > 0)
            {
                Velocity = VectorOps.UnitVector(Velocity) * VelocityModulo;
            }
            else
            {
                Velocity = Vector2.Zero;
            }
        }
 // constrctor per inicialitzar el projectil
 public Projectile(Vector2 origin, Vector2 target, float velocity, int shooterID, Texture2D texture, float scale, float damage, char projectileType)
     : base(texture)
 {
     this.ShooterID      = shooterID;
     this.origin         = origin;
     this.Target         = target;
     this.LinearVelocity = VectorOps.ModuloVector(new Vector2((origin.X - target.X), (origin.Y - target.Y))) / 20;
     this._texture       = texture;
     this.ProjectileType = projectileType;
     this.trajectory     = this.Target - this.origin;
     this.Position       = this.origin;
     this.Direction      = VectorOps.UnitVector(target - origin);
     this.Scale          = scale;
     this.Damage         = damage;
     this.Layer          = 0.01f;
     //IsSaltShoot = true;
 }
示例#4
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F11) && (_previousState.IsKeyUp(Keys.F11)))
            {
                graphics.ToggleFullScreen();
            }



            // Detectem inputs al teclat
            inputManager.detectKeysPressed();
            _previousState = Keyboard.GetState();

            // Actualitzem direcció i moviment del playerChar segons els inputs
            playerChar.Direction = VectorOps.UnitVector(inputManager.GetMousePosition() - playerChar.Position);

            if (inputManager.RightCtrlActive())
            {
                playerChar.MoveRight();
            }
            if (inputManager.LeftCtrlActive())
            {
                playerChar.MoveLeft();
            }
            if (inputManager.UpCtrlActive())
            {
                playerChar.MoveUp();
            }
            if (inputManager.DownCtrlActive())
            {
                playerChar.MoveDown();
            }


            //Actualitzem moviment del llimac de prova ---------------------Babo prova
            playerChar2.Direction = VectorOps.UnitVector(playerChar.Position - playerChar2.Position);

            if (!Slug2Direction)
            {
                playerChar2.MoveRight();
            }
            else
            {
                playerChar2.MoveLeft();
            }
            if (Slug2Direction2)
            {
                playerChar2.MoveUp();
            }
            else
            {
                playerChar2.MoveDown();
            }

            if ((playerChar2.Position.X > graphics.PreferredBackBufferWidth))
            {
                Slug2Direction = true;
            }
            else if (playerChar2.Position.X < 0)
            {
                Slug2Direction = false;
            }

            if (playerChar2.Position.Y > graphics.PreferredBackBufferHeight)
            {
                Slug2Direction2 = true;
            }
            else if (playerChar2.Position.Y < 0)
            {
                Slug2Direction2 = false;
            }

            //Actualitzem moviment del llimac de prova ---------------------Limax prova
            playerChar3.Direction = VectorOps.UnitVector(playerChar.Position - playerChar3.Position);

            if (!Slug3Direction)
            {
                playerChar3.MoveRight();
            }
            else
            {
                playerChar3.MoveLeft();
            }
            if (Slug3Direction2)
            {
                playerChar3.MoveUp();
            }
            else
            {
                playerChar3.MoveDown();
            }

            if ((playerChar3.Position.X > graphics.PreferredBackBufferWidth))
            {
                Slug3Direction = true;
            }
            else if (playerChar3.Position.X < 0)
            {
                Slug3Direction = false;
            }

            if (playerChar3.Position.Y > graphics.PreferredBackBufferHeight)
            {
                Slug3Direction2 = true;
            }
            else if (playerChar3.Position.Y < 0)
            {
                Slug3Direction2 = false;
            }

            // llançem projectils segons els inputs del jugador
            inputManager.DetectMouseClicks();
            projectileManager.Update(gameTime, inputManager.GetMouseWheelValue(), overlaySprites, characterSprites);
            if (inputManager.LeftMouseClick())
            {
                Vector2 projOrigin = playerChar.Position;
                Vector2 projTarget = inputManager.GetMousePosition();
                int     shooterID  = 1; // caldrà gestionar els ID's des del server
                projectileManager.AddProjectile(projOrigin, projTarget, shooterID);
            }

            //if (EnemyShoot.Next(0,32) == 0) //--------------------------- Babo prova
            //projectileEngine.AddProjectile(playerChar2.Position, playerChar.Position, projectileTexture["Slimed"], 2,'S');

            //Això actualitzaria els objectes del escenari
            foreach (var ScenarioObj in scenarioSprites)
            {
                ScenarioObj.Update(gameTime);
            }

            characterEngine.Update(gameTime, slimeSprites, scenarioSprites);
            // Això hauria de moure els projectils, calcular les colisions i notificar als characters si hi ha hagut dany.
            projectileEngine.UpdateProjectiles(gameTime, characterSprites, scenarioSprites);

            // Generem les babes amb una certa espera per no sobrecarregar i les instanciem al update del personatge
            timer.Elapsed += OnTimedEvent;

            foreach (var character in characterSprites.ToArray())
            {
                character.Update(gameTime, characterSprites);
                heartManager.UpdateHealth(character.IDcharacter, character.Health);
                if ((SlimeTime > 80) && (slimeSprites.Count < 400))
                {
                    slimeSprites.Add(
                        new Slime(new Vector2(character.Position.X, character.Position.Y + 20), character.IDcharacter, slimeTexture, 0.15f)
                    {
                        timer = 0,
                    }
                        );
                    character.isSlip = false;
                }
            }

            if ((SlimeTime > 80))
            {
                foreach (var slime in slimeSprites)
                {
                    slime.timer++;
                }
                SlimeTime = 0;
            }

            //Això hauria de fer reaccionar les babes a projectils, characters i objectes de l'escenari
            slimeEngine.UpdateSlime(gameTime, characterSprites, projectileSprites, scenarioSprites);

            foreach (var overlay in this.overlaySprites)
            {
                overlay.Update(gameTime, overlaySprites);
            }

            PostUpdate();
            base.Update(gameTime);
        }