From dffb1ce516b0a93b30c8940cc8abb4a3af004c8d Mon Sep 17 00:00:00 2001 From: Fabian Thome <42369664+Feburrrito@users.noreply.github.com> Date: Thu, 17 Jun 2021 17:23:53 +0200 Subject: [PATCH] player movement --- Webservice/Player.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Webservice/Player.js b/Webservice/Player.js index 1de9a1b..a25899f 100644 --- a/Webservice/Player.js +++ b/Webservice/Player.js @@ -1,16 +1,35 @@ class Player { - constructor(socketUsername) { + curr_field = 0 ; + coord_x = 0; + coord_y = 0; + + constructor(socketUsername, sprites) { this.socketUsername = socketUsername; - this.position = 0; + this.sprites = sprites; this.isAlive = true; + this.coord_x = sprites[0].getX(); + this.coord_y = sprites[0].getY(); + this.curr_field = 0; } + getX(){ + return this.coord_x; + } + + getY(){ + return this.coord_y; + } + + move(amount) { - this.position += amount; + this.curr_field += amount; + this.coord_x = this.sprites[this.curr_field].getX(); + this.coord_y = this.sprites[this.curr_field].getY(); if (this.position === 15) { // todo: win } } + } -module.exports = Player; \ No newline at end of file +module.exports = Player;