-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame_Of_life.pde
107 lines (88 loc) · 1.44 KB
/
Game_Of_life.pde
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
int SIZE = 10;
int RES_X = 2560/SIZE;
int RES_Y = 1080/SIZE;
float scale = 1;
float xPan = 0;
float yPan = 0;
int PLAYERS = 3;
int currentColor=1;
boolean isPlaying = false;
boolean isSpeedHack = false;
int radius = 20;
Cell[][] cells = new Cell[RES_X][RES_Y];
void setup()
{
fullScreen();
setCells(cells);
loop();
}
void draw()
{
translate(xPan, yPan);
scale(scale);
translate(-xPan, -yPan);
drawCells(cells);
if (isPlaying)
{
updateCells(cells);
if (isSpeedHack)
{
for(int i = 0;i<9;i++)
updateCells(cells);
}
}
}
void keyPressed()
{
if (key=='1')
{
currentColor=1;
}
else if(key == '2')
{
currentColor=2;
}
else if(key == '3')
{
currentColor=3;
}
else if(key == '4')
{
currentColor=4;
}
else if(key == '=')
{
isSpeedHack=!isSpeedHack;
}
else if(keyCode == DELETE)
{
clearScreen(cells);
}
}
void mouseDragged()
{
if(mouseButton == LEFT)
userClick(cells, true, currentColor, radius);
}
void mouseClicked()
{
if(mouseButton == LEFT )
userClick(cells, true, currentColor, radius);
else if(mouseButton == RIGHT)
isPlaying=!isPlaying;
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
if (e==-1)
{
scale+=0.05;
xPan=mouseX;
yPan=mouseY;
}
else if (e==1 && scale>1)
{
scale-=0.05;
if(scale<1)
scale=1;
}
}