summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjak1 <mike.wollmann@gmail.com>2021-08-02 00:12:08 +0200
committerjak1 <mike.wollmann@gmail.com>2021-08-02 00:12:08 +0200
commit6c6918bc386b9b085ebc070826294c755aff1f8a (patch)
treee27217ff431a64c69919efbd0b22e0af7f37024b
parent74a41caff6e7274c6926f5ae26b4180c920bb3dc (diff)
downloadthepixelworld-6c6918bc386b9b085ebc070826294c755aff1f8a.tar.gz
thepixelworld-6c6918bc386b9b085ebc070826294c755aff1f8a.tar.bz2
thepixelworld-6c6918bc386b9b085ebc070826294c755aff1f8a.tar.xz
thepixelworld-6c6918bc386b9b085ebc070826294c755aff1f8a.zip
removed const directions (seems to bug a bit (or there is maybe a better way doing that *shrugs*)
fixed some formating
-rw-r--r--client/consts.js9
-rw-r--r--client/index.html7
-rw-r--r--server/Entities/Bullet.js20
-rw-r--r--server/Entities/Entity.js1
-rw-r--r--server/Entities/Player.js53
5 files changed, 44 insertions, 46 deletions
diff --git a/client/consts.js b/client/consts.js
index 242857d..b7df81d 100644
--- a/client/consts.js
+++ b/client/consts.js
@@ -3,14 +3,5 @@ const WIDTH = 500;
const HEIGHT = 500;
-// directions
-const DIR_DOWN = 0;
-const DIR_LEFT = 1;
-const DIR_UP = 2;
-const DIR_RIGHT = 4;
-
-
-
-
// error codes
const CONNECTION_LOST = 10001; \ No newline at end of file
diff --git a/client/index.html b/client/index.html
index 797628f..eb88280 100644
--- a/client/index.html
+++ b/client/index.html
@@ -202,7 +202,7 @@
self.hp = initPack.hp;
self.hpMax = initPack.hpMax;
self.score = initPack.score;
- self.dir = DIR_DOWN;
+ self.dir = initPack.dir;
self.drawPlayer = function(){
var x = self.x - Player.list[selfId].x + WIDTH/2;
@@ -244,6 +244,7 @@
self.x = initPack.x;
self.y = initPack.y;
self.map = initPack.map;
+ self.dir = initPack.dir;
self.draw = function(){
var width = Img.bullet.width;
@@ -308,6 +309,8 @@
b.x = pack.x;
if(pack.y !== undefined)
b.y = pack.y;
+ if(pack.dir !== undefined)
+ b.dir = pack.dir;
}
}
});
@@ -353,7 +356,7 @@
tmxmap.drawLayer("ground",x,y);
}
-
+
var drawPlayerNames = function(){
for(var i in Player.list){
Player.list[i].drawPlayerName();
diff --git a/server/Entities/Bullet.js b/server/Entities/Bullet.js
index cb5a1a4..5b93a45 100644
--- a/server/Entities/Bullet.js
+++ b/server/Entities/Bullet.js
@@ -6,9 +6,11 @@ var Bullet = function(parent, angle) {
self.id = Math.random();
self.speedX = Math.cos(angle/180*Math.PI) *10;
self.speedY = Math.sin(angle/180*Math.PI) *10;
+ self.dir = 0;
self.parent = parent;
self.timer = 0;
self.toRemove = false;
+
var super_update = self.update;
self.update = function(){
if (self.timer++ > 100)
@@ -34,19 +36,21 @@ var Bullet = function(parent, angle) {
self.getInitPack = function() {
return {
- id:self.id,
- x:self.x,
- y:self.y,
- map:self.map,
+ id: self.id,
+ x: self.x,
+ y: self.y,
+ map: self.map,
+ dir: self.dir,
};
}
self.getUpdatePack = function() {
return {
- id:self.id,
- x:self.x,
- y:self.y,
- map:self.map,
+ id: self.id,
+ x: self.x,
+ y: self.y,
+ map: self.map,
+ dir: self.dir,
};
}
diff --git a/server/Entities/Entity.js b/server/Entities/Entity.js
index 99d8c0b..d65492d 100644
--- a/server/Entities/Entity.js
+++ b/server/Entities/Entity.js
@@ -10,7 +10,6 @@ var Entity = function(){
speedX: 0,
speedY: 0,
id: "",
- dir: 0
}
self.update = function(){
self.updatePosition();
diff --git a/server/Entities/Player.js b/server/Entities/Player.js
index 6bc0e65..8286355 100644
--- a/server/Entities/Player.js
+++ b/server/Entities/Player.js
@@ -16,6 +16,7 @@ var Player = function(id){
self.mouseAngle = 0;
self.maxSpeed = 10;
self.hp = 10;
+ self.dir = 0;
self.hpMax = 10;
self.score = 0;
@@ -37,22 +38,22 @@ var Player = function(id){
self.updateSpeed = function(){
if(self.pressingRight){
self.speedX = self.maxSpeed;
- self.dir = consts.DIR_RIGHT;
+ self.dir = 4;
}
else if(self.pressingLeft){
self.speedX = -self.maxSpeed;
- self.dir = consts.DIR_LEFT;
+ self.dir = 1;
}
else
self.speedX = 0;
if(self.pressingUp){
self.speedY = -self.maxSpeed;
- self.dir = consts.DIR_UP;
+ self.dir = 2;
}
else if(self.pressingDown){
self.speedY = self.maxSpeed;
- self.dir = consts.DIR_DOWN;
+ self.dir = 0;
}
else
self.speedY = 0;
@@ -60,28 +61,28 @@ var Player = function(id){
self.getInitPack = function() {
return {
- id:self.id,
- playerName:self.playerName,
- x:self.x,
- y:self.y,
- map:self.map,
- number:self.number,
- hp:self.hp,
- hpMax:self.hpMax,
- score:self.score,
- dir:self.dir,
+ id: self.id,
+ playerName: self.playerName,
+ x: self.x,
+ y: self.y,
+ map: self.map,
+ number: self.number,
+ hp: self.hp,
+ hpMax: self.hpMax,
+ score: self.score,
+ dir: self.dir,
};
}
self.getUpdatePack = function() {
return {
- id:self.id,
- playerName:self.playerName,
- x:self.x,
- y:self.y,
- map:self.map,
- score:self.score,
- hp:self.hp,
- dir:self.dir,
+ id: self.id,
+ playerName: self.playerName,
+ x: self.x,
+ y: self.y,
+ map: self.map,
+ score: self.score,
+ hp: self.hp,
+ dir: self.dir,
};
}
Player.list[id] = self;
@@ -99,19 +100,19 @@ Player.onConnect = function(socket, pName){
socket.on('keyPress', function(data){
if (data.inputId === 'left'){
player.pressingLeft = data.state;
- player.dir = consts.DIR_LEFT;
+ player.dir = 1;
}
else if (data.inputId === 'right'){
player.pressingRight = data.state;
- player.dir = consts.DIR_RIGHT;
+ player.dir = 4;
}
else if (data.inputId === 'up'){
player.pressingUp = data.state;
- player.dir = consts.DIR_UP;
+ player.dir = 2;
}
else if (data.inputId === 'down'){
player.pressingDown = data.state;
- player.dir = consts.DIR_DOWN;
+ player.dir = 0;
}
else if (data.inputId === 'attack'){
player.pressingAttack = data.state;