Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
OutRed
GitHub Repository: OutRed/Cuphead-webgame
Path: blob/main/js/gameplay.js
139 views
1
class Character
2
{
3
constructor(
4
animSet,
5
x=0, y=0,
6
width=100,
7
height=150,
8
speed=5)
9
{
10
initAnim(this, animSet);
11
12
this.speed = speed;
13
14
this.x = x;
15
this.y = y;
16
this.width = width;
17
this.height = height;
18
19
this.flip = ' ';
20
this.chosenPath = "";
21
22
//erasePhysics(this);
23
this.gravitySpeed = 0;
24
}
25
26
// Should be prepareAnimation(this) instead of:
27
animate(fun = function () { return false; })
28
{
29
if(arguments.length == 1) {
30
if(!fun)
31
basicAnim(this);
32
else
33
fun();
34
}
35
else
36
{
37
this.path = this.animSet[this.chosenAct][0];
38
this.maxFrame = this.animSet[this.chosenAct][1];
39
40
if(this.animSet[this.chosenAct][2] == false)
41
{
42
this.takenAnimation = function()
43
{
44
basicAnim(this);
45
}
46
}
47
else
48
{
49
this.takenAnimation = function()
50
{
51
this.animSet[this.chosenAct][2]();
52
}
53
}
54
this.takenAnimation();
55
}
56
}
57
update() { console.log("THERE SHOULD BE AN UPDATE FUNCTION!!!"); }
58
}
59
60
Character.readyToJump = true;
61
Character.isJumping = false;
62
Character.isGround = false;
63
64
//Checks user's hitting on the keys
65
function keyCheck(subj)
66
{
67
if(leftPressed == true) {
68
subj.dx = -speed;
69
subj.flip = 'x';
70
}
71
if(rightPressed == true) {
72
subj.dx = speed;
73
subj.flip = ' ';
74
}
75
if(upPressed == true && subj.isGround && subj.readyToJump) {
76
subj.isJumping = true;
77
subj.readyToJump = false;
78
}
79
if(upPressed == false) {
80
subj.readyToJump = true;
81
}
82
if(downPressed == true)
83
subj.dy = speed;
84
}
85
86
//Always checks the character about his velocity
87
function dirCheck(subj) {
88
if(subj.dx != 0) {
89
try {
90
subj.chosenAct = "run";
91
} catch(err) {
92
subj.frame = 1;
93
}
94
} else {
95
subj.chosenAct = "idle";
96
}
97
}
98
99