Skip to content
Back to skills

React Platformer With Gravity And Collision

ASecurity

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.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
developmentjavascripttypescriptjavareact

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill react-platformer-with-gravity-and-collision --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Platformer With Gravity And Collision?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for React Platformer With Gravity And Collision
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-react-platformer-with-gravity-and-collision/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-react-platformer-with-gravity-and-collision)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "e70feb9b-863c-4dd4-ad6b-e038a731a084"
name: "React Platformer with Gravity and Collision"
description: "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."
version: "0.1.0"
tags:
  - "React"
  - "Platformer"
  - "Game Loop"
  - "Physics"
  - "Hooks"
triggers:
  - "set up a quick platformer"
  - "add a platform and also gravity"
  - "React platformer game with collision"
  - "fix gravity and collision in React game"
---

# 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 `useState` to manage `playerPosition` (object with x, y), `playerVelocity` (object with x, y), and `isGrounded` (boolean).
- Use `useRef` to manage `requestRef` (for `requestAnimationFrame` ID) and `lastTimeRef` (for delta time calculation).
- Define constants `GRAVITY` (e.g., 0.5) and `JUMP_STRENGTH` (e.g., -10).
- Implement a `updateGame` function called via `requestAnimationFrame` that calculates physics based on `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 (`newPosition.y + playerHeight`) against platform top.
  - Player's horizontal bounds against platform width.
  - Player is falling (`velocity.y >= 0`).
- Handle keyboard input (Arrow keys) to update position/velocity state.
- Render `Player` and `Platform` components using absolute positioning.
- Ensure `useEffect` cleans up event listeners and animation frames.
# Anti-Patterns
- Do not use `while` loops for the game loop; use `requestAnimationFrame`.
- Do not mutate state directly; use setter functions.
- Do not use template literals with double quotes for dynamic styles; use backticks.
# Interaction Workflow
1. Initialize state and refs.
2. Set up the game loop in `useEffect`.
3. Set up keyboard event listeners in `useEffect`.
4. 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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.