diff options
| author | BoredGuy <osome3717@gmail.com> | 2026-03-27 16:29:32 -0700 |
|---|---|---|
| committer | BoredGuy <osome3717@gmail.com> | 2026-03-27 16:29:32 -0700 |
| commit | 25fdc90968a14ffd44dae65d6fdb3d50e6df9082 (patch) | |
| tree | 3e11812a480ff173a7c65fd9d53e0efc69f5be27 /TankBattleCore/Game1.cs | |
Initial Commit
Diffstat (limited to 'TankBattleCore/Game1.cs')
| -rw-r--r-- | TankBattleCore/Game1.cs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/TankBattleCore/Game1.cs b/TankBattleCore/Game1.cs new file mode 100644 index 0000000..91a09b5 --- /dev/null +++ b/TankBattleCore/Game1.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using TankBattleCore.Objects; + +namespace TankBattleCore; + +internal enum TankColor +{ + Black +} + +public class Game1 : Game +{ + private static Game1 _instance; + + public static Game1 Instance + { + get + { + if (_instance == null) + { + _instance = new Game1(); + } + + return _instance; + } + } + + private GraphicsDeviceManager _graphics; + private SpriteBatch _spriteBatch; + internal Dictionary<TankColor, Texture2D> TankBodyTextures { get; private set; } + IScene _scene; + + public int WindowWidth + { + get => _graphics.PreferredBackBufferWidth; + } + + public int WindowHeight + { + get => _graphics.PreferredBackBufferHeight; + } + + private Game1() + { + _graphics = new GraphicsDeviceManager(this); + Content.RootDirectory = "Content"; + IsMouseVisible = true; + } + + protected override void Initialize() + { + base.Initialize(); + } + + protected override void LoadContent() + { + _spriteBatch = new SpriteBatch(GraphicsDevice); + + TankBodyTextures = new Dictionary<TankColor, Texture2D>() + { + {TankColor.Black, Content.Load<Texture2D>("tankBlack_outline")} + }; + + _scene = new GameScene(); + } + + protected override void Update(GameTime gameTime) + { + if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) + Exit(); + + float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; + + _scene.Update(dt); + + base.Update(gameTime); + } + + protected override void Draw(GameTime gameTime) + { + GraphicsDevice.Clear(Color.CornflowerBlue); + + _scene.Draw(_spriteBatch); + + base.Draw(gameTime); + } +} |
