Skip to content

Commit

Permalink
fix block size
Browse files Browse the repository at this point in the history
  • Loading branch information
da-in committed Jan 1, 2024
1 parent 8a901a1 commit da666f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/pages/play/PlayPage.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<template>
<div class="absolute z-10">
<span>score: {{score}}</span>
<div class="bg-amber-300">Next</div>
</div>
<div ref="canvas" class=""></div>
</template>
<script setup lang="ts">
import {Engine, Render, Bodies, Composite, World, Runner, Events} from 'matter-js'
import {onMounted, ref} from "vue";
import {blocks} from "./setting.ts";
const score = ref(0)
const canvas = ref<HTMLElement>()
const engine = Engine.create({gravity: {x:0, y:1}})
Expand Down Expand Up @@ -54,7 +61,9 @@ onMounted(()=>{
const index = Number(collision.bodyA.label)
const nextIndex = String(index + 1)
// 최고 단계일 경우
score.value = score.value + (index * 10)
// todo 최고 단계일 경우 처리
if (index === 10) {
return
}
Expand All @@ -77,11 +86,13 @@ onMounted(()=>{
})
const addBlock = (x: number) => {
const index = Math.floor(Math.random() * 5)
const index = Math.floor(Math.random() * 5) + 1 // 1 ~ 5
if(!index){
return
}
const circle = Bodies.circle(x, 10, index * 20, {
const block = blocks[index]
console.log(index)
const circle = Bodies.circle(x, 10, block.size/2, {
label: String(index),
})
World.add(engine.world, circle)
Expand Down
18 changes: 18 additions & 0 deletions src/pages/play/setting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type Block = {
size: number;
};

const score = [3, 5, 7, 10, 15, 20, 25, 30, 40, 50, 100]

Check failure on line 5 in src/pages/play/setting.ts

View workflow job for this annotation

GitHub Actions / cache-and-install

'score' is declared but its value is never read.

export const blocks: { [key: number]: Block } = {
1: { size: 75 },
2: { size: 98 },
3: { size: 137 },
4: { size: 180 },
5: { size: 200 },
6: { size: 240 },
7: { size: 280 },
8: { size: 320 },
9: { size: 320 },
10: { size: 400 },
};

0 comments on commit da666f4

Please sign in to comment.