-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity_Player.js
89 lines (80 loc) · 2.89 KB
/
Entity_Player.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
function Entity_Player()
{
system.log("Constructing Player Entity...");
var self = this;
self.name = "player";
self.x = 1502;
self.y = 1024;
self.speed = 400;
self.heading = 0;//0=left, 1=right;
//Values for Physics
self.stepSize = 0.25;
self.height = 96;
self.width = 16;
self.moving = false;
self.lightInteraction = true;
var animate = new Animation_Manager();
this.addAllEntityAnimations = function()
{
//animate.addAnimation('run','player'/*tex*/,16/*start*/,25/*end*/,75/*tile-ms-time*/,128/*tile-size*/,1024/*sheet-size*/, true);
//animate.addAnimation('idle','playerOld'/*tex*/,8/*start*/,11/*end*/,250/*tile-ms-time*/,128/*tile-size*/,1024/*sheet-size*/, true);
//animate.addAnimation('jump','playerOld'/*tex*/,24/*start*/,31/*end*/,50/*tile-ms-time*/,128/*tile-size*/,1024/*sheet-size*/, false);
};self.addAllEntityAnimations();
this.setPosition = function(X, Y)
{
self.x = X;
self.y = Y;
}
this.jump = function()
{
self.velocity = -600;
}
this.setHeading = function(newHeading)
{
self.heading = newHeading;
self.moving = true;
return 0;
}
this.resetFunctionalVariables = function()
{
self.moving = false;
}
this.doInput = function()
{
self.resetFunctionalVariables();
//self.x += (input.key['right'] == 1) ? self.speed * clock.delta + self.setHeading(1) : 0;
//self.x -= (input.key['left'] == 1) ? self.speed * clock.delta + self.setHeading(0) : 0;
self.y -= (input.key['up'] == 1) ? self.speed * clock.delta + self.setHeading(0) : 0;
self.y += (input.key['down'] == 1) ? self.speed * clock.delta + self.setHeading(1) : 0;
//((input.key['space'] == 1) && self.grounded) ? self.jump() : 0;
/*if(!self.moving && self.grounded){animate.setAnimation('idle');}
else if(self.moving && self.grounded){animate.setAnimation('run');}
else if(!self.grounded){animate.setAnimation('jump');}
if(system.debug){ self.y -= (input.key['up'] == 1) ? self.speed * clock.delta : 0; self.y += (input.key['down'] == 1) ? self.speed * clock.delta : 0; }*/
//Test Particles
if(input.mouseLeft == 2){
r = Math.round(Math.random() * 255);
g = Math.round(Math.random() * 255);
b = Math.round(Math.random() * 255);
fx.addFX('explosion1', input.screenX, input.screenY, 3, 50, false, 'rgb('+r+','+g+','+b+')');
}
}
this.update = function()
{
self.doInput();
animate.updateAnimations();
}
this.draw = function()
{canvas.fillStyle = "rgb(255,0,255)";
canvas.fillRect(h.X(self.x - self.width / 2), h.Y(self.y - self.height / 2), self.width, self.height);
/*
if(self.heading == 1) {
canvas.drawImage(asset.tex[animate.currentTexture()], animate.left(), animate.top(), 128, 128, h.X(self.x - 64), h.Y(self.y - 64), 128, 128);
} else {
canvas.scale(-1,1);
canvas.drawImage(asset.tex[animate.currentTexture()], animate.left(), animate.top(), 128, 128, (h.X(self.x - 64) * -1) - 128, h.Y(self.y - 64), 128, 128);
canvas.scale(-1,1);
}
*/
}
}