/// <summary> /// The method that checks whether or not the zombie has been hit /// </summary> /// <param name="gp">The game object in question (probably should be the player)</param> /// <returns>True if there is collision; false if there isn't</returns> public virtual bool CheckCollision(GamePiece gp) { if (gp._Rectangle.Intersects(this._Rectangle)) { return true; } else { return false; } }
public void Initialize(Viewport viewport, Texture2D texture, Vector2 position,GamePiece.Direction dir) { Texture = texture; Position = position; this.viewport = viewport; D = dir; Active = true; //change the movement speed here projectileMoveSpeed = 20f; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { gameState = GameState.Menu; // Set the previous keyboard state variable to what the current keyboard state is (which is nothing) _prevKbState = Keyboard.GetState(); _Extraction = new GamePiece(400, 560, 256, 256); // Set the button state to hightlight the "Play Button" buttonState = Highlighted.Play; // Create height and width varibles that can be used throughout the class gameHeight = graphics.PreferredBackBufferHeight; gameWidth = graphics.PreferredBackBufferWidth; // Set all of the Human values: _p = new Player(GameVariables.playerStartX, GameVariables.playerStartY, GameVariables.spriteWidth, GameVariables.spriteHeight); // The actual Player humanStep = GameVariables.stepSpeed; // The rate at which the player will take a step zombieStep = GameVariables.stepSpeed; //The HUD rectangle object _h = new GamePiece(-9, -1, 480, 110); scoreTimer = 0; // Create the map objects (It is important to note that the first digit is the Y value, while the second is the X) mt00 = new MapTile(3, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("00")); mt01 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("01")); mt02 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("02")); mt03 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("03")); mt04 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("04")); mt05 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("05")); mt06 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("06")); mt07 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("07")); //mt02 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("grass")); //mt03 = new MapTile(5, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("grass")); mt10 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("10")); mt11 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("11")); mt12 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("12")); mt13 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("13")); mt14 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("14")); mt15 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("15")); mt16 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("16")); mt17 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("17")); //mt12 = new MapTile(0, 2, gameWidth, gameHeight, this.Content.Load<Texture2D>("road")); mt20 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("20")); mt21 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("21")); mt22 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("22")); mt23 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("23")); mt24 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("24")); mt25 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("25")); mt26 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("26")); mt27 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("27")); mt30 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("30")); mt31 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("31")); mt32 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("32")); mt33 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("33")); mt34 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("34")); mt35 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("35")); mt36 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("36")); mt37 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("37")); mt40 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("40")); mt41 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("41")); mt42 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("42")); mt43 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("43")); mt44 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("44")); mt45 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("45")); mt46 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("46")); mt47 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("47")); // Then add them to the list to reference by number listofMaptiles = new List<MapTile>(); listofMaptiles.Add(mt00); listofMaptiles.Add(mt01); listofMaptiles.Add(mt02); listofMaptiles.Add(mt03); listofMaptiles.Add(mt04); listofMaptiles.Add(mt05); listofMaptiles.Add(mt06); listofMaptiles.Add(mt07); //listofMaptiles.Add(mt03); listofMaptiles.Add(mt10); listofMaptiles.Add(mt11); listofMaptiles.Add(mt12); listofMaptiles.Add(mt13); listofMaptiles.Add(mt14); listofMaptiles.Add(mt15); listofMaptiles.Add(mt16); listofMaptiles.Add(mt17); listofMaptiles.Add(mt20); listofMaptiles.Add(mt21); listofMaptiles.Add(mt22); listofMaptiles.Add(mt23); listofMaptiles.Add(mt24); listofMaptiles.Add(mt25); listofMaptiles.Add(mt26); listofMaptiles.Add(mt27); listofMaptiles.Add(mt30); listofMaptiles.Add(mt31); listofMaptiles.Add(mt32); listofMaptiles.Add(mt33); listofMaptiles.Add(mt34); listofMaptiles.Add(mt35); listofMaptiles.Add(mt36); listofMaptiles.Add(mt37); listofMaptiles.Add(mt40); listofMaptiles.Add(mt41); listofMaptiles.Add(mt42); listofMaptiles.Add(mt43); listofMaptiles.Add(mt44); listofMaptiles.Add(mt45); listofMaptiles.Add(mt46); listofMaptiles.Add(mt47); // And also to a dictionary for reference by name for their number that references which // Maptile its connected to dictionaryofMaptiles = new Dictionary<MapTile, int>(); for (int i = 0; i < listofMaptiles.Count; i++) { dictionaryofMaptiles.Add(listofMaptiles[i], i); } // Set the current maptile currentMaptile = listofMaptiles[0]; // Method where you can connect all of the barriers to a map tile SetUpBarrierConnections(); //making the lsit of zombies _zs = new List<Zombie>(); foreach (Zombie z in currentMaptile.GetSetZombieList) { _zs.Add(z); } //Bullet stuffs listBullet = new List<Bullet>(); _b = new Bullet(); bulletTimer = GameVariables.bTimer; //changing how much ammo ammo = 20; dcs = new List<DartCollectible>(); foreach (DartCollectible dc in currentMaptile.GetSetDartCollectibles) { dcs.Add(dc); } //making the start score 0 score = 0; //CheckExternal(); base.Initialize(); }
public void ScreenWall(GamePiece g) { if (g._Rectangle.X <= 0) { g.XValue = 1; } else if (g._Rectangle.X + g._Rectangle.Width >= GameVariables.screenWidth) { g.XValue = GameVariables.screenWidth - g._Rectangle.Width; } else if (g._Rectangle.Y <= 0) { g.YValue = 1; } else if (g._Rectangle.Y + g._Rectangle.Height >= GameVariables.screenHeight) { g.YValue = GameVariables.screenHeight - g._Rectangle.Height; } else if (_h._Rectangle.Contains(g._Rectangle.X,g._Rectangle.Y - 5) && g._Rectangle.Y <= _h._Rectangle.Height - 5) { g.YValue = _h._Rectangle.Height; } else if (_h._Rectangle.Contains(g._Rectangle.X- 5, g._Rectangle.Y) && g._Rectangle.X <= _h._Rectangle.Width - 5) { g.XValue = _h._Rectangle.Width; } }
/// <summary> /// Rudimentary AI For the basic Zombie Class /// </summary> /// <param name="gp">The Zombie in question</param> /// <param name="t"></param> public void AI(GamePiece gp, double t) { aiTimer -= t; // The passed in time is subtracted from the timer previousZombiePosition = currentZombiePosition; // The previous picture now becomes the current if (CheckCollision(gp) == true) { } // Once it collides then just stand there and attack // Otherwise else { if (this._Rectangle.X <= gp._Rectangle.X && gp._Rectangle.X <= this._Rectangle.X + defaultRange && // If in the upper left quadrant this._Rectangle.Y >= gp._Rectangle.Y && gp._Rectangle.Y >= this._Rectangle.Y - defaultRange) // pursue player there { this.YValue -= defaultChaseSpeed; // By moving up d = Direction.Up; aiTimer = defaultWaitTime; // Reset the timer } if (this._Rectangle.X <= gp._Rectangle.X && gp._Rectangle.X <= this._Rectangle.X + defaultRange && // If in the upper right quadrant this._Rectangle.Y <= gp._Rectangle.Y && gp._Rectangle.Y <= this._Rectangle.Y + defaultRange) // pursue player there { this.XValue += defaultChaseSpeed; // By moving right d = Direction.Right; aiTimer = defaultWaitTime; // Rese the timer } if (this._Rectangle.X >= gp._Rectangle.X && gp._Rectangle.X >= this._Rectangle.X - defaultRange && // If in the lower right quadrant this._Rectangle.Y <= gp._Rectangle.Y && gp._Rectangle.Y <= this._Rectangle.Y + defaultRange) // pursue player there { this.YValue += defaultChaseSpeed; // By moving down d = Direction.Down; aiTimer = defaultWaitTime; // Reset the timer } if (this._Rectangle.X >= gp._Rectangle.X && gp._Rectangle.X >= this._Rectangle.X - defaultRange && // If in the lower left quadrant this._Rectangle.Y >= gp._Rectangle.Y && gp._Rectangle.Y >= this._Rectangle.Y - defaultRange) // pursue player there { this.XValue -= defaultChaseSpeed; // By moving left d = Direction.Left; aiTimer = defaultWaitTime; // Reset the timer } currentZombiePosition = this._Rectangle; // Now make the current zombie position into what it is // Now since we're only reseting the timer if the zombie moved then // If he hasn't moved for the default wait time, then... if (aiTimer < 0) { movingTimer -= t; // The timer for how long the zombie moves if (movingTimer > 0) // As long as the timer is greater than 0 { if (flippedDirection == 1) // Change direction ONCE { switch (d) { case Direction.Up: { d = Direction.Down; flippedDirection--; break; } case Direction.Right: { d = Direction.Left; flippedDirection--; break; } case Direction.Down: { d = Direction.Up; flippedDirection--; break; } case Direction.Left: { d = Direction.Right; flippedDirection--; break; } } } switch (d) // Then based on what the zombie's currently set direction { case Direction.Down: // Move down and set the current zombie position to it { this.YValue++; currentZombiePosition = this._Rectangle; break; } case Direction.Right: // Move right and set the current zombie position to it { this.XValue++; currentZombiePosition = this._Rectangle; break; } case Direction.Up: // Move up and set the current zombie position to it { this.YValue--; currentZombiePosition = this._Rectangle; break; } case Direction.Left: // Move left and set the current zombie position to it { this.XValue--; currentZombiePosition = this._Rectangle; break; } } } // Then once it has moved for the set amount of time then // reset both the move and ai timers and the int that allows // the zombie to flip direction once else { aiTimer = defaultWaitTime; movingTimer = 5.0; flippedDirection = 1; } } } }