-
Notifications
You must be signed in to change notification settings - Fork 7
/
Example_-_Switch_array_hills.c
114 lines (83 loc) · 3.1 KB
/
Example_-_Switch_array_hills.c
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
#include "raylib.h"
void floodit();
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example.");
int mymap[50][50] = {0};
for (int i=0;i<20;i++){
int y=0;
if (GetRandomValue(0,1) == 1) y=1;
mymap[10+i][25+y] = 1;
}
for (int i=0;i<31550;i++)
{
int x = GetRandomValue(1,49);
int y = GetRandomValue(1,49);
if (mymap[y][x] == 1)
{
switch (GetRandomValue(0,3))
{
case 0:
mymap[y-1][x]=1;
break;
case 1:
mymap[y+1][x]=1;
break;
case 2:
mymap[y][x-1]=1;
break;
case 3:
mymap[y][x+1]=1;
break;
}
}
}
// Create a Image in memory
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
// Clear our texture(image) before entering the game loop
BeginTextureMode(target);
ClearBackground(BLUE);
EndTextureMode();
// Draw something on it.
for (int y=0;y<50;y++)
{
for (int x=0;x<50; x++)
{
if (mymap[y][x]==1)
{
BeginTextureMode(target);
DrawRectangle(x*16,y*8,16,8,BLACK);
EndTextureMode();
}
}
}
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
DrawText("Switch/array/hillalgo.", 100, 180, 40, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadRenderTexture(target); // Unload render texture
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}