-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrain.cs
159 lines (140 loc) · 4.87 KB
/
Terrain.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
<<<<<<< HEAD
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LunarLander
{
class Terrain
{
//Constructor
public Terrain() {
points = new List<PointF>();
}
public int numOfPoints = 0;
public int TotalHeight = 100;
public int Width = 1700;
const int landingStripWidth = 30;
public List<PointF> points;
/*
* The class terrain is in charge of creating the points that will be connected to make the terrain
*/
public void GenerateTerrain()
{
Random rnd = new Random();
double amp = 0.2; //amplitude of wave
double waveLength = rnd.NextDouble() * (.03-.01) + 0.01; //waveLength of wave
//Previous period and current period are used to check different waves
int previousPeriod = 0;
int currentPeriod = 0;
float tempHeight = 0;
//our terrain is left list of connected dots in random height < 1/2 of screen
for (int w = 0; w < Width; w += rnd.Next(1, 40)) //randomly chooses the x coordinate based on its range and as long as its under the width
{
previousPeriod= (Width - w)/200;
//new sizes for new wave
if (currentPeriod!= previousPeriod)
{
//unique random amplitude
amp = rnd.NextDouble() * (1 - 0.1) + .1; ;
}
currentPeriod = previousPeriod;
//apply new numbers to the sine wave
tempHeight = (Convert.ToSingle((amp * Math.Sin(waveLength * w)+1)*200))+350;
points.Add(new PointF(w, tempHeight));
}
numOfPoints = points.Count();
int landingsCount = 3;
for (int i = 0; i < landingsCount; i++)
{
int idx = rnd.Next(numOfPoints);
try
{
while ((points[idx + 1].X - points[idx].X) < 30)
{
idx = rnd.Next(numOfPoints);
}
}
catch
{
break;
}
points.Insert(idx + 1, (new PointF(points[idx].X + landingStripWidth, points[idx].Y)));
}
points.Add(new PointF(Width, rnd.Next(TotalHeight)));
}
}
}
=======
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LunarLander
{
class Terrain
{
//Constructor
public Terrain() {
points = new List<PointF>();
}
public int TotalHeight = 100;
public int ScreenHeight = 480;
public int midHeight = 50;
public int Width = 800;
const int landingStripWidth = 30;
public List<PointF> points;
public void GenerateTerrain()
{
Random rnd = new Random();
float tempHeight = 0;
//currently has 11 points
//our terrain is left list of connected dots in random height < 1/2 of screen
for (int w = 0; w < Width; w += rnd.Next(1, 10))
{
double amp = .2;
double period = 7;
int currentWave = 0;
/*
switch (currentWave)
{
case 0:
amp = .2;
period = 7;
break;
case 1:
break;
case 2:
break;
}*/
tempHeight = Convert.ToSingle(amp * Math.Sin(period * w)+1);
Console.WriteLine(tempHeight);
tempHeight += rnd.Next(0, 40);
points.Add(new PointF(w, tempHeight));
}
int landingsCount = rnd.Next(3) + 2;
for (int i = 0; i < landingsCount; i++)
//insert landings
{
int idx = rnd.Next(points.Count);
points.Insert(idx + 1, (new PointF(points[idx].X + landingStripWidth, points[idx].Y)));
}
points.Add(new PointF(Width, rnd.Next(TotalHeight)));
/*
//"normalize terrain" - lower it to the lowest point
//find lowest point
float lowest = points.Min(p => p.Y);
*/
//decrease each
for (int i = 0; i < points.Count; i++)
{
points[i] = new PointF(points[i].X, ScreenHeight - (points[i].Y));//- lowest));
}
}
}
}
>>>>>>> f911a7e2a17b228e7d4e8e1b6c4ed4cb05192dd6