public void Draw(GameTime gametime, SpriteBatch spriteBatch, SpriteFont font, Player player) { Vector2 levelPos = new Vector2(5,0); Vector2 lifePos = new Vector2(location_lifeBar.X, location_lifeBar.Y + source_lifeBarOutline.Height + 4); Vector2 expPos = new Vector2(lifePos.X, lifePos.Y + 20); spriteBatch.DrawString(font, "Level: " + player.level ,levelPos, Color.Red); spriteBatch.Draw(lifeBar_texture, destLifeBar, source_lifeBarColor, Color.DarkTurquoise); spriteBatch.Draw(lifeBar_texture, location_lifeBar, source_lifeBarOutline, Color.White); spriteBatch.DrawString(font, "HP: " + player.health + " / " + player.maxHealth, lifePos, Color.Red); spriteBatch.DrawString(font, "Exp: " + player.exp, expPos, Color.Red); }
public void Update(GameTime gameTime, Player player) { double doubleOffset = (double)player.health * 1.0 / (double)player.maxHealth; destLifeBar.Width = (int)(lifeBarWidth * doubleOffset); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Debugging string debugFont = Content.Load<SpriteFont>("DebugFont"); hitFont = Content.Load<SpriteFont>("PlainFont"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //load enemy texture and thruster texture enemySpriteSheet = Content.Load<Texture2D>("Enemy"); thrusterSpriteSheet = Content.Load<Texture2D>("thrust"); //Load player texture player = new Player(Content.Load<Texture2D>("Ships"), thrusterSpriteSheet, new Vector2(SCREEN_WIDTH/2,SCREEN_HEIGHT/1.5f)); //Test enemy enemies.Add(new Enemy(enemySpriteSheet,thrusterSpriteSheet, new Vector2(200, 0), 0, player.getPosition(), SCREEN_WIDTH, SCREEN_HEIGHT,3)); //Weapons weapons = new Weapons(Content.Load<Texture2D>("weapons"), SCREEN_WIDTH, SCREEN_HEIGHT); //lifebars lifeBar_texture = Content.Load<Texture2D>("hudBars"); //HUD hud = new HUD(lifeBar_texture); COLLISIONOBVIOUS = new Texture2D(GraphicsDevice, 1, 1); COLLISIONOBVIOUS.SetData(new Color[] { Color.White }); }
public void Update(GameTime timer, Vector2 position, KeyboardState prev, KeyboardState curr,Player player) { //check to see if the spacebar is pressed if (curr.IsKeyDown(Keys.Z) && !player.isDead) if (ableToShoot) { shoot(currentGun, position,player.level); ableToShoot = !ableToShoot; } //if the player has shot already then the player must wait //before able to shoot again. (Small wait period not noticable) if (!ableToShoot) { shootTimer += timer.ElapsedGameTime.Milliseconds; if (shootTimer > pauseBetweenShotTimer) { ableToShoot = !ableToShoot; shootTimer = resetTimer; } } //Debug purposes to change weapons if (curr.IsKeyDown(Keys.S) && prev.IsKeyUp(Keys.S)) currentGun = (currentGun + 1) % 6; //update the bullets for (int j = bulletsFire.Count-1; j >= 0; j--) { Bullet bullet = bulletsFire[j]; //for each bullet of anything bullet.timer -= timer.ElapsedGameTime.Milliseconds; if (bullet.timer < 0) { bullet.timer = 100f; bullet.animation += 1; bullet.animation %= 2; bullet.source.Y = weaponHeight * bullet.animation; } for (int i = 0; i < bullet.bulletVectors.Count; i++) { if (offScreenBullet(bullet.bulletVectors.ElementAt(i))) { //check to see if the list is empty then remove the currentbullet shot bullet.bulletVectors.RemoveAt(i); i--; if (bullet.bulletVectors.Count == emptyChamber) { removeCurrentShot(bullet.bulletType); bulletsFire.Remove(bullet); } } //otherwise update the bullet positions and trajectory else { Vector2 temp = bullet.bulletVectors.ElementAt(i); bullet.bulletVectors.RemoveAt(i); temp.Y -= ShootSpeed; bullet.bulletVectors.Insert(i,temp); } } } }