Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maximesflowers committed Oct 22, 2022
2 parents 366dca1 + 5ded22e commit 7ff312f
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 5 deletions.
1 change: 1 addition & 0 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
</script>

<template>
Expand Down
7 changes: 6 additions & 1 deletion assets/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ button {
button,
select {
cursor: pointer;
}
}


.limit {
/*@apply */
}
11 changes: 11 additions & 0 deletions classes/Level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {reactive} from "#imports";

export class Level {
obstacles = new Set<number>()

constructor(props:Level) {
const proxy = reactive(this)
Object.assign(proxy, props)
return proxy
}
}
39 changes: 39 additions & 0 deletions classes/Robot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {reactive} from "#imports"
import {Level} from "~/classes/Level"

export class Robot {
name = ""
color = ""

_x = 0
_y = 0

_level: Level

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
}

// move
this._x++

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

jump() {
this._y++
}
}
12 changes: 12 additions & 0 deletions components/Controller.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts" setup>
</script>
<template>
<div class="w-full bg-gray-200 h-20 flex justify-between p-6">
<button>
Play
</button>
<button>
?
</button>
</div>
</template>
18 changes: 18 additions & 0 deletions components/GameView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts" setup>
import {Robot} from "~/classes/Robot";
defineProps<{
Robo?: Robot,
}>()
</script>
<template>
<div class="grid w-full h-full bg-green-200"
style="grid-template-columns: repeat(24, minmax(0, 1fr));
grid-template-rows: repeat(24, minmax(0, 1fr));">
<div>Test</div>
<div>Test</div>
<div>Test</div>
<div>Test</div>
<div>Test</div>
</div>
</template>
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineNuxtConfig({
global: false,
dirs: [],
},
ssr: false,
telemetry: false,
modules: ["@nuxtjs/tailwindcss"],
experimental: {
Expand Down
10 changes: 10 additions & 0 deletions pages/chapter/console/1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts" setup>
import GameView from "~/components/GameView.vue";
import Controller from "~/components/Controller.vue"
</script>
<template>
<div class="flex flex-col aspect-square">
<GameView class="flex-grow"/>
<Controller class="fixed bottom-0"/>
</div>
</template>
18 changes: 15 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<script setup lang="ts">
import {onMounted} from "#imports"
import {Robot} from "~/classes/Robot"
import {Level} from "~/classes/Level"
import Counter from "~/components/Counter.vue"
const level = new Level({obstacles: new Set([2, 4, 8])})
const Robo = new Robot({level})
import Counter from "~/components/Counter.vue";
</script>

<template>
<main>
<h1>Robo</h1>
<Counter/>
<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>
1 change: 0 additions & 1 deletion services/Robo.ts

This file was deleted.

0 comments on commit 7ff312f

Please sign in to comment.