summaryrefslogtreecommitdiff
path: root/client/index.html
diff options
context:
space:
mode:
authorjak1 <mike.wollmann@gmail.com>2021-09-05 11:54:09 +0200
committerjak1 <mike.wollmann@gmail.com>2021-09-05 11:54:09 +0200
commit4e0d0b3fe4c538afcf347542a5d1b60ae82cfc9b (patch)
tree1905ec0c1167d0014fe68d345bd530cbc6edabc8 /client/index.html
parent667bbe8ab13ec5598e89644a092715693d90d343 (diff)
downloadthepixelworld-4e0d0b3fe4c538afcf347542a5d1b60ae82cfc9b.tar.gz
thepixelworld-4e0d0b3fe4c538afcf347542a5d1b60ae82cfc9b.tar.bz2
thepixelworld-4e0d0b3fe4c538afcf347542a5d1b60ae82cfc9b.tar.xz
thepixelworld-4e0d0b3fe4c538afcf347542a5d1b60ae82cfc9b.zip
added player sit(X)
added player rotate(Shift) while standing or sitting on the same tile
Diffstat (limited to 'client/index.html')
-rw-r--r--client/index.html40
1 files changed, 31 insertions, 9 deletions
diff --git a/client/index.html b/client/index.html
index 69e2c86..4dae05f 100644
--- a/client/index.html
+++ b/client/index.html
@@ -203,6 +203,8 @@
self.hpMax = initPack.hpMax;
self.score = initPack.score;
self.dir = initPack.dir;
+ self.shift = false;
+ self.sit = false;
self.drawPlayer = function(){
var x = self.x - Player.list[selfId].x + WIDTH/2;
@@ -211,8 +213,16 @@
// 'player'
var width = 64;
var height = 64;
+ if (self.sit){
+ console.log("sitting")
+ finalWidth = width * self.dir;
+ finalHeight = height * 4;
+ } else {
+ finalWidth = 0;
+ finalHeight = height * self.dir;
+ }
ctx.drawImage(Img.player,
- 0 /* base sprite */, (height * self.dir),
+ finalWidth /* base sprite */, finalHeight,
width, height,
x-width/2, y-height/2,
width, height);
@@ -299,6 +309,8 @@
p.dir = pack.dir;
if(pack.playerName !== undefined)
p.playerName = pack.playerName;
+ if(pack.sit !== undefined)
+ p.sit = pack.sit;
}
}
for(var i = 0; i < data.bullet.length; i++){
@@ -398,26 +410,36 @@
if (document.activeElement === document.getElementById('ui') ||
document.activeElement === document.getElementById('game') ||
document.activeElement === document.getElementById('ctx')){
+ // shift
+ if(event.keyCode === 16)
+ self.shift = true;
+ // movement
if(event.keyCode === 68 || event.keyCode === 39) // d
- socket.emit('keyPress',{inputId: 'right', state: true});
+ socket.emit('keyPress',{inputId: 'right', state: true, shift: self.shift});
else if(event.keyCode === 65 || event.keyCode === 37) // a
- socket.emit('keyPress',{inputId: 'left', state: true});
+ socket.emit('keyPress',{inputId: 'left', state: true, shift: self.shift});
else if(event.keyCode === 83 || event.keyCode === 40) // s
- socket.emit('keyPress',{inputId: 'down', state: true});
+ socket.emit('keyPress',{inputId: 'down', state: true, shift: self.shift});
else if(event.keyCode === 87 || event.keyCode === 38) // w
- socket.emit('keyPress',{inputId: 'up', state: true});
+ socket.emit('keyPress',{inputId: 'up', state: true, shift: self.shift});
+ else if(event.keyCode === 88)
+ socket.emit('keyPress',{inputId: 'sit', state: !self.sit, shift: self.shift});
}
}
document.onkeyup = function(event){
+ // shift
+ if(event.keyCode === 16)
+ self.shift = false;
+ // movement
if(event.keyCode === 68 || event.keyCode === 39) // d
- socket.emit('keyPress',{inputId: 'right', state: false});
+ socket.emit('keyPress', {inputId: 'right', state: false, shift: self.shift});
else if(event.keyCode === 65 || event.keyCode === 37) // a
- socket.emit('keyPress',{inputId: 'left', state: false});
+ socket.emit('keyPress', {inputId: 'left', state: false, shift: self.shift});
else if(event.keyCode === 83 || event.keyCode === 40) // s
- socket.emit('keyPress',{inputId: 'down', state: false});
+ socket.emit('keyPress', {inputId: 'down', state: false, shift: self.shift});
else if(event.keyCode === 87 || event.keyCode === 38) // w
- socket.emit('keyPress',{inputId: 'up', state: false});
+ socket.emit('keyPress', {inputId: 'up', state: false, shift: self.shift});
}
document.onmousedown = function(event){