/// <summary> /// Draws the background image on the form. /// /// Author AMS 2017 /// </summary> private void DrawBackground() { Graphics graphics = backgroundGraphics.Graphics; Image background = backgroundImage; graphics.DrawImage(backgroundImage, new Rectangle(0, 0, displayPanel.Width, displayPanel.Height)); Terrain battlefield = currentGame.GetLevel(); Brush brush = new SolidBrush(landscapeColour); for (int y = 0; y < Terrain.HEIGHT; y++) { for (int x = 0; x < Terrain.WIDTH; x++) { if (battlefield.IsTileAt(x, y)) { int drawX1 = displayPanel.Width * x / levelWidth; int drawY1 = displayPanel.Height * y / levelHeight; int drawX2 = displayPanel.Width * (x + 1) / levelWidth; int drawY2 = displayPanel.Height * (y + 1) / levelHeight; graphics.FillRectangle(brush, drawX1, drawY1, drawX2 - drawX1, drawY2 - drawY1); } } } }
/// <summary> /// /// This method calls the ControlledTank to fall down one tile if possible. /// If the tank is moved due to the result of this method, it will return true, /// otherwise it will be false /// /// Author John Santias and Hoang Nguyen October 2017 /// /// </summary> /// <returns> Returns true if tank is moved, otherwise returns false </returns> public bool Gravity() { if (!Exists()) { return(false); } Terrain t = game.GetLevel(); int x = GetX(); int y = GetYPos(); if (t.CheckTankCollision(x, y + 1)) { return(false); } else { tankY++; currentDur--; if (tankY == Terrain.HEIGHT - TankModel.HEIGHT) { currentDur = 0; return(true); } } return(true); }