From eda8819614501745eb9e028c5ca317eafc607c87 Mon Sep 17 00:00:00 2001 From: Raphael Carrara de Lima Date: Thu, 11 Nov 2021 22:53:31 +0000 Subject: [PATCH 1/2] Primeira subida --- playground/Arapha/client.html | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 playground/Arapha/client.html diff --git a/playground/Arapha/client.html b/playground/Arapha/client.html new file mode 100644 index 00000000..645889bc --- /dev/null +++ b/playground/Arapha/client.html @@ -0,0 +1,60 @@ + + + Meu primeiro jogo multiplayer + + + + + + + + \ No newline at end of file From 05ef3e2a037387825ff69fda7b9279c5a0e90336 Mon Sep 17 00:00:00 2001 From: Raphael Carrara de Lima Date: Fri, 12 Nov 2021 00:50:54 +0000 Subject: [PATCH 2/2] Segundo commit --- playground/Arapha/client.html | 47 ++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/playground/Arapha/client.html b/playground/Arapha/client.html index 645889bc..6d40f208 100644 --- a/playground/Arapha/client.html +++ b/playground/Arapha/client.html @@ -20,7 +20,8 @@ const screen = document.getElementById("screen") const context = screen.getContext("2d") - + const currentPlayerId = 'player1' + const game = { players: { 'player1': {x:1, y:1}, @@ -30,21 +31,59 @@ 'fruit1': {x:3, y:1} } } + + function createGame() { + function movePlayer(comand) { + console.log(`movendo ${comand.playerId} com ${comand.keyPressed}`) + } + return { + movePlayer + } + } + + document.addEventListener('keydown', handlekeydown) + + function handlekeydown (event) { + + const keyPressed = event.key + const player = game.players[currentPlayerId] + + if (keyPressed === 'ArrowUp' && player.y - 1 >= 0) { + player.y = player.y - 1 + return + } + + if (keyPressed === 'ArrowRight' && player.x + 1 < screen.width) { + player.x = player.x + 1 + return + } + + if (keyPressed === 'ArrowDown' && player.y + 1 < screen.height) { + player.y = player.y + 1 + return + } + + if (keyPressed === 'ArrowLeft' && player.x - 1 >= 0) { + player.x = player.x - 1 + return + } + + } renderScreen() function renderScreen() { context.fillStyle = 'white' - context.fillRect (0, 0, 10, 10) + context.clearRect (0, 0, 10, 10) - for (playerId in game.players) { + for (const playerId in game.players) { const player = game.players [playerId] context.fillStyle = 'black' context.fillRect (player.x, player.y, 1, 1) } - for (fruitId in game.fruits) { + for (const fruitId in game.fruits) { const fruit = game.fruits [fruitId] context.fillStyle = 'green' context.fillRect (fruit.x, fruit.y, 1, 1)