From d917286669e87d120ee0a1de99bf8a6f5a05f4bd Mon Sep 17 00:00:00 2001 From: koehr Date: Mon, 23 Apr 2018 00:35:47 +0200 Subject: [PATCH] player --- src/Field.vue | 50 +++++++++++++++++++++++++++++----- src/assets/dwarf.png | Bin 0 -> 1102 bytes src/level/def.js | 19 +++++++------ src/level/first-iteration.js | 9 +++--- src/level/index.js | 25 ++++++++--------- src/level/second-iteration.js | 4 +-- src/level/third-iteration.js | 17 ++++++++++++ 7 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 src/assets/dwarf.png diff --git a/src/Field.vue b/src/Field.vue index 06b5b7a..85fa318 100644 --- a/src/Field.vue +++ b/src/Field.vue @@ -3,11 +3,12 @@ +
x:{{ x }}, y:{{ y }}
@@ -24,12 +25,17 @@ export default { data () { return { x: 0, - y: 0 + y: 0, + player_x: 0, + player_y: 0 } }, + mounted () { + this.findStartPos() + }, computed: { rows () { - return level.grid(this.x, this.y) + return level.grid(this.x, this.y, this.player_x, this.player_y) } }, methods: { @@ -41,6 +47,26 @@ export default { if (ev.shiftKey) this.y -= 32 else this.y-- this.y = Math.max(0, this.y) + }, + goRight (ev) { + if (ev.shiftKey) this.x += 32 + else this.x++ + }, + goLeft (ev) { + if (ev.shiftKey) this.x -= 32 + else this.x-- + }, + findStartPos () { + const x = parseInt(WIDTH / 2) + + for (let y = HEIGHT - 1; y; y--) { + const block = this.rows[y][x] + if (block.walkable) { + this.player_x = x + this.player_y = y + break + } + } } } } @@ -48,12 +74,11 @@ export default {