data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add physics to it so you can throw the pet

dusk 1cf96f41 7ca4121d

+63 -3
+1 -1
src/app.html
··· 6 6 <meta name="viewport" content="width=device-width, initial-scale=1" /> 7 7 %sveltekit.head% 8 8 </head> 9 - <body data-sveltekit-preload-data="hover"> 9 + <body style="overflow: hidden" data-sveltekit-preload-data="hover"> 10 10 <div style="display: contents">%sveltekit.body%</div> 11 11 </body> 12 12 </html>
+62 -2
src/components/pet.svelte
··· 1 1 <script lang="ts"> 2 2 import { draggable } from '@neodrag/svelte'; 3 + import type { argv0 } from 'process'; 3 4 4 5 let position = $state({ x: 0, y: 0 }); 5 6 let rotation = $state(0.0); ··· 61 62 return moveBy; 62 63 }; 63 64 65 + // Physics constants 66 + let velocityX = $state(0); 67 + let velocityY = $state(0); 68 + let gravity = 200.0; // Gravity strength (positive because -Y is up) 69 + let friction = 0.96; // Air friction 70 + let bounciness = 0.8; // How much energy is preserved on bounce 71 + 64 72 const move = () => { 65 73 if (dragged) { 66 74 return; 67 75 } 68 76 69 - if (position.y !== 0) { 70 - position.y = Math.ceil(lerp(position.y, 0.0, 0.2)); 77 + // Apply physics when pet is in motion 78 + if (velocityX !== 0 || velocityY !== 0 || position.y !== 0) { 79 + // Apply gravity (remember negative Y is upward) 80 + velocityY += gravity * delta; 81 + 82 + // Apply friction 83 + velocityX *= friction; 84 + velocityY *= friction; 85 + 86 + // Update position 87 + position.x += velocityX * delta; 88 + position.y += velocityY * delta; 89 + 90 + // Handle window boundaries 91 + const viewportWidth = window.innerWidth; 92 + 93 + // Bounce off sides 94 + if (position.x < 0) { 95 + position.x = 0; 96 + velocityX = -velocityX * bounciness; 97 + } else if (position.x > viewportWidth) { 98 + position.x = viewportWidth; 99 + velocityX = -velocityX * bounciness; 100 + } 101 + 102 + // Bounce off bottom (floor) 103 + if (position.y > 0) { 104 + position.y = 0; 105 + velocityY = -velocityY * bounciness; 106 + // Only bounce if velocity is significant 107 + if (Math.abs(velocityY) < 1) { 108 + velocityY = 0; 109 + position.y = 0; 110 + } 111 + } 112 + 113 + // Stop very small movements 114 + if (position.y === 0) { 115 + velocityX = 0; 116 + velocityY = 0; 117 + position.y = 0; 118 + } 119 + 120 + // Update flip based on velocity 121 + if (Math.abs(velocityX) > 0.5) { 122 + flip = velocityX < 0; 123 + } 124 + 125 + targetRotation = velocityX * 0.02 + velocityY * 0.01; 126 + 71 127 return; 72 128 } 73 129 130 + // Normal movement when not physics-based 74 131 let moveByX = moveTowards(position.x, targetX, speed); 75 132 position.x += moveByX; 76 133 ··· 123 180 }, 124 181 onDragEnd: () => { 125 182 dragged = false; 183 + // Apply velocity based on the drag movement 184 + velocityX = rotationVelocity * 80.0; // Convert rotation velocity to horizontal movement 185 + velocityY = -Math.abs(rotationVelocity) * 30.0; // Jump higher with faster drags 126 186 } 127 187 }} 128 188 class="absolute bottom-[5vh] z-[1000] hover:animate-squiggle"