-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProceduralGeneration.cpp
More file actions
104 lines (78 loc) · 1.7 KB
/
ProceduralGeneration.cpp
File metadata and controls
104 lines (78 loc) · 1.7 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#define CONSOLE_GAME_ENGINE_IMPLEMENTATION
#include "ConsoleGameEngine.hpp"
class Example : public ConsoleGameEngine
{
public:
Example()
{
sAppName = L"Example";
}
private:
uint32_t Lehmer(uint32_t seed)
{
uint32_t nLehmer;
uint64_t tmp;
nLehmer = seed + 0xE120FC15;
tmp = (uint64_t)nLehmer * 0x4A39B70D;
uint32_t m1 = (tmp >> 32) ^ tmp;
tmp = (uint64_t)m1 * 0x12FAD5C9;
uint32_t m2 = (tmp >> 32) ^ tmp;
return m2;
}
void Wrap(uint32_t& n, uint32_t min, uint32_t max)
{
n = (n % (max - min)) + min;
}
bool bPanStarted = false;
int nStartPanX = 0;
int nStartPanY = 0;
int nOffsetX = 0;
int nOffsetY = 0;
protected:
bool OnUserCreate() override
{
return true;
}
bool OnUserUpdate(float fDeltaTime) override
{
if (GetMouse(0).bPressed)
{
nStartPanX = GetMouseX();
nStartPanY = GetMouseY();
bPanStarted = true;
}
if (GetMouse(0).bReleased)
bPanStarted = false;
if (bPanStarted)
{
int32_t nMouseX = GetMouseX();
int32_t nMouseY = GetMouseY();
nOffsetX += nStartPanX - nMouseX;
nOffsetY += nStartPanY - nMouseY;
nStartPanX = nMouseX;
nStartPanY = nMouseY;
}
Clear(PIXEL_SOLID, FG_BLACK);
for (int i = 0; i < ScreenWidth(); i++)
for (int j = 0; j < ScreenHeight(); j++)
{
uint32_t nSeed = (j + nOffsetY) << 16 | (i + nOffsetX);
uint32_t nRand = Lehmer(nSeed);
bool bIsPlanet = nRand % 2048 < 4;
uint32_t nRadius = nRand;
Wrap(nRadius, 3, 8);
uint32_t nCol = nRand;
Wrap(nCol, 1, 15);
if (bIsPlanet)
FillCircle(i, j, nRadius, PIXEL_SOLID, (int16_t)nCol);
}
return true;
}
};
int main()
{
Example demo;
if (demo.ConstructConsole(256, 240, 4, 4) == RC_OK)
demo.Run();
return 0;
}