public void Update(GameTime gameTime, PlayerSprite player) { Vector2 playerPos = player.getPosition(); Rectangle playerRect = player.getRectangle(); center = new Vector2((playerPos.X + playerRect.Width / 2) - (GlobalClass.ScreenWidth / 2), (playerPos.Y + playerRect.Height / 2) - (GlobalClass.ScreenHeight / 2)); // clamping // top if (center.Y < 0) { center.Y = 0; } // left if (center.X < 0) { center.X = 0; } // bottom if (center.Y + GlobalClass.ScreenHeight > game.GetRoom(game.GetRoomID()).GetRoomRectangle().Height) { center.Y = game.GetRoom(game.GetRoomID()).GetRoomRectangle().Height - GlobalClass.ScreenHeight; } // right if (center.X + GlobalClass.ScreenWidth > 2410) { center.X = 2410 - GlobalClass.ScreenWidth; } //move camera to follow player transform = Matrix.CreateScale(new Vector3(1, 1, 0)) * Matrix.CreateTranslation(new Vector3(-center.X, -center.Y, 0)); }
public WeaponIcon(string textureFile, int x, WeaponType type, PlayerSprite player) { //constructor this.textureFile = textureFile; this.x = x; this.type = type; this.player = player; Initialize(); }
//update method public override void Update(GameTime gameTime) { //determine how much damage the bullet should do foreach (GameComponent g in game.Components) { if (g is PlayerSprite) { PlayerSprite p = (PlayerSprite)g; Weapon w = p.GetWeapon(); if (w.GetWeaponType() == WeaponType.Shotgun) { damage = 1; } else { damage = 1; } } } //logic for determining which direction the bullet should move position += direction * speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Sprite collisionSprite = new Sprite(game); //check for collisions foreach (GameComponent g in game.Components) { if (g is Enemy) { Enemy s = (Enemy)g; Rectangle b = s.getRectangle(); if (b.Intersects(this.boundingBox)) { collisionSprite = s; remove = true; s.removeHelth(damage); s.setShouldColor(); } } } //remove objects that have collided (can't be removed in the loop) if (remove) { game.Components.Remove(this); } base.Update(gameTime); }
//room constructor public Room(Game game, string textureFile, Vector2 position, int row, int column, bool up, bool down, PlayerSprite player, Color r_color, int id) : base(game, textureFile, position, 1) { this.row = row; this.column = column; this.up = up; this.down = down; boundaryPosition = new Vector2(10, 10); doors = new List <Door>(); this.player = player; this.r_color = r_color; this.id = id; this.DrawOrder = 1; }
public GameElements(Game game, PlayerSprite player) { this.game = game; this.Player = player; }
//update method public override void Update(GameTime gameTime) { if (((Game1)Game).GetGameState() == Game1.GameState.PLAY) { //logic for removal if (health <= 0) { this.setRemove(); (game as Game1).playZombieDeath(); int r = Game1.Random.Next(0, 8); if (r == 0) { game.Components.Add(new itemDrop(game, null, position)); } } //player damage representation if (shouldColor) { color = Color.Red; colorTimer = 5; shouldColor = false; } //reduce color timer colorTimer--; //reset the color if (colorTimer <= 0) { color = Color.White; } //logic for animation if (this.direction == Facing.Left) { sRec.Y = texture.Height / spriteRows + 1; } else if (this.direction == Facing.Right) { sRec.Y = 0; } Console.WriteLine(boundingBox.X + " " + boundingBox.Y); base.Update(gameTime); //update current time currentTime++; //check for collisions with player foreach (GameComponent g in game.Components) { if (g is PlayerSprite) { PlayerSprite s = (PlayerSprite)g; //get position of player target = s.getPlayerPosition(); //collision logic Rectangle b = s.getRectangle(); if (b.Intersects(this.collisionRec)) { //damage the player if (currentTime >= delay) { s.reducePlayerHealth(damage); currentTime = 0; } } if (position.X > (s.getPlayerPosition().X - 5f)) { this.direction = Facing.Left; } else { this.direction = Facing.Right; } } } //movement AI(); // check for movement if (position.X == prevX && position.Y == prevY) { animate = false; frameCount = 0; } else { animate = true; } // if enemy is moving, animate if (animate) { if (frameCount == animationSpeed) { // check for rollover on sprite strip if ((sRec.X + sRec.Width) > (texture.Width - sRec.Width)) { sRec.X = 0; } else { sRec.X += sRec.Width; } // restart timer frameCount = 0; } } // increment animation assets as appropriate frameCount += 1; prevX = position.X; prevY = position.Y; } if (remove == true) { if (((Game1)Game).gameObj == Objective.Elimination) { ((Game1)Game).objEliminate -= 1; } game.Components.Remove(this); } collisionRec.X = boundingBox.X; collisionRec.Y = boundingBox.Y; }