using System using SFML Graphics using SFML System namespace AIGravity

 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
using System;
using SFML.Graphics;
using SFML.System;
namespace AIGravityDefied
{
class Map
{
public int seed;
private int size;
public float[,] points = new float[100, 2];
private Random rand;
public Map(int size, int seed = 0)
{
if (seed == 0)
{
rand = new Random();
seed = rand.Next(0, 10000);
}
else
{
rand = new Random(seed);
}
this.seed = seed;
this.size = size;
Generate();
System.Console.WriteLine("Seed: {0}", seed);
}
private float GetRandom(int min, int max)
{
return (float)rand.NextDouble() * (max - min) + min;
}
private void Generate()
{
float x1 = 200, y1 = 500;
points[0, 0] = 0;
points[0, 1] = 500;
points[1, 0] = x1;
points[1, 1] = y1;
for (int i = 2; i < size; i++)
{
x1 += GetRandom(30, 100);
points[i, 0] = x1;
y1 += GetRandom(-50, 50);
points[i, 1] = y1;
}
}
public VertexArray Render()
{
var line = new VertexArray(PrimitiveType.Lines, 4);
for (int i = 1; i < size; i++)
{
line.Append(new Vertex(new Vector2f(points[i - 1, 0], points[i - 1, 1])));
line.Append(new Vertex(new Vector2f(points[i, 0], points[i, 1])));
}
return line;
}
}
}