-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame1.cs
More file actions
66 lines (59 loc) · 2.13 KB
/
Game1.cs
File metadata and controls
66 lines (59 loc) · 2.13 KB
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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Linq;
namespace SpriteFontProofFont;
public class Game1 : Game {
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private SFProofFont font;
private Texture2D pixel;
public Game1() {
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize() {
base.Initialize();
}
protected override void LoadContent() {
_spriteBatch = new SpriteBatch(GraphicsDevice);
font = new(GraphicsDevice, "Content/Audiowide.sfpf");
pixel = new(GraphicsDevice, 1, 1);
pixel.SetData([Color.White]);
}
protected override void Update(GameTime gameTime) {
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
float wave = MathF.Pow(MathF.Sin((float)gameTime.TotalGameTime.TotalSeconds * 0.25f * float.Pi), 2);
_spriteBatch.Begin();
var text = " <(`>`)\n(y) * |)\n cD | |D\n j bb";
float angle = float.Pi * 0.6f * (1 - wave);
float scale = 0.25f + 0.75f * wave;
Vector2 size = font.MeasureString(text, 100 * scale);
_spriteBatch.Draw(
pixel,
new Rectangle(300, 40, (int)size.X, (int)size.Y),
null, Color.Red,
angle, Vector2.Zero, SpriteEffects.None, 0
);
font.DrawString(
_spriteBatch,
text,
new(300, 40),
Color.Green, 100 * scale, angle
);
_spriteBatch.End();
base.Draw(gameTime);
}
private readonly Random rng = new();
public string RandomString(int length = 8) {
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
return new string([.. Enumerable.Range(0, length).Select(_ => chars[rng.Next(chars.Length)])]);
}
}