-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
110 lines (96 loc) · 2.82 KB
/
main.js
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
// ************************************************
// Teugg Soccer Physics
// Rip-off of the once popular Soccer Physics game
// Horribly coded by : Kevin Le Teugg, 2020
// File : main.js
// Description : Main function of the code
// ************************************************
function main() {
// GAME ENGINE UPDATE
Engine.update(engine);
// SOCKET EMIT
//socket.emit('keys', keyPressed());
// CANVAS BACKGROUND AND TEXT
image(background0, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
push();
fill(0);
textSize(20);
stroke(0, 0, 0);
pop();
// SCORE LOGIC
gameScore.scoreCheck(ball, goal1, goal2);
gameScore.show();
// TIMER
gameTimer.timerTick();
gameTimer.show();
// SHOW GRAPHICS
ball.show();
ground.show();
goal1.show();
goal2.show();
player1Def.show();
player1Atk.show();
player2Def.show();
player2Atk.show();
// IN CASE BALL GETS STUCK ON TOP OF GOAL - DON'T THINK IF IT WILL WORK
if (ball.body.position.y < (goal1.h - ball.r) && ball.body.velocity.x == 0 && ball.body.velocity.y == 0) {
gameManager.resetBall();
}
if (menu == P1_LOCAL_LEFT_SELECTED) {
singlePlayerAIRight.tickAI(player2Def, player2Atk);
}
else if (menu == P1_LOCAL_RIGHT_SELECTED) {
singlePlayerAILeft.tickAI(player1Def, player1Atk);
}
else if (menu == 1000) {
//singlePlayerAIRight.AItest(player2Def, player2Atk);
singlePlayerAILeft.tickAI(player1Def, player1Atk);
singlePlayerAIRight.tickAI(player2Def, player2Atk);
}
// KEEP PLAYERS UPRIGHT
if (player1Def.isOnGround(ground)){
player1Def.updateAbsoluteAngle();
player1Def.uprightTilt();
}
if (player1Atk.isOnGround(ground)){
player1Atk.updateAbsoluteAngle();
player1Atk.uprightTilt();
}
if (player2Def.isOnGround(ground)){
player2Def.updateAbsoluteAngle();
player2Def.uprightTilt();
}
if (player2Atk.isOnGround(ground)){
player2Atk.updateAbsoluteAngle();
player2Atk.uprightTilt();
}
// GAME CONTROLS
if (keyIsDown(65)) {
if (menu == P1_LOCAL_LEFT_SELECTED || menu == P2_LOCAL_SELECTED) {
//player1Def.cstrLegs.stiffness = 0.00001;
player1Def.cstrLegs.stiffness = 0;
player1Def.kick(kickForceCoeff);
}
}
if (keyIsDown(68)) {
if (menu == P1_LOCAL_LEFT_SELECTED || menu == P2_LOCAL_SELECTED) {
//player1Atk.cstrLegs.stiffness = 0.00001;
player1Atk.cstrLegs.stiffness = 0;
player1Atk.kick(kickForceCoeff);
}
}
if (keyIsDown(RIGHT_ARROW)) {
if (menu == P1_LOCAL_RIGHT_SELECTED || menu == P2_LOCAL_SELECTED) {
//player2Def.cstrLegs.stiffness = 0.00001;
player2Def.cstrLegs.stiffness = 0;
player2Def.kick(kickForceCoeff);
}
}
if (keyIsDown(LEFT_ARROW)){
if (menu == P1_LOCAL_RIGHT_SELECTED || menu == P2_LOCAL_SELECTED) {
//player2Atk.cstrLegs.stiffness = 0.00001;
player2Atk.cstrLegs.stiffness = 0;
player2Atk.kick(kickForceCoeff);
}
}
}