game-village-politics-frontend/app/components/village/Animal.vue

43 lines
2.1 KiB
Vue

<script setup lang="ts">
const props = defineProps<{
kind: 'sheep' | 'chicken'
/** A small closed loop on screen it wanders along, stopping to graze or peck. */
d: string
dur: number
begin: number
size: number
}>()
// Four stretches of the loop, each followed by a stop.
const keyPoints = '0;0.25;0.25;0.5;0.5;0.75;0.75;1;1'
const keyTimes = '0;0.12;0.3;0.42;0.55;0.67;0.8;0.92;1'
const peck = computed(() => (props.kind === 'chicken' ? 0.7 : 2.2))
</script>
<!-- A sheep or a chicken: a few flat panels, head going down to graze or peck. -->
<template>
<g>
<g :transform="`scale(${size})`">
<template v-if="kind === 'sheep'">
<path d="M-1 -0.9h0.6V0h-0.6zM1.2 -0.9h0.6V0h-0.6z" fill="#3a2a1c" />
<path d="M-2.2 -3.4Q-2.4 -1 -0.6 -0.7H2Q3 -1.6 2.4 -3.4Q0.2 -4.6 -2.2 -3.4z" fill="#e8e1cf" />
<path d="M0.2 -0.7H2Q3 -1.6 2.4 -3.4Q1.4 -3.9 0.2 -3.9z" fill="#c9c1ad" />
<g>
<animateTransform attributeName="transform" type="rotate" :values="`0 2.2 -2.6;28 2.2 -2.6;28 2.2 -2.6;0 2.2 -2.6;0 2.2 -2.6`" keyTimes="0;0.15;0.6;0.75;1" :dur="`${peck}s`" :begin="`${begin}s`" repeatCount="indefinite" />
<path d="M2.1 -3.3L3.7 -3.1L3.6 -1.9L2.3 -2.1z" fill="#3a2a1c" />
</g>
</template>
<template v-else>
<path d="M-0.3 -0.8h0.3V0h-0.3zM0.4 -0.8h0.3V0h-0.3z" fill="#c49a2c" />
<path d="M-1.4 -2.6Q-1.2 -0.7 0.4 -0.8Q1.4 -1.2 1.2 -2.2Q0 -3.2 -1.4 -2.6z" fill="#f0e8d6" />
<g>
<animateTransform attributeName="transform" type="rotate" values="0 1 -2.2;40 1 -2.2;0 1 -2.2;0 1 -2.2" keyTimes="0;0.2;0.4;1" :dur="`${peck}s`" :begin="`${begin}s`" repeatCount="indefinite" />
<path d="M0.8 -3.4L1.7 -3.2L1.6 -2.2L0.9 -2.3z" fill="#f0e8d6" />
<path d="M1.7 -3L2.3 -2.7L1.7 -2.5z" fill="#c49a2c" />
<path d="M0.9 -3.6L1.4 -3.9L1.4 -3.3z" fill="#9b2a1c" />
</g>
</template>
</g>
<animateMotion :dur="`${dur}s`" :begin="`${begin}s`" repeatCount="indefinite" calcMode="linear" :keyPoints="keyPoints" :keyTimes="keyTimes" :path="d" />
</g>
</template>