// 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; } }
//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); } }
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); } }
//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(); } }
// 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--; } } } }