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 @@
0 ? x - 1 : 0"
+ @keydown.right="goRight($event)"
+ @keydown.left="goLeft($event)"
/>
+
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 {