-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboardFunctions.js
147 lines (140 loc) · 7.64 KB
/
keyboardFunctions.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
if(typeof KeyboardJS !== 'undefined'){
KeyboardJS.on('i', function(){
body = b2world.getBodyAt(mousex, mousey)
b2world.applyImpulse(body, 270, 10)
});
KeyboardJS.on('b', function(){
b2world.createCircle('glowball', Game.asset.getImageByName('glowball'), 40, mousex, mousey, box2d.b2BodyType.b2_dynamicBody)
});
KeyboardJS.on('c', function(){
// bitmap.clearCircle(mousex, mousey, 40)
// terrainBody.clipTerrain({points: 16, radius: 40, x: mousex, y: mousey})
terrainBody.clipTerrain({points: clipPoints, radius: clipRadius, x: mousex, y: mousey})
b2world.getStaticBodyListAt(mousex,mousey,36,0)
});
KeyboardJS.on('o', function(){
if (b2world.debug == 0 ) {
b2world.debug = 1
} else {
b2world.debug = 0
}
});
KeyboardJS.on('e', function(){
if(isEmptyObject(playerCollisionWith)){
if(leftplayer.item !== ''){
var throwingball = b2world.createCircle(leftplayer.item, Game.asset.getImageByName(leftplayer.item), 9, leftplayer.body.GetPosition().x * 40+40, leftplayer.body.GetPosition().y * 40-5, box2d.b2BodyType.b2_dynamicBody)
//console.log(throwingball)
b2world.applyImpulse(throwingball.body, 1, 1)
leftplayer.item = ''
playerItem = ''
}
}else{
if(isEmptyObject(playerCollisionWith) !== true && playerCollisionWith.GetUserData().name === 'baum2'){
console.log(playerCollisionWith)
playerCollisionWith.SetType(box2d.b2BodyType.b2_dynamicBody)
}
if(isEmptyObject(playerCollisionWith) !== true && playerCollisionWith.GetUserData().name === 'haus2'){
console.log(playerCollisionWith)
var menu = new CG.Menu(Game.width2, 200, 10)
var button1 = new CG.Button(Game.asset.getImageByName('back1'), new CG.Point(Game.width2, 100), '(SCALE)', small, function () {
console.log('menu btn1 clicked')
})
button1.name = 'button1'
menu.addButton(button1)
// var menuHouse = new CG.Button(Game.asset.getImageByName('arrow-25'), new CG.Point(20, 20), 'Button', small, buttonhausCallback)
// menuHouse.name = 'button'
// menuHouse.visible = false
ingamemenulayer.addElement(menu)
mainscreen.addLayer(ingamemenulayer)
}
}
});
KeyboardJS.on('a', function(){
leftplayer.addVelocity(new b2Vec2(-1, 0))
});
KeyboardJS.on('d', function(){
leftplayer.addVelocity(new b2Vec2(1, 0))
});
KeyboardJS.on('w', function(){
if(leftplayer.playerJump === false){
leftplayer.addVelocity(new b2Vec2(0, -5))
}
});
KeyboardJS.on('w + a', function(){
if(leftplayer.playerJump === false){
leftplayer.addVelocity(new b2Vec2(-1, -5))
}
});
KeyboardJS.on('w + d', function(){
if(leftplayer.playerJump === false){
leftplayer.addVelocity(new b2Vec2(1, -5))
}
});
KeyboardJS.on('s', function(){
leftplayer.addVelocity(new b2Vec2(0, 3))
});
KeyboardJS.on('right', function(){
velo = b2world.elements[1].body.GetLinearVelocity()
velo.SelfAdd(new b2Vec2(5, 0))
b2world.elements[1].body.SetLinearVelocity(velo)
});
KeyboardJS.on('left', function(){
velo = b2world.elements[1].body.GetLinearVelocity()
velo.SelfAdd(new b2Vec2(-5, 0))
b2world.elements[1].body.SetLinearVelocity(velo)
});
KeyboardJS.on('up', function(){
b2world.elements[1].body.ApplyForce(new b2Vec2(0, -500), b2world.elements[1].body.GetWorldCenter())
});
KeyboardJS.on('q + d', function () {
// console.log('d down')
// bitmap.clearCircle(leftplayer.body.GetPosition().x * 40 +40,leftplayer.body.GetPosition().y * 40+18, 40)
// terrainBody.clipTerrain({points: 16, radius: 40, x: leftplayer.body.GetPosition().x * 40+40, y: leftplayer.body.GetPosition().y * 40+18})
terrainBody.clipTerrain({points: clipPoints, radius: clipRadius, x: leftplayer.body.GetPosition().x * 40 +40, y: leftplayer.body.GetPosition().y * 40 +18})
b2world.getStaticBodyListAt(leftplayer.body.GetPosition().x *40+40, leftplayer.body.GetPosition().y * 40+18, 36, 0)
});
KeyboardJS.on('q + s + d', function () {
// console.log('s&d down')
// bitmap.clearCircle(leftplayer.body.GetPosition().x * 40 +40,leftplayer.body.GetPosition().y * 40+25, 40)
// terrainBody.clipTerrain({points: 16, radius: 40, x: leftplayer.body.GetPosition().x * 40+40, y: leftplayer.body.GetPosition().y * 40+25})
terrainBody.clipTerrain({points: clipPoints, radius: clipRadius, x: leftplayer.body.GetPosition().x * 40 +40, y: leftplayer.body.GetPosition().y * 40 +25})
b2world.getStaticBodyListAt(leftplayer.body.GetPosition().x *40+40, leftplayer.body.GetPosition().y * 40+25, 36, 0)
});
KeyboardJS.on('q + s', function () {
// console.log('s down')
// bitmap.clearCircle(leftplayer.body.GetPosition().x * 40+25,leftplayer.body.GetPosition().y * 40+40, 40)
// terrainBody.clipTerrain({points: 16, radius: 40, x: leftplayer.body.GetPosition().x * 40+25, y: leftplayer.body.GetPosition().y * 40+40})
terrainBody.clipTerrain({points: clipPoints, radius: clipRadius, x: leftplayer.body.GetPosition().x * 40 +25, y: leftplayer.body.GetPosition().y * 40 +40})
b2world.getStaticBodyListAt(leftplayer.body.GetPosition().x *40+25, leftplayer.body.GetPosition().y * 40+40, 36, 0)
});
KeyboardJS.on('q + s + a', function () {
// console.log('sa down')
// bitmap.clearCircle(leftplayer.body.GetPosition().x * 40 ,leftplayer.body.GetPosition().y * 40+30, 40)
// terrainBody.clipTerrain({points: 16, radius: 40, x: leftplayer.body.GetPosition().x * 40, y: leftplayer.body.GetPosition().y * 40+30})
terrainBody.clipTerrain({points: clipPoints, radius: clipRadius, x: leftplayer.body.GetPosition().x * 40, y: leftplayer.body.GetPosition().y * 40 +30})
b2world.getStaticBodyListAt(leftplayer.body.GetPosition().x *40, leftplayer.body.GetPosition().y * 40+30, 36, 0)
});
KeyboardJS.on('q + a', function() {
// console.log('a down')
// bitmap.clearCircle(leftplayer.body.GetPosition().x * 40 ,leftplayer.body.GetPosition().y * 40+20, 40)
// terrainBody.clipTerrain({points: 16, radius: 40, x: leftplayer.body.GetPosition().x * 40, y: leftplayer.body.GetPosition().y * 40+20})
terrainBody.clipTerrain({points: clipPoints, radius: clipRadius, x: leftplayer.body.GetPosition().x * 40, y: leftplayer.body.GetPosition().y * 40 +20})
b2world.getStaticBodyListAt(leftplayer.body.GetPosition().x *40, leftplayer.body.GetPosition().y * 40+20, 36, 0)
});
KeyboardJS.on('q + w', function(){
});
KeyboardJS.on('q + w + d', function(){
});
KeyboardJS.on('q + w + a', function(){
});
}
/* **
* Helper Function
** */
function isEmptyObject(obj) {
for(var key in obj) {
if(obj.hasOwnProperty(key))
return false;
}
return true;
}