import { computed, reactive } from 'vue' import { RECIPROCAL, STAGE_WIDTH, STAGE_HEIGHT } from '../level/def' const player: Player = reactive({ x: Math.round((STAGE_WIDTH + 2) / 2), y: Math.round((STAGE_HEIGHT + 2) / 2), lastDir: 0, vx: 0, vy: 1, // always falling, because of gravity inventory: [], // not yet in use }) export default function usePlayer() { const dx = computed(() => player.vx * RECIPROCAL) const dy = computed(() => player.vy * RECIPROCAL) const direction = computed(() => (player.lastDir < 0 ? 'left' : 'right')) return { player, direction, dx, dy } }