Exemple #1
0
        // Detectem colisions i actualitzem posicions, timers i flags del character
        public void Update(GameTime gameTime, List <Character> characterSprites)
        {
            if (isHit)
            {
                _PainTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (_PainTimer > 0.3f)
            {
                _PainTimer = 0f;
                isHit      = false;
            }

            //Reprodueix l'animació
            SetAnimations();
            float Framespeed = 0.2f * 4 / (4 + VectorOps.ModuloVector(VelocityInform));

            this._animationManager.Update(gameTime, Framespeed);

            //"Equació" per definir a quina capa es mostrarà el "sprite" perquè un personatge no li estigui trapitjant la cara al altre
            float LayerValue = this.Position.Y / 10000;

            if (LayerValue > 0.4)
            {
                Layer = 0.4f;
            }
            else
            {
                Layer = LayerValue + 0.01f;
            }
        }
Exemple #2
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;
     }
 }
 public bool IsNear(Vector2 position, float threshold)
 {
     if (VectorOps.ModuloVector(new Vector2(this.Position.X - position.X, this.Position.Y - position.Y)) < threshold)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #4
0
 public bool IsNear(Vector2 position)
 {
     if (VectorOps.ModuloVector(new Vector2(this.Position.X - position.X, this.Position.Y - position.Y)) < radiumSlime)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public bool IsNear(Vector2 Position)
 {
     if ((VectorOps.ModuloVector(this.Position - Position)) > (Math.Max(this._texture.Width, this._texture.Height) * this.HitBoxScale * this.Scale))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #6
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;
 }
        // Mecànica de la sal directe
        private void DirectSaltUpdate(List <Character> characterList, List <ScenarioObjects> objectsList, Projectile projectile)
        {
            //Elimina la sal en un límit de distancia
            if (VectorOps.ModuloVector(projectile.Origin - projectile.Position) > 2000)
            {
                projectile.KillProjectile();
            }

            //Definim la colisió entre la sal
            foreach (var projectileItem in projectileList)
            {
                if ((projectile.DetectCollision(projectileItem)) && (projectileItem != projectile))
                {
                    projectile.KillProjectile();
                }
            }

            //Definir la colisió de la sal
            foreach (var character in characterList)
            {
                if (projectile.DetectCollision(character))
                {
                    if (projectile.ShooterID != character.IDcharacter)
                    {
                        // notificar el dany al personatge!!!
                        character.NotifyHit(projectile.Direction, projectile.ShooterID, projectile.Damage, projectile.LinearVelocity);
                        projectile.KillProjectile();
                    }
                }
            }

            foreach (var Object in objectsList)
            {
                if (projectile.DetectCollision(Object))
                {
                    projectile.KillProjectile();
                }
            }
        }
        // Mecànica de la sal no neutoniana
        private void SlimedSaltUpdate(List <Character> characterList, List <ScenarioObjects> objectsList, Projectile projectile)
        {
            //Elimina la sal en un límit de distancia
            if (VectorOps.ModuloVector(projectile.Origin - projectile.Position) > 2000)
            {
                projectile.KillProjectile();
            }

            //Definim la colisió entre la sal
            foreach (var projectileItem in projectileList)
            {
                if ((projectile.DetectCollision(projectileItem)) && (projectileItem != projectile))
                {
                    if (projectileItem.ProjectileType == 'S')
                    {
                        if (projectile.DetectBottomCollision(projectileItem))
                        {
                            projectile.Direction.Y = Math.Abs(projectile.Direction.Y);
                            projectile.HitCount++;
                        }

                        if (projectile.DetectTopCollision(projectileItem))
                        {
                            projectile.Direction.Y = -Math.Abs(projectile.Direction.Y);
                            projectile.HitCount++;
                        }

                        if (projectile.DetectRightCollision(projectileItem))
                        {
                            projectile.Direction.X = Math.Abs(projectile.Direction.X);
                            projectile.HitCount++;
                        }
                        if (projectile.DetectLeftCollision(projectileItem))
                        {
                            projectile.Direction.X = -Math.Abs(projectile.Direction.X);
                            projectile.HitCount++;
                        }
                    }
                    else
                    {
                        projectile.KillProjectile();
                    }
                }
            }

            //Definir la colisió de la sal
            foreach (var character in characterList)
            {
                if (projectile.DetectCollision(character))
                {
                    if ((projectile.ShooterID != character.IDcharacter) || (projectile.HitCount != 0))
                    {
                        // notificar el dany al personatge!!!
                        character.NotifyHit(projectile.Direction, projectile.ShooterID, projectile.Damage, projectile.LinearVelocity);
                        projectile.KillProjectile();
                    }
                }
            }

            foreach (var Object in objectsList)
            {
                if (projectile.DetectBottomCollision(Object))
                {
                    projectile.Direction.Y = Math.Abs(projectile.Direction.Y);
                    projectile.HitCount++;
                }

                if (projectile.DetectTopCollision(Object))
                {
                    projectile.Direction.Y = -Math.Abs(projectile.Direction.Y);
                    projectile.HitCount++;
                }

                if (projectile.DetectRightCollision(Object))
                {
                    projectile.Direction.X = Math.Abs(projectile.Direction.X);
                    projectile.HitCount++;
                }
                if (projectile.DetectLeftCollision(Object))
                {
                    projectile.Direction.X = -Math.Abs(projectile.Direction.X);
                    projectile.HitCount++;
                }
            }

            if (projectile.HitCount > 10)
            {
                projectile.KillProjectile();
            }
        }
Exemple #10
0
        public void DrawText(SpriteBatch spriteBatch)
        {
            var fontY = 10;

            foreach (var Character in _CharacterSprite)
            {
                spriteBatch.DrawString(_font, string.Format("Direction: {0}    Velocity: {1}    Slipping:{2}", VectorOps.Vector2ToDeg(Character.Direction), Character.VelocityInform, Character.isSlip), new Vector2(10, fontY += 20), Color.Black);
            }

            spriteBatch.DrawString(_font, string.Format("Mouse Position: {0}", new Vector2(Mouse.GetState().X, Mouse.GetState().Y)), new Vector2(10, fontY += 20), Color.Black);
            spriteBatch.DrawString(_font, string.Format("SlimeTimer: {0}", _timer1), new Vector2(10, fontY += 20), Color.Black);
            spriteBatch.DrawString(_font, string.Format("Screen Dimensions: {0}", new Vector2(widthscreen, heightscreen)), new Vector2(10, fontY += 20), Color.Black);
            spriteBatch.DrawString(_font, string.Format("WheelMouse: {0}", Mouse.GetState().ScrollWheelValue), new Vector2(10, fontY             += 20), Color.Black);
        }
Exemple #11
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);
        }
        // Mecànica de la sal no neutoniana
        private void SlimedSaltUpdate(List <Character> characterList, List <ScenarioObjects> objectsList, Projectile projectile, bool testMode, Character Controllable)
        {
            //Elimina la sal en un límit de distancia
            if (VectorOps.ModuloVector(projectile.Origin - projectile.Position) > 2000)
            {
                projectile.KillProjectile();
                foreach (Character chara in characterList)
                {
                    if (chara.IDcharacter == projectile.ShooterID)
                    {
                        chara.BulletNumber--;
                    }
                }
            }


            //Definim la colisió entre la sal
            foreach (var projectileItem in projectileList)
            {
                if ((projectile.DetectCollision(projectileItem)) && (projectileItem != projectile))
                {
                    if (projectileItem.ProjectileType == 'S')
                    {
                        Vector2 Velocity = new Vector2(projectile.LinearVelocity * projectile.Direction.X, projectile.LinearVelocity * projectile.Direction.X);
                        if (projectile.DetectBottomCollision(projectileItem))
                        {
                            //projectile.Direction.Y = Math.Abs(projectile.Direction.Y);
                            Velocity.Y = Math.Abs(projectileItem.Velocity.Y);
                            projectile.HitCount++;
                        }

                        if (projectile.DetectTopCollision(projectileItem))
                        {
                            //projectile.Direction.Y = -Math.Abs(projectile.Direction.Y);
                            Velocity.Y = -Math.Abs(projectileItem.Velocity.Y);
                            projectile.HitCount++;
                        }

                        if (projectile.DetectRightCollision(projectileItem))
                        {
                            //projectile.Direction.X = Math.Abs(projectile.Direction.X);
                            Velocity.X = Math.Abs(projectileItem.Velocity.X);
                            projectile.HitCount++;
                        }
                        if (projectile.DetectLeftCollision(projectileItem))
                        {
                            //projectile.Direction.X = -Math.Abs(projectile.Direction.X);
                            Velocity.X = -Math.Abs(projectileItem.Velocity.X);
                            projectile.HitCount++;
                        }

                        projectile.LinearVelocity = VectorOps.ModuloVector(Velocity);
                        projectile.Direction      = new Vector2(Velocity.X / projectile.LinearVelocity, Velocity.Y / projectile.LinearVelocity);
                    }
                    else
                    {
                        projectile.KillProjectile();
                        foreach (Character chara in characterList)
                        {
                            if (chara.IDcharacter == projectile.ShooterID)
                            {
                                chara.BulletNumber--;
                            }
                        }
                    }
                }
            }

            //Definir la colisió de la sal
            foreach (var character in characterList)
            {
                if (projectile.DetectCollision(character))
                {
                    if ((projectile.ShooterID != character.IDcharacter) || (projectile.HitCount != 0))
                    {
                        //info del qui dispara
                        float shooterAttack = 1f;
                        char  shooterType   = 'B';
                        foreach (var chara in characterList)
                        {
                            if (chara.IDcharacter == projectile.ShooterID)
                            {
                                shooterAttack = chara.Attack;
                                shooterType   = chara.charType;
                            }
                        }
                        // notificar el dany al personatge!!!
                        if ((!character.SlugHability) || (!((character.charType == 'S') || (character.charCopied == 'S'))))
                        {
                            character.NotifyHit(projectile.Direction, projectile.ShooterID, projectile.Damage, projectile.LinearVelocity, shooterAttack, shooterType);
                        }
                        bool Rejected = false;

                        if ((character.charType == 'S') || (character.charCopied == 'S'))
                        {
                            Random bulletRejected = new Random();
                            if (character.SlugHability)
                            {
                                Rejected = true;
                            }
                            if (bulletRejected.Next(0, 9) == 0)
                            {
                                Rejected = true;
                            }
                        }
                        //Destrueix l'objecte
                        projectile.KillProjectile();
                        foreach (Character chara in characterList)
                        {
                            if (chara.IDcharacter == projectile.ShooterID)
                            {
                                chara.BulletNumber--;
                            }
                        }

                        if ((Rejected) && ((testMode) || (character.IDcharacter == Controllable.IDcharacter)))
                        {
                            newProjectile.Add(new Projectile(projectile.Position, projectile.Position - (projectile.Direction * VectorOps.ModuloVector(projectile.Origin - projectile.Target)), masterProjVelocity, character.IDcharacter, projectile._texture, masterProjScale, projectile.Damage, projectile.ProjectileType, character.NextProjectileID)
                            {
                                delayGeneration = 200,
                            });
                            character.NextProjectileID++;
                        }
                    }
                }
            }

            foreach (var Object in objectsList)
            {
                if (projectile.DetectBottomCollision(Object))
                {
                    projectile.Direction.Y = Math.Abs(projectile.Direction.Y);
                    projectile.HitCount++;
                }

                if (projectile.DetectTopCollision(Object))
                {
                    projectile.Direction.Y = -Math.Abs(projectile.Direction.Y);
                    projectile.HitCount++;
                }

                if (projectile.DetectRightCollision(Object))
                {
                    projectile.Direction.X = Math.Abs(projectile.Direction.X);
                    projectile.HitCount++;
                }
                if (projectile.DetectLeftCollision(Object))
                {
                    projectile.Direction.X = -Math.Abs(projectile.Direction.X);
                    projectile.HitCount++;
                }
            }

            if (projectile.HitCount > 10)
            {
                projectile.KillProjectile();
                foreach (Character chara in characterList)
                {
                    if (chara.IDcharacter == projectile.ShooterID)
                    {
                        chara.BulletNumber--;
                    }
                }
            }
        }
