-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaking_Hitbox
More file actions
359 lines (317 loc) · 11.9 KB
/
Making_Hitbox
File metadata and controls
359 lines (317 loc) · 11.9 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
//Character Placement
var player1X = 45;
var player1Y = 200;
var player2X = 260 ;
var player2Y = 150 ;
var pX = 0;
var pY = 0;
var pW = 0;
var pH = 0;
var eW = 50;
var eH = 50;
var p2X = 150;
var p2Y = 165;
var p2W = 29;
var p2H = 30;
//Character Movement
var boxerSpeed = 3;
var enemyboxerSpeed = 3;
//Key Input Code
var keys = [];
var keyPressed = function() {
keys[keyCode] = true; };
var keyReleased = function() {
keys[keyCode] = false; };
//BitMoji Code
var drawtopPunch = function (BitX,BitY,bitHeight){
//Top
fill(23, 99, 50);
rect(BitX + bitHeight/150 * 75,BitY+ bitHeight/150 *129, bitHeight/150 *50, bitHeight/150 *65);
rect(BitX + bitHeight/150 * 118,BitY+bitHeight/150 *126, bitHeight/150 *70,bitHeight/150 *25,bitHeight/150 * 20);
rect(BitX + bitHeight/150 * 59,BitY+bitHeight/150 *126,bitHeight/150 * 25,bitHeight/150 * 60,bitHeight/150 * 20);
//Pants
fill(61, 57, 46);
rect(BitX + bitHeight/150 * 75,BitY+bitHeight/150 *191,bitHeight/150 * 50,bitHeight/150 * 82);
line(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *272,BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *200);
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 100,BitY+bitHeight/150 *194,bitHeight/150 * 5,bitHeight/150 * 5);
};
var drawbitheadPunch = function (BitX,BitY,bitHeight){
//Head
fill(224, 172, 105);
ellipse(BitX + bitHeight/150 * 142, BitY+ bitHeight/150 *85,bitHeight/150 * 18,bitHeight/150 * 26);
ellipse(BitX + bitHeight/150 * 58,BitY+ bitHeight/150 * 85,bitHeight/150 * 18,bitHeight/150 * 26);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *91,bitHeight/150 * 86,bitHeight/150 * 100);
//Eye 1
fill(255, 255, 255);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *94,bitHeight/150 * 20,bitHeight/150 * 20);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *94,bitHeight/150 * 20,bitHeight/150 * 20);
//Eye 2
fill(135, 82, 2);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *94,bitHeight/150 * 13,bitHeight/150 * 13);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *94,bitHeight/150 * 13,bitHeight/150 * 13);
//Eye 3
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *94,bitHeight/150 * 8,bitHeight/150 * 8);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *94,bitHeight/150 * 8,bitHeight/150 * 8);
//Eye 4
fill(250, 250, 250);
ellipse(BitX + bitHeight/150 * 117,BitY+ bitHeight/150 *92,bitHeight/150 * 4,bitHeight/150 * 4);
ellipse(BitX + bitHeight/150 * 77,BitY+ bitHeight/150 *92,bitHeight/150 * 4,bitHeight/150 * 4);
//Beanie
fill(124, 124, 125);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *51,bitHeight/150 *78,bitHeight/150 *42);
rect(BitX + bitHeight/150 * 58,BitY+ bitHeight/150 *55,bitHeight/150 *83,bitHeight/150 *18);
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *29,bitHeight/150 *10,bitHeight/150 *5);
//Nose
fill(219, 168, 105);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *109,bitHeight/150 *17,bitHeight/150 *12);
//Lips
fill(255, 129, 112);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *126,bitHeight/150 *33,bitHeight/150 *10);
line(BitX + bitHeight/150 * 115,BitY+ bitHeight/150 *125,BitX + bitHeight/150 * 84,BitY+ bitHeight/150 *125);
//Facial Hair
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *79,bitHeight/150 *19,bitHeight/150 *3);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *79,bitHeight/150 *19,bitHeight/150 *3);
triangle(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *144,BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *135,BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *135);
rect(BitX + bitHeight/150 * 87,BitY+ bitHeight/150 *117,bitHeight/150 *25,bitHeight/150 *1);
};
var drawtop = function (BitX,BitY,bitHeight){
//Top
fill(23, 99, 50);
rect(BitX + bitHeight/150 * 75,BitY+ bitHeight/150 *129, bitHeight/150 *50, bitHeight/150 *65);
rect(BitX + bitHeight/150 * 118,BitY+bitHeight/150 *126, bitHeight/150 *25,bitHeight/150 *60,bitHeight/150 * 20);
rect(BitX + bitHeight/150 * 59,BitY+bitHeight/150 *126,bitHeight/150 * 25,bitHeight/150 * 60,bitHeight/150 * 20);
//Pants
fill(61, 57, 46);
rect(BitX + bitHeight/150 * 75,BitY+bitHeight/150 *191,bitHeight/150 * 50,bitHeight/150 * 82);
line(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *272,BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *200);
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 100,BitY+bitHeight/150 *194,bitHeight/150 * 5,bitHeight/150 * 5);
};
var drawbithead = function (BitX,BitY,bitHeight){
//Head
fill(224, 172, 105);
ellipse(BitX + bitHeight/150 * 142, BitY+ bitHeight/150 *85,bitHeight/150 * 18,bitHeight/150 * 26);
ellipse(BitX + bitHeight/150 * 58,BitY+ bitHeight/150 * 85,bitHeight/150 * 18,bitHeight/150 * 26);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *91,bitHeight/150 * 86,bitHeight/150 * 100);
//Eye 1
fill(255, 255, 255);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *94,bitHeight/150 * 20,bitHeight/150 * 20);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *94,bitHeight/150 * 20,bitHeight/150 * 20);
//Eye 2
fill(135, 82, 2);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *94,bitHeight/150 * 13,bitHeight/150 * 13);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *94,bitHeight/150 * 13,bitHeight/150 * 13);
//Eye 3
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *94,bitHeight/150 * 8,bitHeight/150 * 8);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *94,bitHeight/150 * 8,bitHeight/150 * 8);
//Eye 4
fill(250, 250, 250);
ellipse(BitX + bitHeight/150 * 117,BitY+ bitHeight/150 *92,bitHeight/150 * 4,bitHeight/150 * 4);
ellipse(BitX + bitHeight/150 * 77,BitY+ bitHeight/150 *92,bitHeight/150 * 4,bitHeight/150 * 4);
//Beanie
fill(124, 124, 125);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *51,bitHeight/150 *78,bitHeight/150 *42);
rect(BitX + bitHeight/150 * 58,BitY+ bitHeight/150 *55,bitHeight/150 *83,bitHeight/150 *18);
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *29,bitHeight/150 *10,bitHeight/150 *5);
//Nose
fill(219, 168, 105);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *109,bitHeight/150 *17,bitHeight/150 *12);
//Lips
fill(255, 129, 112);
ellipse(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *126,bitHeight/150 *33,bitHeight/150 *10);
line(BitX + bitHeight/150 * 115,BitY+ bitHeight/150 *125,BitX + bitHeight/150 * 84,BitY+ bitHeight/150 *125);
//Facial Hair
fill(0, 0, 0);
ellipse(BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *79,bitHeight/150 *19,bitHeight/150 *3);
ellipse(BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *79,bitHeight/150 *19,bitHeight/150 *3);
triangle(BitX + bitHeight/150 * 100,BitY+ bitHeight/150 *144,BitX + bitHeight/150 * 120,BitY+ bitHeight/150 *135,BitX + bitHeight/150 * 80,BitY+ bitHeight/150 *135);
rect(BitX + bitHeight/150 * 87,BitY+ bitHeight/150 *117,bitHeight/150 *25,bitHeight/150 *1);
};
var drawbitGuard = function (BitX,BitY,bitHeight){
//Boxing Gloves
fill(255, 0, 0);
ellipse(BitX + bitHeight/150 * 70,BitY+bitHeight/150 *120,bitHeight/150 * 40,bitHeight/150 * 39);
ellipse(BitX + bitHeight/150 * 135,BitY+bitHeight/150 *120,bitHeight/150 * 40,bitHeight/150 * 39);
};
var drawbitPunch = function (BitX,BitY,bitHeight){
//Boxing Gloves
fill(255, 0, 0);
ellipse(pX = BitX + bitHeight/150 * 70, pY = BitY+bitHeight/150 *120, pW = bitHeight/150 * 40, pH = bitHeight/150 * 39);
ellipse(BitX + bitHeight/150 * 185,BitY+bitHeight/150 *137,bitHeight/150 * 40,bitHeight/150 * 39);
};
//enemy
var enTop = function(eX, eY, eW, eH){
fill(110, 143, 189);
rect(eX, eY, eW, eH);
};
//Health Bar Code
var healthBar = function(x,y,w,h,maxHealth){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.maxHealth = maxHealth;
this.maxWidth = w;
this.health = maxHealth;
};
healthBar.prototype.draw = function() {
strokeWeight(5);
stroke(0, 0, 0);
fill(255, 255, 255);
rect(this.x, this.y, this.maxWidth, this.h);
fill(255, 0, 0);
rect(this.x, this.y, this.w, this.h);
};
healthBar.prototype.Damage = function(amount) {
this.health = amount;
this.w = (this.health / this.maxHealth) * this.maxWidth;
if(this.w <= 0){this.w = 0;}
};
var health = 100;
var healthBarWidth = 200;
var healthBarHeight = 25;
var x1 = width / 2 - healthBarWidth / 2;
var y1 = height / 2 - healthBarHeight / 2;
var health1 = new healthBar(x1 - 60, y1 + 175, healthBarWidth - 60, healthBarHeight, health);
var health2 = new healthBar(x1 + 100, y1 + 175, healthBarWidth - 60, healthBarHeight, health);
//Main Code
var draw = function() {
background(121, 121, 168);
var drawRing = function(){
//Bottom
fill(31, 28, 31);
rect(40,300,300,40);
//Ring Floor
fill(86, 135, 132);
rect(40,140,300,160);
//Blue Corner
fill(59, 71, 199);
rect(40,90,8,50);
rect(332,90,8,50);
//Red Corner
fill(247, 32, 32);
rect(332,250,8,50);
rect(40,250,8,50);
//Rope Rings
fill(46, 42, 42);
ellipse(54,95,12,10);
ellipse(54,112,12,10);
ellipse(54,130,12,10);
ellipse(326,95,12,10);
ellipse(326,112,12,10);
ellipse(326,130,12,10);
ellipse(54,255,12,10);
ellipse(54,273,12,10);
ellipse(54,290,12,10);
ellipse(326,255,12,10);
ellipse(326,273,12,10);
ellipse(326,290,12,10);
//Top Rope
fill(227, 20, 20);
rect(51,95,5,155);
rect(323,95,5,155);
rect(60,92,260,5);
//Middle Rope
fill(247, 247, 247);
rect(323,260,5,8);
rect(51,260,5,8);
rect(60,109,260,5);
//Bottom Rope
fill(27, 186, 2);
rect(323,277,5,8);
rect(51,277,5,8);
rect(60,127,260,5);
};
drawRing();
enTop(player2X, player2Y, eW, eH);
//Health Bar Damage
var hitPoint = function() {
var newHealth = health -= random(1,10);
var newHealth2 = health -= random(1,10);
health1.Damage(newHealth);
health2.Damage(newHealth2);
};
//Draw Health Bars
health1.draw();
health2.draw();
strokeWeight(1);
//Control Layout For Player
if (keyIsPressed && keys[UP]) {
player1Y = player1Y-boxerSpeed;
}
if (keyIsPressed && keys[DOWN]) {
player1Y = player1Y + boxerSpeed;
}
if (keyIsPressed && keys[LEFT]) {
player1X = player1X - boxerSpeed;
}
if (keyIsPressed && keys[RIGHT]) {
player1X = player1X + boxerSpeed;
}
if (keyIsPressed && keys[77]) {
drawtopPunch(player1X, player1Y, 50);
drawbitheadPunch(player1X, player1Y, 50);
drawbitPunch(player1X, player1Y, 50);
}
else{
drawtop(player1X, player1Y, 50);
drawbithead(player1X, player1Y, 50);
drawbitGuard(player1X, player1Y, 50);
}
//Control Layout For Enemy
if (keyIsPressed && keys[87]) {
player2Y = player2Y - enemyboxerSpeed;
}
if (keyIsPressed && keys[83]) {
player2Y = player2Y + enemyboxerSpeed;
}
if (keyIsPressed && keys[65]) {
player2X = player2X - enemyboxerSpeed;
}
if (keyIsPressed && keys[68]) {
player2X = player2X + enemyboxerSpeed;
}
else
{
enTop(player2X, player2Y, 50);
}
//Keep Player1 In The Ring
if(player1Y > 210){
player1Y = 210;
}
if(player1Y < 50){
player1Y = 50;
}
if(player1X > 275){
player1X = 275;
}
if(player1X < 35){
player1X = 35;
}
//Keep Player2 In The Ring
if(player2Y > 210){
player2Y = 210;
}
if(player2Y < 50){
player2Y = 50;
}
if(player2X > 275){
player2X = 275;
}
if(player2X < 35){
player2X = 35;
}
//Detect Enemy Punched
if(pX > player2X - eW && pX < player2X + eW && pY > player2Y - eH && pY < player2Y + eH) {
var newHealth2 = health -= random(0.01,0.5);
health2.Damage(newHealth2);
pX = player1X - boxerSpeed;
pY = player1Y + boxerSpeed;
}
};