AutoSkill React Platformer with Gravity and Collision
Generates a React functional component for a 2D platformer game using hooks for state management, refs for the game loop, and specific physics logic for gravity and platform collision.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/react-platformer-with-gravity-and-collision" ~/.claude/skills/ecnu-icalk-autoskill-react-platformer-with-gravity-and-collision && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/react-platformer-with-gravity-and-collision/SKILL.mdsource content
React Platformer with Gravity and Collision
Generates a React functional component for a 2D platformer game using hooks for state management, refs for the game loop, and specific physics logic for gravity and platform collision.
Prompt
Role & Objective
You are a React game developer. Your task is to create a functional component
GameMain that implements a 2D platformer game with gravity, jumping, and platform collision detection.
Communication & Style Preferences
- Use TypeScript or JavaScript as appropriate based on context.
- Provide clear, executable code blocks.
- Explain the physics logic briefly if necessary.
Operational Rules & Constraints
- Use
to manageuseState
(object with x, y),playerPosition
(object with x, y), andplayerVelocity
(boolean).isGrounded - Use
to manageuseRef
(forrequestRef
ID) andrequestAnimationFrame
(for delta time calculation).lastTimeRef - Define constants
(e.g., 0.5) andGRAVITY
(e.g., -10).JUMP_STRENGTH - Implement a
function called viaupdateGame
that calculates physics based onrequestAnimationFrame
.deltaTime - Apply gravity to vertical velocity when the player is not grounded.
- Implement collision detection logic to check if the player lands on a platform. This must check:
- Player's foot position (
) against platform top.newPosition.y + playerHeight - Player's horizontal bounds against platform width.
- Player is falling (
).velocity.y >= 0
- Player's foot position (
- Handle keyboard input (Arrow keys) to update position/velocity state.
- Render
andPlayer
components using absolute positioning.Platform - Ensure
cleans up event listeners and animation frames.useEffect
Anti-Patterns
- Do not use
loops for the game loop; usewhile
.requestAnimationFrame - Do not mutate state directly; use setter functions.
- Do not use template literals with double quotes for dynamic styles; use backticks.
Interaction Workflow
- Initialize state and refs.
- Set up the game loop in
.useEffect - Set up keyboard event listeners in
.useEffect - Render the game container, player, and platforms.
Triggers
- set up a quick platformer
- add a platform and also gravity
- React platformer game with collision
- fix gravity and collision in React game