Skip to content

Commit 22ef8b7

Browse files
committed
first den-ctf. need to fix indentation
1 parent 78e0e15 commit 22ef8b7

1 file changed

Lines changed: 216 additions & 0 deletions

File tree

den-ctf.html

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<!doctype html>
2+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.1/lib/p5.js"></script>
3+
4+
<script>
5+
let x1change = 0;
6+
let x1 = x1change;
7+
let y1change = 0;
8+
let y1 = y1change;
9+
let x2 = 0;
10+
let y2 = 0;
11+
let span = 500;
12+
let flagx = span / 2;
13+
let flag1y = span -30;
14+
let flag2y = 30;
15+
let tag1 = false;
16+
let tag2 = false;
17+
let flag1pickup = false;
18+
let flag2pickup = false;
19+
let player1win = false;
20+
let player2win = false;
21+
22+
function setup() {
23+
createCanvas(span, span);
24+
x1 = 250;
25+
y1 = span - 100;
26+
x2 = 250;
27+
y2 = 100;
28+
frameRate(60);
29+
}
30+
31+
function draw() {
32+
background(220);
33+
//tag physics
34+
{
35+
//Blue Get tagged
36+
if (x1 - x2 < 30 && x1 - x2 > -30) {
37+
if (y1 - y2 < 30 && y1 - y2 > -30) {
38+
if (y1 < span / 2) {
39+
tag1 = true;
40+
} else {
41+
tag1 = false;
42+
}
43+
} else {
44+
tag1 = false;
45+
}
46+
} else {
47+
tag1 = false;
48+
}
49+
//Red Get tagged
50+
if (x1 - x2 < 30 && x1 - x2 > -30) {
51+
if (y1 - y2 < 30 && y1 - y2 > -30) {
52+
if (y2 > span / 2) {
53+
tag2 = true;
54+
} else {
55+
tag2 = false;
56+
}
57+
} else {
58+
tag2 = false;
59+
}
60+
} else {
61+
tag2 = false;
62+
}
63+
//respawn
64+
65+
if (tag2 === true) {
66+
x2 = span / 2;
67+
y2 = span / 5;
68+
}
69+
if (tag1 === true) {
70+
x1 = span / 2;
71+
y1 = span - span / 5;
72+
}
73+
}
74+
//flag physics
75+
{
76+
if(tag2){
77+
flag1pickup=false
78+
}
79+
//blue flag taken
80+
if (x2 - flagx < 30 && x2 - flagx > -30) {
81+
if (y2 - flag1y>-30 && y2-flag1y<30){
82+
flag1pickup = true;
83+
84+
}
85+
}
86+
87+
88+
if (flag1pickup) {
89+
if (y2 < span / 2) {
90+
player2win = true
91+
92+
}
93+
}
94+
if(player2win){
95+
textSize(85)
96+
text("RED WINS!!!", 0, span / 2 + 30);
97+
return
98+
}
99+
100+
if(tag1){
101+
flag2pickup=false
102+
}
103+
//blue flag taken
104+
if (x1 - flagx < 30 && x1 - flagx > -30) {
105+
if (y1 - flag2y>-30 && y1-flag2y<30){
106+
flag2pickup = true;
107+
108+
}
109+
}
110+
111+
112+
if (flag2pickup) {
113+
if (y1 > span / 2) {
114+
player1win = true
115+
116+
}
117+
}
118+
if(player1win){
119+
fill(0,0,255)
120+
textSize(80)
121+
text("BLUE WINS!!!", 0, span / 2 + 30);
122+
return
123+
}
124+
}
125+
//Bush pyhsics
126+
127+
square(flagx - 15, flag2y - 15, 30);
128+
line(0, span / 2, span, span / 2);
129+
130+
131+
fill(0, 0, 255);
132+
square(flagx - 15, flag1y -15, 30);
133+
134+
//Player 1
135+
{
136+
fill(0, 0, 255);
137+
//Movement
138+
{
139+
if (keyIsDown(65) === true) {
140+
x1 -= 5;
141+
}
142+
if (keyIsDown(68) === true) {
143+
x1 += 5;
144+
}
145+
if (keyIsDown(87) === true) {
146+
y1 -= 5;
147+
}
148+
if (keyIsDown(83) === true) {
149+
y1 += 5;
150+
}
151+
}
152+
translate(x1, y1);
153+
154+
//Borders
155+
{
156+
if (x1 > span) {
157+
x1 = span;
158+
}
159+
if (x1 < span - span) {
160+
x1 = span - span;
161+
}
162+
if (y1 > span) {
163+
y1 = span;
164+
}
165+
if (y1 < span - span) {
166+
y1 = span - span;
167+
}
168+
}
169+
}
170+
171+
circle(0, 0, 30);
172+
rect(-5, -30, 10, 15);
173+
translate(-x1, -y1);
174+
175+
//Player 2
176+
{
177+
fill(255, 0, 0);
178+
translate(x2, y2);
179+
rotate(78.548);
180+
//Movement
181+
{
182+
if (keyIsDown(74) === true) {
183+
x2 -= 5;
184+
}
185+
if (keyIsDown(76) === true) {
186+
x2 += 5;
187+
}
188+
if (keyIsDown(73) === true) {
189+
y2 -= 5;
190+
}
191+
if (keyIsDown(75) === true) {
192+
y2 += 5;
193+
}
194+
}
195+
196+
//Borders
197+
{
198+
if (x2 > span) {
199+
x2 = span;
200+
}
201+
if (x2 < span - span) {
202+
x2 = span - span;
203+
}
204+
if (y2 > span) {
205+
y2 = span;
206+
}
207+
if (y2 < span - span) {
208+
y2 = span - span;
209+
}
210+
}
211+
}
212+
213+
circle(0, 0, 30);
214+
rect(-5, -30, 10, 15);
215+
}
216+
</script>

0 commit comments

Comments
 (0)