-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
132 lines (112 loc) · 4.7 KB
/
Program.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
using System;
using SFML.Window;
using SFML.Graphics;
namespace praysim
{
class Program
{
static void Main(string[] args)
{
var world = new Creature[800, 800];
var i = new Instance(world, 800, 800, 50, 25);
for (int x = 0; x< i.XSize; x++)
{
for (int y = 0; y < i.YSize; y++)
{
world[x, y] = new Creature();
}
}
var window = new RenderWindow(new VideoMode(i.XSize, i.YSize), "PreySim", Styles.Close);
// events
window.Closed += (sender, e) =>
{
window.Close();
};
window.MouseButtonReleased += (sender, e) =>
{
if (e.Button == Mouse.Button.Left)
{
// set pray
Console.WriteLine("new pray at " + e.X + "," + e.Y);
if (e.X < i.XSize && e.Y < i.YSize && e.X > -1 && e.Y > -1)
{
i.World[e.X, e.Y].Type = CreatureType.Pray;
i.World[e.X, e.Y].Ticks = 0;
}
}
else if (e.Button == Mouse.Button.Right)
{
// set predator
Console.WriteLine("new pred at " + e.X + "," + e.Y);
if (e.X < i.XSize && e.Y < i.YSize && e.X > -1 && e.Y > -1)
{
i.World[e.X, e.Y].Type = CreatureType.Predator;
i.World[e.X, e.Y].Ticks = 0;
}
}
};
window.KeyPressed += (object sender, KeyEventArgs e) =>
{
switch (e.Code)
{
case Keyboard.Key.P:
i.MaxTicksToDeath++;
break;
case Keyboard.Key.O:
i.MaxTicksToDeath--;
break;
case Keyboard.Key.Q:
i.DupInterval--;
break;
case Keyboard.Key.W:
i.DupInterval++;
break;
}
};
window.SetFramerateLimit(60);
var textureToDraw = new Texture(800, 800);
var spriteToDraw = new Sprite(textureToDraw);
var viewport = i.GetWorldImage(800, 800);
textureToDraw.Update(viewport);
var fpsCounter = new Text("FPS:", new Font(Resource1.Roboto_Regular), 25);
var prayCounter = new Text("PRAY COUNT:", new Font(Resource1.Roboto_Regular), 25);
var predCounter = new Text("PRED COUNT:", new Font(Resource1.Roboto_Regular), 25);
var maxLifeCounter = new Text("MAX LIFE:", new Font(Resource1.Roboto_Regular), 25);
var dupIntCounter = new Text("DUP FREQ:", new Font(Resource1.Roboto_Regular), 25);
var controls = new Text("press q to dec and w to inc dup interval\npress o to dec and p to inc max life", new Font(Resource1.Roboto_Regular), 25);
prayCounter.Position = new SFML.System.Vector2f(0, 40);
predCounter.Position = new SFML.System.Vector2f(0, 80);
maxLifeCounter.Position = new SFML.System.Vector2f(0, 120);
dupIntCounter.Position = new SFML.System.Vector2f(0, 160);
controls.Position = new SFML.System.Vector2f(350, 0);
var clock = new SFML.System.Clock();
float dt = 0;
// main loop
while (window.IsOpen)
{
window.DispatchEvents();
window.Clear();
viewport = i.GetWorldImage(800, 800);
textureToDraw.Update(viewport);
// update gui components
fpsCounter.DisplayedString = "FPS: "+ Math.Round(1/dt);
prayCounter.DisplayedString = "PRAY COUNT: " + i.GetPrayCount();
predCounter.DisplayedString = "PRED COUNT: " + i.GetPredCount();
maxLifeCounter.DisplayedString = "MAX LIFE: " + i.MaxTicksToDeath;
dupIntCounter.DisplayedString = "DUP INTERVAL: " + i.DupInterval;
// draw
window.Draw(spriteToDraw);
window.Draw(fpsCounter);
window.Draw(predCounter);
window.Draw(prayCounter);
window.Draw(maxLifeCounter);
window.Draw(dupIntCounter);
window.Draw(controls);
window.Display();
GC.Collect();
dt = clock.Restart().AsSeconds();
i.Step();
}
}
}
}