Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
OutRed
GitHub Repository: OutRed/Cuphead-webgame
Path: blob/main/js/physics.js
139 views
1
function prepareVelocity(subj) {
2
subj.velocity = [
3
collectedTime = 1
4
];
5
subj.velocity.x = 0;
6
subj.velocity.y = 0;
7
}
8
9
function simPhysics(subj) {
10
subj.dx = 0;
11
subj.dy = 0;
12
subj.gravitySpeed += 0.15;
13
subj.dy += subj.gravitySpeed;
14
15
//COLLISION STUFF
16
//Cuphead can't get moved through barrier
17
//Checks user's pressing on the keys (MUST BE GOT REMOVED TO GAMEPLAY.JS)
18
keyCheck(subj);
19
physJob = givenForce / subj.velocity.collectedTime;
20
21
if(subj.isJumping) {
22
subj.isJumping = false;
23
subj.velocity.collectedTime = 1;
24
subj.velocity.y -= physJob;
25
}
26
27
subj.dy += subj.velocity.y;
28
29
subj.isGround = false;
30
31
//Always checks the character's direction and changed to the supposed to be flip
32
dirCheck(subj);
33
34
if(subj.x >= 500 && rightPressed)
35
subj.dx = 0;
36
//Cuphead can't get moved deeper a floop (collision)
37
if(subj.y > (testSq.y - subj.height))
38
subj.isGround = true;
39
40
if(subj.isGround && subj.dy > 0) {
41
subj.velocity.y = 0;
42
subj.velocity.collectedTime = 1;
43
erasePhysics(subj);
44
subj.dy = 0;
45
}
46
47
}
48
49
function resultPhysics(subj) {
50
subj.x += subj.dx;
51
subj.y += subj.dy;
52
}
53
54
function erasePhysics(subj) {
55
subj.gravitySpeed = 0;
56
}
57
58