-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
160 lines (128 loc) · 5.04 KB
/
Game.cs
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.IO;
using IDGTF2WeaponGenerator.Classes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using SpriteFontPlus;
namespace IDGTF2WeaponGenerator
{
public class TF2WeaponGenerator : Game
{
private static GraphicsDeviceManager _graphics;
private static SpriteBatch _spriteBatch;
public static Random random = new Random();
public static SpriteFont font;
public static SpriteFont TF2Font;
public static SpriteFont TF2FontBold;
public static Texture2D whiteTex;
public static WeaponSystem weaponSystem;
private static float _globalTime = 0;
public static float GlobalTime => _globalTime;
public static GraphicsDeviceManager Graphics => _graphics;
public static Vector2 WindowSizeGraphics => new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight);
public static Point screenSize = new Point(1024, 768);
public static string WorkingDirectory => Directory.GetCurrentDirectory();
public static string AssetDirectory => "Assets/";
public static SpriteBatch SpriteBatch
{
get
{
return _spriteBatch;
}
}
public static TF2WeaponGenerator instance;
public TF2WeaponGenerator()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
instance = this;
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
IsFixedTimeStep = true;
Content.RootDirectory = "Content";
//adjust window size
_graphics.PreferredBackBufferWidth = screenSize.X;
_graphics.PreferredBackBufferHeight = screenSize.Y;
Window.Title = ("TF2 Generator");
Logging.ConsoleLog("Game Started");
_graphics.ApplyChanges();
weaponSystem = new WeaponSystem();
weaponSystem.MakeNewWeapon();
base.Initialize();
}
protected override void LoadContent()
{
whiteTex = Content.Load<Texture2D>(AssetDirectory + "White");
TF2Font = Content.Load<SpriteFont>(AssetDirectory + "TF2");
TF2FontBold = Content.Load<SpriteFont>(AssetDirectory + "TF2Bold");
font = TtfFontBaker.Bake(File.ReadAllBytes(@"C:\\Windows\\Fonts\arial.ttf"), 25, 1024, 1024, new[] { CharacterRange.BasicLatin, CharacterRange.Latin1Supplement, CharacterRange.LatinExtendedA, CharacterRange.Cyrillic }).CreateSpriteFont(GraphicsDevice); //Idk how this works but it make fonts a lot easier
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
protected override void UnloadContent()
{
if (whiteTex != null)
whiteTex.Dispose();
}
protected override void Update(GameTime gameTime)
{
Controls.UpdateControls();
_globalTime = (float)(gameTime.TotalGameTime.TotalSeconds % 3600.0);
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
SpriteBatch.Begin();
Color color = Color.White;// Color.Lerp(Color.Red, Color.White, 0.50f + (float)Math.Sin(GlobalTime / 2f) / 2f);
SpriteBatch.Draw(whiteTex, Vector2.Zero, null, color, 0, Vector2.Zero, screenSize.ToVector2() / whiteTex.Size(), SpriteEffects.None, 0);
weaponSystem.DrawWeapon();
SpriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
public class Logging
{
public static void ConsoleLog(string str)
{
System.Diagnostics.Debug.WriteLine(str);
}
}
public class Controls
{
public static bool nextButton = false;
public static Vector2 mousePos;
public static MouseState TheMouse => Mouse.GetState();
public static void UpdateControls()
{
mousePos = TheMouse.Position.ToVector2();
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
if (!nextButton)
{
TF2WeaponGenerator.weaponSystem.MakeNewWeapon();
nextButton = true;
}
}
else
{
nextButton = false;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
TF2WeaponGenerator.instance.Exit();
}
}
public static class HelperClass
{
public static Vector2 Size(this Texture2D tex)
{
return new Vector2(tex.Width, tex.Height) / 2f;
}
}
}