diff --git a/src/App.vue b/src/App.vue index 2dd47d8..3496ffe 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,12 +9,16 @@ import createLevel from './level' import useTime from './util/useTime' import useInput from './util/useInput' import usePlayer from './util/usePlayer' +import useLightMap from './util/useLightMap' -const { updateTime, timeOfDay, clock } = useTime() +const { updateTime, time, clock } = useTime() const { player, direction, dx, dy } = usePlayer() const { inputX, inputY, running, paused, help, inventory } = useInput() const level = createLevel(STAGE_WIDTH + 2, STAGE_HEIGHT + 2) +const lightMapEl = ref(undefined) +let lightMap: ReturnType + player.inventory.push( { name: 'Shovel', type: 'tool', icon: 'shovel', quality: 'bronze', amount: 1 }, { name: 'Sword', type: 'weapon', icon: 'sword', quality: 'bronze', amount: 2 }, @@ -67,19 +71,18 @@ const blocked = computed(() => { } }) +// TODO +const damagedBlocks = ref([]) + function dig(blockX: number, blockY: number, oldBlockType: BlockType) { // ยง 4 ArbZG if (paused.value) return // TODO: temporary filter if (oldBlockType === 'air' || oldBlockType === 'cave') return + // when we finally dig that block + level.change({ type: 'exchange', x: floorX.value + blockX, y: floorY.value + blockY, newType: 'air' }) - level.change({ - type: 'exchange', - x: floorX.value + blockX, - y: floorY.value + blockY, - newType: 'air' - }) // This feels like cheating, but it makes Vue recalculate floorX // which then recalculates the blocks, so that the changes are // applied. Otherwise, they wouldn't be visible before moving @@ -133,39 +136,54 @@ const move = (thisTick: number): void => { walking.value = !!dx_ - x.value += dx_ * movementMultiplier + if (dy_ <= 0) x.value += dx_ * movementMultiplier if (dy_ < 0 || arriving.value) { y.value += dy_ * movementMultiplier } else { y.value += dy_ * fallMultiplier } + + lightMap.draw(floorX.value, floorY.value, tx.value, ty.value, time.value) lastTick = thisTick } function calcBrightness(level: number, row: number) { const barrier = lightBarrier.value[row] + const barrierLeft = lightBarrier.value[row - 1] + const barrierRight = lightBarrier.value[row + 1] + let delta = barrier - level - (floorY.value - 3) + const deltaL = Math.min(3, barrierLeft - level - (floorY.value - 3)) + const deltaR = Math.min(3, barrierRight - level - (floorY.value - 3)) if (delta > 3) delta = 3 else if (delta < 0) delta = 0 + if (deltaR > delta || deltaL > delta) delta = Math.max(deltaL, deltaR) - 1 + return `sun-${delta}` } onMounted(() => { + const canvas = lightMapEl.value! + canvas.height = (BLOCK_SIZE + 2) * STAGE_HEIGHT + canvas.width = (BLOCK_SIZE + 2) * STAGE_WIDTH + const ctx = canvas.getContext('2d')! + + lightMap = useLightMap(ctx) lastTick = performance.now() move(lastTick) })