Exemple #13
0
        //Apartat de les animacions
        protected virtual void SetAnimations()
        {
            if (isHit)
            {
                float angle = VectorOps.Vector2ToDeg(Direction);
                //Animació de ser colpejat per la salt
                if (angle < 315 && angle > 225)
                {
                    _animationManager.Play(_animations["Slug up hit"]);
                }
                else if (angle >= 315 || angle < 45)
                {
                    _animationManager.Play(_animations["Slug right hit"]);
                }
                else if (angle <= 225 && angle > 135)
                {
                    _animationManager.Play(_animations["Slug left hit"]);
                }
                else
                {
                    _animationManager.Play(_animations["Slug down hit"]);
                }
            }
            else
            {
                // Detecció del angle de dispar amb la corresponent animació (probablement s'haurà de fer de forma més eficient)
                // Angle entre animacions: 18 graus || pi/10 radiants -- Desfasament: 9 graus || pi/20 radiant

                float angle = VectorOps.Vector2ToDeg(Direction);
                if ((angle <= 9 && angle >= 0) || (angle <= 360 && angle > 351))
                {
                    _animationManager.Play(_animations["Slug right0"]);
                }
                else if (angle <= 27 && angle > 9)
                {
                    _animationManager.Play(_animations["Slug right-22_5"]);
                }
                else if (angle <= 45 && angle > 27)
                {
                    _animationManager.Play(_animations["Slug right-45"]);
                }
                else if (angle <= 63 && angle > 45)
                {
                    _animationManager.Play(_animations["Slug down45"]);
                }
                else if (angle <= 81 && angle > 63)
                {
                    _animationManager.Play(_animations["Slug down22_5"]);
                }
                else if (angle <= 99 && angle > 81)
                {
                    _animationManager.Play(_animations["Slug down0"]);
                }
                else if (angle <= 117 && angle > 99)
                {
                    _animationManager.Play(_animations["Slug down-22_5"]);
                }
                else if (angle <= 135 && angle > 117)
                {
                    _animationManager.Play(_animations["Slug down-45"]);
                }
                else if (angle <= 153 && angle > 135)
                {
                    _animationManager.Play(_animations["Slug left45"]);
                }
                else if (angle <= 171 && angle > 153)
                {
                    _animationManager.Play(_animations["Slug left22_5"]);
                }
                else if (angle <= 189 && angle > 171)
                {
                    _animationManager.Play(_animations["Slug left0"]);
                }
                else if (angle <= 207 && angle > 189)
                {
                    _animationManager.Play(_animations["Slug left-22_5"]);
                }
                else if (angle <= 225 && angle > 207)
                {
                    _animationManager.Play(_animations["Slug left-45"]);
                }
                else if (angle <= 243 && angle > 225)
                {
                    _animationManager.Play(_animations["Slug up45"]);
                }
                else if (angle <= 261 && angle > 243)
                {
                    _animationManager.Play(_animations["Slug up22_5"]);
                }
                else if (angle <= 279 && angle > 261)
                {
                    _animationManager.Play(_animations["Slug up0"]);
                }
                else if (angle <= 297 && angle > 279)
                {
                    _animationManager.Play(_animations["Slug up-22_5"]);
                }
                else if (angle <= 315 && angle > 297)
                {
                    _animationManager.Play(_animations["Slug up-45"]);
                }
                else if (angle <= 333 && angle > 315)
                {
                    _animationManager.Play(_animations["Slug right45"]);
                }
                else if (angle <= 351 && angle > 333)
                {
                    _animationManager.Play(_animations["Slug right22_5"]);
                }
                else
                {
                    _animationManager.Play(_animations["Slug down0"]);
                }
            }
        }