#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace Wehrmacht
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
ContentManager content;
SpriteBatch Sprite;
SpriteFont Arial;
Texture2D Tank;
public float TankAngle;
public Rectangle TankPosition;
Texture2D Ammo;
public Vector2 AmmoPosition;
public bool Shooted;
public int MouseX;
public int MouseY;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
this.IsMouseVisible = true;
TankAngle = 0;
AmmoPosition = new Vector2(100, 100);
Shooted = false;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
Arial = content.Load<SpriteFont>("Arial");
Tank = content.Load<Texture2D>("Tank");
TankAngle = 0.0f;
TankPosition = new Rectangle(100, 100, Tank.Width, Tank.Height);
Ammo = content.Load<Texture2D>("Ammo");
Sprite = new SpriteBatch(graphics.GraphicsDevice);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
content.Unload();
}
}
protected override void Update(GameTime gameTime)
{
// Maus mit der Position und Taste abfragen
if (Mouse.GetState().RightButton == ButtonState.Pressed)
{
MouseX = Mouse.GetState().X;
MouseY = Mouse.GetState().Y;
/*
x1 MouseX = Mouse.GetState().X;
y1 MouseY = Mouse.GetState().Y;
x2 TankPosition.X;
y2 TankPosition.Y;
*/
if (MouseX > TankPosition.X){
for (float x = MouseX; x < TankPosition.X; x++)
{
TankPosition.Y = TankPosition.Y = (TankPosition.Y - MouseY) * x / (TankPosition.X - MouseX) + (MouseY - (TankPosition.Y - MouseY) * MouseX / (TankPosition.X - MouseX));
TankPosition.X = x;
}
}
MouseX = Mouse.GetState().X;
MouseY = Mouse.GetState().Y;
}
// Munition schießen
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
Shooted = true;
}
if (Shooted == true && AmmoPosition.X < 800)
{
AmmoPosition.X += 5;
}
// Spiel verlassen
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
{
this.Exit();
}
// Panzer vorwärts fahren lassen
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
TankPosition.X += 1;
if (Shooted == false)
{
AmmoPosition.X += 1;
}
}
// Panzer rückwärts fahren lassen
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
TankPosition.X -= 1;
if (Shooted == false)
{
AmmoPosition.X -= 1;
}
}
// Panzer nach links drehen
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
TankAngle -= 0.02f;
}
// Panzer nach rechts drehen
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
TankAngle += 0.02f;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
Sprite.Begin();
Sprite.Draw(Tank, TankPosition, Color.White);
/*Sprite.Draw(
Tank,
TankPosition,
new Rectangle(0, 0, Tank.Width, Tank.Height),
Color.White,
TankAngle,
new Vector2(Tank.Width / 2, Tank.Height / 2),
SpriteEffects.None,
0.0f
);*/
Sprite.Draw(Ammo, AmmoPosition, Color.White);
Sprite.End();
base.Draw(gameTime);
}
}
}