PotatoPlan/Tractor_VS/Game1/Game1.cs
BOTLester 165f50b3fd Stable branch push
testin
2020-04-07 17:50:31 +02:00

91 lines
3.5 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
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;
private Texture2D tractor;
private Tractor tractorUnit = new Tractor();
private Input input = new Input();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
input.init(graphics, new Vector2(8,8), 56, 1);
tractorUnit.updateSizing(input.getTileSize(), input.getSpacing());
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()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
tile = Content.Load<Texture2D>("Tile");
tractor = Content.Load<Texture2D>("Tractor");
Bold = Content.Load<SpriteFont>("Font");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
tractorUnit.updateSizing(input.getTileSize(), input.getSpacing());
tractorUnit.updatePosition(input.getSize());
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed()));
input.changeSize();
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, 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 tractors target
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPos().X, (int)tractorUnit.getPos().Y, input.getTileSize(), input.getTileSize()), Color.Black); //Draws the tractor
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 20) , Color.White); //Draws the the speed
spriteBatch.End();
base.Draw(gameTime);
}
}
}