Skip to content

Commit

Permalink
fix collision
Browse files Browse the repository at this point in the history
  • Loading branch information
da-in committed Mar 5, 2024
1 parent fb31c18 commit b0021f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
</template>
<script setup lang="ts">
import {RouterView} from 'vue-router'
import {onMounted} from 'vue'
import Layout from './components/Layout.vue'
onMounted(() => {
window.scrollTo(0, 1)
})
</script>
10 changes: 9 additions & 1 deletion src/hooks/use-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const usePlayer = (element: Ref<HTMLCanvasElement | undefined>) => {

Events.on(engine, 'collisionStart', (event) => {
event.pairs.forEach((collision) => {
console.log(collision.bodyA.label, collision.bodyB.label, '충돌:', collision.bodyA.id, collision.bodyB.id)
if (collision.bodyA.label === 'removed' || collision.bodyB.label === 'removed') {
return
}
if (collision.bodyA.label === 'line' || collision.bodyB.label === 'line') {
const circle = collision.bodyA.label === 'line' ? collision.bodyB.id : collision.bodyA.id
collisions.value.add(circle)
Expand All @@ -87,6 +91,9 @@ export const usePlayer = (element: Ref<HTMLCanvasElement | undefined>) => {
return
}

collision.bodyA.label = 'removed'
collision.bodyB.label = 'removed'

scoreRef.value = scoreRef.value + (blocks[index].score)

const newBlock = createBlock(index + 1, collision.collision.supports[0].x, collision.collision.supports[0].y, ratioRef.value)
Expand Down Expand Up @@ -119,7 +126,8 @@ export const usePlayer = (element: Ref<HTMLCanvasElement | undefined>) => {
})

const addBlock = () => {
currentBlockRef.value = createBlock(10, widthRef.value / 2, 80, ratioRef.value, true)
currentBlockRef.value = createBlock(2, widthRef.value / 2, 80, ratioRef.value, true)
// currentBlockRef.value = createBlock(nextBlockRef.value, widthRef.value / 2, 80, ratioRef.value, true)
isSetBlock.value = false
World.add(engine.world, currentBlockRef.value)
setNextBlock()
Expand Down

0 comments on commit b0021f1

Please sign in to comment.