Skip to content

Commit

Permalink
robot climb method
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Jaeger authored and Simon Jaeger committed Oct 22, 2022
1 parent 841fac8 commit 5d12267
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
20 changes: 12 additions & 8 deletions classes/Robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class Robot {
color = ""

_x = 0
_y = 0
_y: 0 | 1 = 0

_level: Level

Expand All @@ -19,22 +19,26 @@ export class Robot {

move() {
// check for obstacle
if (!(this._y > 0) && this._level.obstacles.has(this._x + 1)) {
if (this._y === 0 && this._level.obstacles.has(this._x + 1)) {
console.log("cannot move, obstacle in the way")
return
}

// move
this._x++

// land if possible
if ((this._y > 0) && !this._level.obstacles.has(this._x)) {
this._y--
// fall if possible
if ((this._y === 1) && !this._level.obstacles.has(this._x)) {
this._y = 0
}
}

jump() {
// TODO: climb? up right? prevent jump spam and gliding right over whole level
this._y++
climb() {
// check for obstacle
if (this._y === 0 && this._level.obstacles.has(this._x + 1)) {
this._y = 1
} else {
console.log("cannot climb, nothing to climb on")
}
}
}
22 changes: 8 additions & 14 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@

<template>
<main>
<GameView :robo="robo"/>
<!-- <ul>-->
<!-- <li v-for="obst of Robo._level.obstacles">x</li>-->
<!-- </ul>-->
<!-- <h1 class="font-mono">pixel</h1>-->
<!-- <h2>normal</h2>-->
<!-- <pre>{{ JSON.stringify(Robo, null, 2) }}</pre>-->
<!-- <pre>obstacles: {{ [...level.obstacles].join(",") }}</pre>-->
<!-- <div class="w-96 h-32 bg-black relative">-->
<!-- <div-->
<!-- class="w-8 h-8 bg-gray-500 absolute"-->
<!-- :style="{left: (Robo._x * 32)+'px', bottom: (Robo._y * 32)+'px'}"-->
<!-- ></div>-->
<!-- </div>-->
<pre>{{ JSON.stringify(robo, null, 2) }}</pre>
<pre>obstacles: {{ [...level.obstacles].join(",") }}</pre>
<div class="w-96 h-32 bg-black relative">
<div
class="w-8 h-8 bg-gray-500 absolute"
:style="{left: (robo._x * 32)+'px', bottom: (robo._y * 32)+'px'}"
></div>
</div>
</main>
</template>

0 comments on commit 5d12267

Please sign in to comment.