-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathden-ctf.html
More file actions
209 lines (194 loc) · 3.61 KB
/
Copy pathden-ctf.html
File metadata and controls
209 lines (194 loc) · 3.61 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.1/lib/p5.js"></script>
<script>
let x1change = 0;
let x1 = x1change;
let y1change = 0;
let y1 = y1change;
let x2 = 0;
let y2 = 0;
let span = 500;
let flagx = span / 2;
let flag1y = span - 30;
let flag2y = 30;
let tag1 = false;
let tag2 = false;
let flag1pickup = false;
let flag2pickup = false;
let player1win = false;
let player2win = false;
function setup() {
createCanvas(span, span);
x1 = 250;
y1 = span - 100;
x2 = 250;
y2 = 100;
frameRate(60);
}
function draw() {
background(220);
//tag physics
{
//Blue Get tagged
if (x1 - x2 < 30 && x1 - x2 > -30) {
if (y1 - y2 < 30 && y1 - y2 > -30) {
if (y1 < span / 2) {
tag1 = true;
} else {
tag1 = false;
}
} else {
tag1 = false;
}
} else {
tag1 = false;
}
//Red Get tagged
if (x1 - x2 < 30 && x1 - x2 > -30) {
if (y1 - y2 < 30 && y1 - y2 > -30) {
if (y2 > span / 2) {
tag2 = true;
} else {
tag2 = false;
}
} else {
tag2 = false;
}
} else {
tag2 = false;
}
//respawn
if (tag2 === true) {
x2 = span / 2;
y2 = span / 5;
}
if (tag1 === true) {
x1 = span / 2;
y1 = span - span / 5;
}
}
//flag physics
{
if (tag2) {
flag1pickup = false;
}
//blue flag taken
if (x2 - flagx < 30 && x2 - flagx > -30) {
if (y2 - flag1y > -30 && y2 - flag1y < 30) {
flag1pickup = true;
}
}
if (flag1pickup) {
if (y2 < span / 2) {
player2win = true;
}
}
if (player2win) {
textSize(85);
text("RED WINS!!!", 0, span / 2 + 30);
return;
}
if (tag1) {
flag2pickup = false;
}
//blue flag taken
if (x1 - flagx < 30 && x1 - flagx > -30) {
if (y1 - flag2y > -30 && y1 - flag2y < 30) {
flag2pickup = true;
}
}
if (flag2pickup) {
if (y1 > span / 2) {
player1win = true;
}
}
if (player1win) {
fill(0, 0, 255);
textSize(80);
text("BLUE WINS!!!", 0, span / 2 + 30);
return;
}
}
//Bush pyhsics
square(flagx - 15, flag2y - 15, 30);
line(0, span / 2, span, span / 2);
fill(0, 0, 255);
square(flagx - 15, flag1y - 15, 30);
//Player 1
{
fill(0, 0, 255);
//Movement
{
if (keyIsDown(65) === true) {
x1 -= 5;
}
if (keyIsDown(68) === true) {
x1 += 5;
}
if (keyIsDown(87) === true) {
y1 -= 5;
}
if (keyIsDown(83) === true) {
y1 += 5;
}
}
translate(x1, y1);
//Borders
{
if (x1 > span) {
x1 = span;
}
if (x1 < span - span) {
x1 = span - span;
}
if (y1 > span) {
y1 = span;
}
if (y1 < span - span) {
y1 = span - span;
}
}
}
circle(0, 0, 30);
rect(-5, -30, 10, 15);
translate(-x1, -y1);
//Player 2
{
fill(255, 0, 0);
translate(x2, y2);
rotate(78.548);
//Movement
{
if (keyIsDown(74) === true) {
x2 -= 5;
}
if (keyIsDown(76) === true) {
x2 += 5;
}
if (keyIsDown(73) === true) {
y2 -= 5;
}
if (keyIsDown(75) === true) {
y2 += 5;
}
}
//Borders
{
if (x2 > span) {
x2 = span;
}
if (x2 < span - span) {
x2 = span - span;
}
if (y2 > span) {
y2 = span;
}
if (y2 < span - span) {
y2 = span - span;
}
}
}
circle(0, 0, 30);
rect(-5, -30, 10, 15);
}
</script>