summaryrefslogtreecommitdiff
path: root/TankBattleCore/Game1.cs
blob: 91a09b5c119aa2bd6dc30efcfa83b510adecbf86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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);
    }
}