forked from Rovanion/SuperHappyFunTime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.js
98 lines (90 loc) · 3.19 KB
/
Demo.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
/**
* A computer controller for a Character.
* @param gameState The current state of the game, as in a level.
* @param character The character to be controlled.
*/
Demo = function(gameState, character){
this.gameState = gameState;
this.character = character;
};
Demo.prototype = {
run: function(){
for (var i = 0; i < 100; i++) {
this.gameState.time.events.add(1000 + i*8500, this.walkRight, this, 850);
this.gameState.time.events.add(1500 + i*8500, this.shoot, this, -Math.PI / 16, 610);
this.gameState.time.events.add(2000 + i*8500, this.walkRight, this, 1060);
this.gameState.time.events.add(3300 + i*8500, this.walkLeft, this, 200);
this.gameState.time.events.add(3500 + i*8500, this.shoot, this, -Math.PI * 20 / 32, 900);
this.gameState.time.events.add(3600 + i*8500, this.jump, this);
this.gameState.time.events.add(4200 + i*8500, this.walkLeft, this, 3500);
this.gameState.time.events.add(4500 + i*8500, this.jump, this);
this.gameState.time.events.add(5100 + i*8500, this.jump, this);
this.gameState.time.events.add(5700 + i*8500, this.jump, this);
this.gameState.time.events.add(6300 + i*8500, this.jump, this);
this.gameState.time.events.add(8500 + i*8500, this.resetBobby, this);
}
},
/**
* @param angle The angle in radians towards which to fire a hookshot.
* @param releaseTime For how long should the hook be held?
*/
shoot: function(angle, releaseTime){
this.character.hookShot.shoot(
this.character.torso.position.x + 20 * Math.sin(angle),
this.character.torso.position.y + 20 * Math.cos(angle),
angle
);
console.debug(angle);
if (angle > -Math.PI / 2) {
this.character.torso.animations.frame = 1;
this.character.torso.rotation = angle;
} else {
this.character.torso.animations.frame = 0;
this.character.torso.rotation = -angle;
}
this.gameState.time.events.add(releaseTime, this.character.hookShot.cancelHook, this.character.hookShot);
},
/**
* Make the character walk right.
* @param duration For how long he should walk.
*/
walkRight: function(duration){
this.character.legs.animations.play('right', null, true);
this.character.torso.body.acceleration.setTo(this.character.ACCELERATION * 20, 0);
this.gameState.time.events.add(duration, this.stopWalking, this);
},
/**
* Make the character walk left.
* @param duration For how long he should walk.
*/
walkLeft: function(duration){
this.character.legs.animations.play('left', null, true);
this.character.torso.body.acceleration.setTo(-this.character.ACCELERATION * 20, 0);
//this.character.torso.angle
this.gameState.time.events.add(duration, this.stopWalking, this);
},
/**
* Stop the character from walking.
*/
stopWalking: function(){
this.character.torso.body.acceleration.setTo(0, 0);
this.character.legs.animations.stop();
},
/**
* Make the character jump
*/
jump: function(){
if(this.character.torso.body.blocked.down){
this.character.torso.body.velocity.setTo(
this.character.torso.body.velocity.x,
this.character.JUMP_ACCELERATION
);
}
},
resetBobby: function() {
this.character.torso.body.velocity.x = 0;
this.character.torso.body.velocity.y = 0;
this.character.torso.x = 100;
this.character.torso.y = 200;
}
};