Menu

Introducing CarverJS
πŸ“°
0

Introducing CarverJS

DEV CommunityΒ·Het DaveΒ·about 1 month ago
#G1Y6ZmhG
#webdev#gamedev#react#game#carverjs#multiplayer
Reading 0:00
15s threshold

Here is a complete 2D game written in React. Move with WASD. Renders in a browser. The whole thing is around 40 lines. import { useRef , useEffect } from " react " ; import { Game , World , Actor } from " @carverjs/core/components " ; import { useGameLoop , useInput } from " @carverjs/core/hooks " ; import { useGameStore } from " @carverjs/core/store " ; import type { Group } from " @carverjs/core/types " ; function Player () { const ref = useRef < Group > ( null ); const setPhase = useGameStore (( s ) => s . setPhase ); const { getAxis } = useInput (); useEffect (() => { setPhase ( " playing " ); }, [ setPhase ]); useGameLoop (( dt ) => { if ( ! ref . current ) return ; ref . current . position . x += getAxis ( " KeyA " , " KeyD " ) * 5 * dt ; ref . current . position .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More