Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (69 loc) · 2.17 KB
/
Copy pathProgram.cs
File metadata and controls
85 lines (69 loc) · 2.17 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Foster.Framework;
using System.Numerics;
using var game = new Game();
game.Run();
class Game : App
{
private const float Acceleration = 1200;
private const float Friction = 500;
private const float MaxSpeed = 800;
private readonly Batcher batch;
private readonly Texture texture;
private Vector2 pos = new(128, 128);
private Vector2 speed = new();
public Game() : base(new AppConfig()
{
ApplicationName = "Shapes",
WindowTitle = "Hello Shapes",
Width = 1280,
Height = 720
})
{
batch = new(GraphicsDevice);
texture = new(GraphicsDevice, new Image(128, 128, Color.Blue));
}
protected override void Startup() {}
protected override void Shutdown() {}
protected override void Update()
{
Window.Title = $"Something Else {Window.Width}x{Window.Height} : {Window.WidthInPixels}x{Window.HeightInPixels}";
if (Input.Keyboard.Down(Keys.Left))
speed.X -= Acceleration * Time.Delta;
if (Input.Keyboard.Down(Keys.Right))
speed.X += Acceleration * Time.Delta;
if (Input.Keyboard.Down(Keys.Up))
speed.Y -= Acceleration * Time.Delta;
if (Input.Keyboard.Down(Keys.Down))
speed.Y += Acceleration * Time.Delta;
if (!Input.Keyboard.Down(Keys.Left, Keys.Right))
speed.X = Calc.Approach(speed.X, 0, Time.Delta * Friction);
if (!Input.Keyboard.Down(Keys.Up, Keys.Down))
speed.Y = Calc.Approach(speed.Y, 0, Time.Delta * Friction);
if (Input.Keyboard.Pressed(Keys.F4))
Window.Fullscreen = !Window.Fullscreen;
if (speed.Length() > MaxSpeed)
speed = speed.Normalized() * MaxSpeed;
pos += speed * Time.Delta;
}
protected override void Render()
{
Window.Clear(new Color(
Calc.Clamp(Input.Mouse.X / Window.WidthInPixels, 0, 1),
Calc.Clamp(Input.Mouse.Y / Window.HeightInPixels, 0, 1),
0.25f,
1.0f
));
batch.PushMatrix(
new Vector2(Window.WidthInPixels, Window.HeightInPixels) / 2,
new Vector2(texture.Width, texture.Height) / 2,
Vector2.One,
(float)Time.Elapsed.TotalSeconds * 4.0f);
batch.Image(texture, Vector2.Zero, Color.White);
batch.PopMatrix();
batch.Circle(new Circle(pos, 64), 16, Color.Red);
batch.Circle(new Circle(Input.Mouse.Position, 8), 16, Color.White);
batch.Render(Window);
batch.Clear();
}
}