-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collision detection; falling after jump
- Loading branch information
Simon Jaeger
authored and
Simon Jaeger
committed
Oct 22, 2022
1 parent
cca4471
commit 6c55357
Showing
2 changed files
with
42 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
import {reactive} from "#imports"; | ||
import {reactive} from "#imports" | ||
import {Level} from "~/classes/Level" | ||
|
||
export class Robot { | ||
name='' | ||
color='' | ||
name = "" | ||
color = "" | ||
|
||
_x = 0 | ||
_y = 0 | ||
_x = 0 | ||
_y = 0 | ||
|
||
constructor() { | ||
const proxy = reactive(this) | ||
window.Robo = proxy | ||
return proxy | ||
} | ||
_level: Level | ||
|
||
move() { | ||
// TODO: do not increment if blocked | ||
// TODO: land if not blocked below | ||
this._x++ | ||
constructor(config: { level: Level }) { | ||
this._level = config.level | ||
const proxy = reactive(this) | ||
window.Robo = proxy | ||
return proxy | ||
} | ||
|
||
move() { | ||
// check for obstacle | ||
if (!(this._y > 0) && this._level.obstacles.has(this._x + 1)) { | ||
console.log("cannot move, obstacle in the way") | ||
return | ||
} | ||
|
||
jump() { | ||
this._y++ | ||
// move | ||
this._x++ | ||
|
||
// land if possible | ||
if ((this._y > 0) && !this._level.obstacles.has(this._x)) { | ||
this._y-- | ||
} | ||
} | ||
} | ||
|
||
jump() { | ||
this._y++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
<script setup lang="ts"> | ||
import {onMounted} from "#imports"; | ||
import {Robot} from "~/classes/Robot"; | ||
import {Level} from "~/classes/Level"; | ||
import {onMounted} from "#imports" | ||
import {Robot} from "~/classes/Robot" | ||
import {Level} from "~/classes/Level" | ||
import Counter from "~/components/Counter.vue" | ||
const Robo = new Robot() | ||
const level = new Level({obstacles: new Set([2,4,8])}) | ||
console.log(level) | ||
const level = new Level({obstacles: new Set([2, 4, 8])}) | ||
const Robo = new Robot({level}) | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<pre>{{ JSON.stringify(Robo, null, 2)}}</pre> | ||
<pre>obstacles: {{ [...level.obstacles].join(',') }}</pre> | ||
<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'}"></div> | ||
<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> |