public void Update(Viking viking) { this.exp = viking.getExp(); this.toLevel = viking.getExpToLevel(); if (exp > toLevel) { viking.levelUp(); } currentExp.Width = (int)((exp / toLevel) * width); }
public void Initialize(GraphicsDevice g, Viking viking) { //TODO set fullhealth at startup fullHealth = new Rectangle(10, 10, 200, 20); currentHealth = new Rectangle(10, 10, 200, 20); healthBarLocationRectangle = new Rectangle(20, 40, 342, 138); testiColour = new Rectangle(0, 0, 62, 138); testiColour2 = new Rectangle(122, 40, 62, 138); pixel = new Texture2D(g, 1, 1); pixel.SetData <Color>(new Color[] { Color.White }); health = viking.getHealth(); }
public void Update(GameTime time, Viking viking, int speedmod) { gatePos.X -= speedmod; if (gatePos.X < (1920 - 450)) { FinishVisible = true; } else { FinishVisible = false; } if (viking.collidesWith(gatePos)) { finished = true; } }
public void Update(Viking viking) { //TODO resize current health box fullHealth.Width = 2 * viking.getFullHealth(); currentHealth.Width = 2 * viking.getHealth(); fullhealth = viking.getFullHealth(); //testiColour.Width -= 62/25; //testiColour2.Width -= 62/25; cLevel = viking.getLevel(); if (health > viking.getHealth()) { health -= 1; } if (health < viking.getHealth()) { health += 1; } }
public void Update(Viking viking, GameTime time, int modifySpeed) { if (bloodspatters.Count > 0) { drawblood = 1; for (int b = 0; b < bloodspatters.Count; b++) { bloodspatters[b].Update(time, modifySpeed); if (!bloodspatters[b].Active) { bloodspatters.RemoveAt(b); } } } else { drawblood = 0; } if (!Dead) { currenthealth.Width = (int)(0.5 * health); if (hit) { hittimer -= (float)time.ElapsedGameTime.TotalMilliseconds; if (hittimer < 0) { this.hit = false; this.hittimer = 50f; } } if (attacking) { if (hitting) { bodyPos.X -= modifySpeed; attackRotation += MathHelper.ToRadians(25); if (!(bodyPos.X - viking.Position.X < 150 && bodyPos.X - viking.Position.X > -120)) { this.hitting = false; attackRotation = 0; } } else { if (bodyPos.X - viking.Position.X < 150 && bodyPos.X - viking.Position.X > -120) { bodyPos.X -= modifySpeed; this.hitting = true; } else { if (bodyPos.X > viking.Position.X) { bodyPos.X -= (int)(enemyMoveSpeed * time.ElapsedGameTime.TotalSeconds) + modifySpeed; enemyDirection = false; } else { bodyPos.X += (int)(enemyMoveSpeed * time.ElapsedGameTime.TotalSeconds) - modifySpeed; enemyDirection = true; } } } } else { bodyPos.X -= modifySpeed; if (bodyPos.X < 2000) { attacking = true; } } currenthealth.X = bodyPos.X + 60; fullhealth.X = bodyPos.X + 60; bullets = viking.getBullets(); for (int i = 0; i < bullets.Count; i++) { if (bullets[i].Position.Intersects(bodyPos) || bullets[i].Position.Intersects(leftLegPos) || bullets[i].Position.Intersects(rightLegPos)) { if (bullets[i].Position.Intersects(leftLegPos) || bullets[i].Position.Intersects(rightLegPos)) { if (!this.jumping) { this.falling = false; this.jumping = true; } } this.health -= bullets[i].Damage; angle = bullets[i].angle; addSpatter(bullets[i].Position); bullets[i].Active = false; if (!hit) { hit = true; } if (enemyDirection) { bodyPos.X -= 5; } else { bodyPos.X += 5; } } } } if (this.health <= 0) { this.Dead = true; } if (Dead && drawblood == 0) { this.Active = false; } //Positions for other bodyparts leftArmPos = new Rectangle(bodyPos.X + 136, bodyPos.Y + 80, 59, 148); rightArmPos = new Rectangle(bodyPos.X + 34, bodyPos.Y + 80, 51, 150); leftLegPos = new Rectangle(bodyPos.X + 115, bodyPos.Y + 160, 104, 157); rightLegPos = new Rectangle(bodyPos.X + 55, bodyPos.Y + 170, 116, 158); //Arm rotation if (!rot1) { Rotation = Rotation + MathHelper.ToRadians(4); if (MathHelper.ToDegrees(Rotation) >= 45) { rot1 = true; } } else if (rot1) { Rotation = Rotation - MathHelper.ToRadians(4); if (MathHelper.ToDegrees(Rotation) <= -45) { rot1 = false; } } if (rot2) { Rotation2 = Rotation2 + MathHelper.ToRadians(4); if (MathHelper.ToDegrees(Rotation2) >= 45) { rot2 = false; } } else if (!rot2) { Rotation2 = Rotation2 - MathHelper.ToRadians(4); if (MathHelper.ToDegrees(Rotation2) <= -45) { rot2 = true; } } if (jumping && bodyPos.Y > 517 && !falling) { if (bodyPos.Y > groundLevel - 150) { bodyPos.Y -= 10; } else if (bodyPos.Y > groundLevel - 200 && bodyPos.Y <= groundLevel - 150) { bodyPos.Y -= 6; } } else if (bodyPos.Y < groundLevel) { falling = true; if (bodyPos.Y < groundLevel - 100) { bodyPos.Y += 6; } else if (bodyPos.Y > groundLevel - 100 && bodyPos.Y < groundLevel) { bodyPos.Y += 9; } } else { jumping = false; } }