diff --git a/public/characterSprites/Blue/Down.png b/public/characterSprites/Blue/Down.png new file mode 100644 index 0000000..f3abeaf Binary files /dev/null and b/public/characterSprites/Blue/Down.png differ diff --git a/public/characterSprites/Blue/Left.png b/public/characterSprites/Blue/Left.png new file mode 100644 index 0000000..f3abeaf Binary files /dev/null and b/public/characterSprites/Blue/Left.png differ diff --git a/public/characterSprites/Blue/Right.png b/public/characterSprites/Blue/Right.png new file mode 100644 index 0000000..cedb27f Binary files /dev/null and b/public/characterSprites/Blue/Right.png differ diff --git a/public/characterSprites/Blue/Up.png b/public/characterSprites/Blue/Up.png new file mode 100644 index 0000000..cedb27f Binary files /dev/null and b/public/characterSprites/Blue/Up.png differ diff --git a/public/characterSprites/Orange/Down.png b/public/characterSprites/Orange/Down.png new file mode 100644 index 0000000..19fa928 Binary files /dev/null and b/public/characterSprites/Orange/Down.png differ diff --git a/public/characterSprites/Orange/Left.png b/public/characterSprites/Orange/Left.png new file mode 100644 index 0000000..7af9a41 Binary files /dev/null and b/public/characterSprites/Orange/Left.png differ diff --git a/public/characterSprites/Orange/Right.png b/public/characterSprites/Orange/Right.png new file mode 100644 index 0000000..19fa928 Binary files /dev/null and b/public/characterSprites/Orange/Right.png differ diff --git a/public/characterSprites/Orange/Up.png b/public/characterSprites/Orange/Up.png new file mode 100644 index 0000000..7af9a41 Binary files /dev/null and b/public/characterSprites/Orange/Up.png differ diff --git a/public/classes/Player.js b/public/classes/Player.js index f920bdf..5743a8b 100644 --- a/public/classes/Player.js +++ b/public/classes/Player.js @@ -1,6 +1,6 @@ class Player extends Sprite { - constructor({position,clickX,clickY,incrementX,incrementY,userId,username,skin,message,atPosition,animationColumn,imageSrc,frames,center,sprites}){ + constructor({position,clickX,clickY,incrementX,incrementY,userId,username,skin,message,atPosition,isCharacter2D,animationColumn,imageSrc,frames,center,sprites}){ super({position,imageSrc,frames,center,atPosition,sprites,skin}) // super({imageSrc}) this.clickX = clickX @@ -10,6 +10,7 @@ class Player extends Sprite { this.incrementY = incrementY this.userId = userId this.username = username + this.isCharacter2D = isCharacter2D this.message = message this.messageSent = false @@ -82,10 +83,18 @@ class Player extends Sprite { this.atPosition=false + if(this.isCharacter2D){ + // console.log(this.angleDeg) + if(90
  • Click anywhere in the box to move
  • Write /name followed by your name in the text box to change your name
  • +
  • You can change your character with /dino followed by 1,2,3,4 eg. /dino 2
  • Use the textbox to chat and the emoji button to send emojis
  • Be nice & Have fun!
  • Dino sprites by @ScissorMarks
    diff --git a/public/index.js b/public/index.js index 2191dbc..ac1bcb3 100644 --- a/public/index.js +++ b/public/index.js @@ -81,18 +81,15 @@ socket.on('updatePlayers', (bPlayers) =>{ skin:bPlayer.skin, message:'', atPosition:true, + isCharacter2D:true, animationColumn:0, imageSrc:'characterSprites/' + bPlayer.skin + '/Down.png', frames: 7, center:true, - sprites:{ - down:'characterSprites/' + bPlayer.skin + '/Down.png', - up:'characterSprites/' + bPlayer.skin + '/Up.png', - right:'characterSprites/' + bPlayer.skin + '/Right.png', - left:'characterSprites/' + bPlayer.skin + '/Left.png' - } + sprites:spriteFunction(bPlayer.skin) }) + // console.log(fPlayers[id]) fPlayers[socket.id].username = localStorage.getItem('username') socket.emit('username',fPlayers[socket.id].username); @@ -102,7 +99,9 @@ socket.on('updatePlayers', (bPlayers) =>{ fPlayers[id].clickY = bPlayer.clickY fPlayers[id].message = bPlayer.message fPlayers[id].username = bPlayer.username - fPlayers[id].skin = bPlayer.skin + spriteFunctionUpdate(fPlayers[id],bPlayer.skin) + // fPlayers[id].sprites = spriteFunction(bPlayer.skin) + // console.log(fPlayers[id]) //update player position without animation if tab is inactive if (document.hidden) { @@ -207,8 +206,24 @@ document.querySelector('#textInput').addEventListener('submit',(event)=>{ }else if(inputValue==='/debug'){ if(debugMode) {debugMode=false;}else{debugMode=true;} - }else if(inputValue==='/red'){ - fPlayers[socket.id].skin = "Red"; + }else if(inputValue.includes("/dino ")){ + console.log(inputValue.slice(6,7)); + switch(inputValue.slice(6,7)) { + case '1': + fPlayers[socket.id].skin = "Green"; + break; + case '2': + fPlayers[socket.id].skin = "Red"; + break; + case '3': + fPlayers[socket.id].skin = "Orange"; + break; + case '4': + fPlayers[socket.id].skin = "Blue"; + break; + default: + fPlayers[socket.id].skin = "Green"; + } socket.emit('skin',fPlayers[socket.id].skin); }else{ fPlayers[socket.id].message=document.querySelector('#input').value @@ -218,4 +233,22 @@ document.querySelector('#textInput').addEventListener('submit',(event)=>{ fPlayers[socket.id].messageSent = true; } document.querySelector('#textInput').reset(); -}) \ No newline at end of file +}) + +function spriteFunction(skin) { + return { + down:'characterSprites/' + skin + '/Down.png', + up:'characterSprites/' + skin + '/Up.png', + right:'characterSprites/' + skin + '/Right.png', + left:'characterSprites/' + skin + '/Left.png' + }; + } + + function spriteFunctionUpdate(obj,skin) { + + obj.Down.src='characterSprites/' + skin + '/Down.png'; + obj.Up.src='characterSprites/' + skin + '/Up.png'; + obj.Left.src='characterSprites/' + skin + '/Left.png'; + obj.Right.src='characterSprites/' + skin + '/Right.png'; + + } \ No newline at end of file