1
0
forked from s425077/PotatoPlan
PotatoPlan/Tractor_VS/Game1/Game1.cs
BOTLester 4d1b20b32f done by hand, but works eh.
First stable. RC_01
2020-04-08 20:04:31 +02:00

118 lines
5.4 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace Game1
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont Bold;
private Texture2D[] tile = new Texture2D[4];
private Texture2D tractor;
private Texture2D house;
private Tractor tractorUnit = new Tractor();
private Input input = new Input();
private House houseUnit = new House();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
//Generates the map with some random values
input.init(graphics, new Vector2(8,8), 56, 1); //Generates the starting size
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
tractorUnit.init(houseUnit.GetRectangle());
tractorUnit.updateSizing(input, 0, houseUnit.getVector());
tractorUnit.setPos(houseUnit.getVector());
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 125;
graphics.ApplyChanges();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
//Loads the PNG content and Fonts
tile[0] = Content.Load<Texture2D>("tileunplantable");
tile[1] = Content.Load<Texture2D>("Plantable");
tile[2] = Content.Load<Texture2D>("Planted");
tile[3] = Content.Load<Texture2D>("Crop");
tractor = Content.Load<Texture2D>("Tractor");
Bold = Content.Load<SpriteFont>("Font");
house = Content.Load<Texture2D>("house");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime) //updates every 60 seconds
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the size
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the speed of the tractor
input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles
houseUnit.updateRectangle(input.getSize(), input.getTileSize());
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) //Draw Function
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
for(int i = 0; i < input.getSize().X; i++) //Draw the tiles
{
for (int j = 0; j < input.getSize().Y; j++)
{
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).Status], new Rectangle(i * (input.getTileSize() + input.getSpacing()), j * (input.getTileSize() + input.getSpacing()), input.getTileSize(), input.getTileSize()), Color.White);
}
}
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getTargetPosition().X, (int)tractorUnit.getTargetPosition().Y, input.getTileSize(), input.getTileSize()) , Color.Red); //Draws the current target of the tractor
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPos().X, (int)tractorUnit.getPos().Y, input.getTileSize(), input.getTileSize()), Color.White);
spriteBatch.Draw(house, houseUnit.GetRectangle(), Color.White);
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 20) , Color.White); //Draws the speed value
spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * input.getTileSize() + 40), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 60), Color.White);
spriteBatch.DrawString(Bold, tractorUnit.getCurrentTask(), new Vector2(10, input.getSize().Y * input.getTileSize() + 80), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, tractorUnit.getScore().ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 100), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}