Skip to content

Commit

Permalink
add door entity tracking to Sokoban
Browse files Browse the repository at this point in the history
  • Loading branch information
preaction committed Aug 18, 2024
1 parent fdd0458 commit 6311d47
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
24 changes: 18 additions & 6 deletions examples/Sokoban/scenes/NewScene.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},
{
"name": "Sokoban",
"data": {}
"data": {
"doorEntity": "Door (Closed)"
}
},
{
"name": "Physics",
Expand All @@ -37,12 +39,15 @@
"components": {
"Transform": {
"z": 2000,
"rw": 1,
"rw": "1",
"sx": 1,
"sy": 1,
"sz": 1,
"x": "",
"y": ".5"
"x": "0",
"y": ".5",
"rz": "0",
"ry": "0",
"rx": "0"
},
"OrthographicCamera": {
"frustum": 10,
Expand Down Expand Up @@ -562,7 +567,7 @@
"$schema": "1",
"name": "Door (Closed)",
"type": "Entity",
"active": false,
"active": true,
"components": {
"Transform": {
"x": 0,
Expand All @@ -585,7 +590,14 @@
"atlas": "images/[email protected]"
}
},
"BoxCollider": {},
"BoxCollider": {
"ox": 0,
"oy": 0,
"oz": 0,
"sx": 1,
"sy": 1,
"sz": 1
},
"RigidBody": {
"lx": 0,
"ly": 0,
Expand Down
16 changes: 13 additions & 3 deletions examples/Sokoban/systems/Sokoban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,27 @@ export default class Sokoban extends System {
// Set up event listeners
this.physics.watchEnterByQuery(this.crateQuery, this.crateEnter.bind(this));
this.physics.watchExitByQuery(this.crateQuery, this.crateLeave.bind(this));
this.physics.watchEnterByQuery(this.gridQuery, this.playerEnter.bind(this));
this.physics.watchExitByQuery(this.gridQuery, this.playerLeave.bind(this));

this.moveTo = new three.Vector3();
this.velocity = new three.Vector3();
}

crateEnter(crateEid: number, eids: Set<number>) {
console.log(`${crateEid}: Collides: ${Array.from(eids).join(', ')}`);
console.log(`${crateEid}: Crate collides: ${Array.from(eids).join(', ')}`);
}

crateLeave(crateEid: number, eids: Set<number>) {
console.log(`${crateEid}: Leaves: ${Array.from(eids).join(', ')}`);
console.log(`${crateEid}: Crate leaves: ${Array.from(eids).join(', ')}`);
}

playerEnter(playerEid: number, eids: Set<number>) {
console.log(`${playerEid}: Player collides: ${Array.from(eids).join(', ')}`);
}

playerLeave(playerEid: number, eids: Set<number>) {
console.log(`${playerEid}: Player leaves: ${Array.from(eids).join(', ')}`);
}

start() {
Expand Down Expand Up @@ -134,6 +144,6 @@ export default class Sokoban extends System {

static get editorComponent(): string {
// Path to the .vue component, if any
return '';
return './systems/Sokoban.vue';
}
}
24 changes: 24 additions & 0 deletions examples/Sokoban/systems/Sokoban.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
props: ['modelValue', 'scene'],
data() {
return {};
},
methods: {
update() {
this.$emit('update:modelValue', this.modelValue);
},
},
});
</script>
<template>
<div>
<div class="d-flex justify-content align-items-center">
<label class="me-1">Door</label>
<InputEntity name="doorEntity" v-model="modelValue.doorEntity" />
</div>
</div>
</template>
<style></style>

0 comments on commit 6311d47

Please sign in to comment.