Skip to content

Commit

Permalink
game over modal
Browse files Browse the repository at this point in the history
  • Loading branch information
da-in committed Jan 3, 2024
1 parent 672aef6 commit 5fa17ad
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Binary file added src/assets/end-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/end-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions src/pages/play/PlayPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
<next-block :next-index="nextBlockRef"/>
</div>
<div ref="canvas" class=""></div>
<game-over v-if="gameOverRef" :score="scoreRef" @replay="onReplay"/>
</template>
<script setup lang="ts">
import {Engine, Render, Bodies, Composite, World, Runner, Events} from 'matter-js'
import {onMounted, ref} from "vue";
import {createBlock} from "../../utils";
import NextBlock from "./_components/NextBlock.vue";
import GameOver from "./_components/GameOver.vue";
const scoreRef = ref(0)
const isDroppingRef = ref(false)
const nextBlockRef = ref(0)
const gameOverRef = ref(false)
const canvas = ref<HTMLElement>()
const engine = Engine.create({gravity: {x:0, y:1}})
Expand All @@ -38,7 +41,7 @@ onMounted(()=>{
}
});
const ground = Bodies.rectangle(width/2, height-60, width, 120, { isStatic: true, render: {fillStyle: '#FCBF31', lineWidth:4, strokeStyle:'#000000'}});
const ground = Bodies.rectangle(width/2, height-48, width, 96, { isStatic: true, render: {fillStyle: '#FCBF31', lineWidth:4, strokeStyle:'#000000'}});
const left = Bodies.rectangle(0, height/2, 1, height, {
isStatic: true,
render: {fillStyle: '#FFFFFF'}
Expand All @@ -64,7 +67,7 @@ onMounted(()=>{
if(isDroppingRef.value){
return
}
alert('gameover')
gameOverRef.value=true
}
if (collision.bodyA.label !== collision.bodyB.label) {
return
Expand All @@ -85,7 +88,6 @@ onMounted(()=>{
})
const addBlock = (x: number) => {
console.log(nextBlockRef.value)
if(!nextBlockRef.value){
return
}
Expand All @@ -100,6 +102,11 @@ const setNextBlock = () => {
nextBlockRef.value = Math.floor(Math.random() * 5) + 1 // 1 ~ 5
}
const onReplay = () => {
// todo : 새로고침 성능 확인
location.reload()
}
window.addEventListener('click', (event)=>{
if(isDroppingRef.value){
return
Expand Down
21 changes: 21 additions & 0 deletions src/pages/play/_components/GameOver.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div class="fixed inset-0 flex items-center justify-center z-50">
<div class="flex flex-col gap-10 w-[300px] h-[675px] justify-center items-center bg-white text-4xl rounded-3xl border-2 border-black">
<img :src="endText" alt="" width="75"/>
<img :src="endImage" alt="덕 같이 멸망" width="253"/>
<span>score: {{ score }}</span>
<button @click="$emit('replay')" class="bg-[#FCBF31] rounded-full border-2 border-black px-6">또 해야되네</button>
</div>
</div>
</template>
<script setup lang="ts">
import endImage from '../../../assets/end-image.png'
import endText from '../../../assets/end-text.png'
defineProps({
score: {
type: Number,
default: 0
}
})
</script>
2 changes: 1 addition & 1 deletion src/pages/play/_components/NextBlock.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="flex items-center bg-[#FCBF31] rounded-full w-36 pl-10 -ml-6 border-2 border-black">
<div class="flex justify-center items-center bg-[#FCBF31] rounded-r-full w-28 border-2 border-l-0 border-black">
<span class="text-4xl mr-3" >Next</span>
<div :style="{background: block?.color}" class="w-[26px] h-[26px] rounded-full border-2 border-black"></div>
</div>
Expand Down

0 comments on commit 5fa17ad

Please sign in to comment.