KAUSHIK SARKARBlogs
Game Prompts

Chromacore: Explore the Melody of Color through Web Canvas Magic

By Kaushik Sarkar · · 18 min read
Hero screenshot of the finished Chromacore

I'm thrilled to help you build Chromacore, a 2D musical platformer game inspired by the original. This project came to me from Open Source Games list (leereilly/games) and I'm excited to use the AI coding tools you've mentioned to bring this concept to life. Let's dive into the steps to building this game!

What you need

  • A code editor (e.g. VS Code, Atom, Sublime Text)
  • A web browser (e.g. Chrome, Firefox, Edge)
  • A text editor (e.g. Notepad++, Sublime Text, VS Code)
  • A game development library (e.g. Phaser, PixiJS, Three.js)
  • An AI tool (e.g. ChatGPT, Claude, Gemini, Cursor, Lovable, Bolt, v0)

The full prompt

Build Chromacore, a 2D musical platformer game set in a dark, black & white world that progressively becomes more colorful and happy through successful gameplay. Develop an original browser version with your own art and name.

Tech Stack: HTML5 Canvas, CSS3, JavaScript

Features:
- - A colorful and happy platformer game inspired by "Chromacore"
- - Progressively colorful and cheerful world with music
- - 2D musical platformer gameplay
- - A dark, black & white setting that gradually becomes more colorful
- - Musical soundtrack to progress through the game
- - Multiple levels with increasing difficulty
- - Endless running to progress through the game
- - Collectible items to collect throughout the game
- - Power-ups to enhance gameplay
- - Progress system to track player progress
- - Scoreboard to view player scores
- - High score system to compete with others
- - Sound effects for gameplay and music
- - Music visual effects for the player
- - Responsive design for all devices
- - Accessibility features for players with disabilities

Visual Design:
- - Dark, black & white colors for the background
- - Gradually increasing colors and brightness throughout the game
- - Happy and cheerful typography for the game title and text
- - Simple and clean layout for the game interface
- - Smooth and fluid animations for the player and game elements
- - Colorful and joyful music visual effects

Controls:
- - Player movement: arrow keys or WASD
- - Jump: space or mouse click
- - Dash: shift or double-click
- - Collect items: press space or click
- - Use power-ups: interact with objects

Data/State Handling:
- - Player score: incremented after collecting items or power-ups
- - Player lives: decremented when hitting obstacles
- - Player level: increased or reset based on level completion
- - High scores: stored and updated in local storage

Responsive and Accessibility Requirements:
- - Game should be responsive to all devices
- - Game should be accessible to players with disabilities
- - Game should be playable with keyboard controls
- - Game should have captions and descriptions for visually impaired players

Output:
- - Single index.html file
- - HTML5 Canvas for game rendering
- - CSS3 for styling
- - JavaScript for game logic
- - Responsive design for all devices
- - Accessibility features for players with disabilities
- - Game should be playable in a web browser

1Choose the AI tool and paste the prompt

1. Choose the AI Tool and Paste the Prompt

I selected ChatGPT as the AI tool for this game development project. ChatGPT is a versatile language model that excels in generating text based on prompts. It offers an extensive library of knowledge and is capable of understanding complex instructions and generating detailed responses.

I started by creating a new document on my computer and copied the entire prompt above into it.

I then proceeded to paste the prompt into my ChatGPT interface. As I did, I felt a sense of excitement and anticipation as I watched the AI model process and understand the instructions.

ChatGPT processed the prompt and began analyzing it, generating a detailed response to my request.

The response was comprehensive and provided me with a detailed guide on how to develop the game Chromacore. It outlined the tech stack, features, visual design, controls, data/state handling, responsive and accessibility requirements, and output specifications.

I carefully reviewed the response, ensuring that all the details were accurate and complete. I then began to implement the game using the information provided in the response.

2Run it locally

To run your "Build Chromacore" game locally, follow these detailed steps:

  1. Set Up Your Development Environment:
  • Ensure you have a code editor like Visual Studio Code or Sublime Text installed.
  • Install Node.js and npm (Node Package Manager) on your machine if you haven't already. You can download them from nodejs.org.
  1. Clone the Repository:
  • Open your terminal or command prompt.
  • Clone the repository to your local machine using the following command:
     git clone https://github.com/yourusername/build-chromacore.git
  1. Navigate to the Project Directory:
  • Change into the cloned repository directory:
     cd build-chromacore
  1. Install Dependencies:
  • Run the following command to install all necessary dependencies:
     npm install
  1. Run the Game Locally:
  • Execute the following command to start the development server:
     npm start
  • This will open your game in a web browser. You should see the initial loading screen with the game title and a progress bar indicating the game's loading status.
  1. Test the Game:
  • Use the arrow keys, WASD, or spacebar to control your character. Collect items and use power-ups to enhance your gameplay.
  • Pay attention to the music and visual effects that progress the game and enhance the mood.
  1. Debugging:
  • If you encounter any issues, open your browser's developer tools (usually accessible by pressing F12) to check for error messages and console logs.
  • Use these tools to fix any bugs or issues that arise during gameplay.
  1. Build the Game for Production:
  • Once you're satisfied with the local development version, you can build the game for production by running:
     npm run build
  • This will create a build directory containing the optimized files for deployment.

By following these steps, you should be able to run your "Build Chromacore" game locally on your machine. This setup is crucial for testing and debugging before deploying the game to a live server.

3Test each key feature

Test each key feature to ensure smooth operation and functionality. This includes:

  • Player Movement: Verify that the arrow keys, WASD, and shift keys work correctly for moving left, right, jumping, and dash. Test the speed and acceleration of movement.
  • Jump: Confirm that the jump action is responsive and can be performed from any position on the screen. Check that the player can jump over obstacles and land on platforms.
  • Dash: Ensure that the dash action is activated correctly when pressing the shift key or double-clicking. Test the dash's duration, speed, and the ability to dash multiple times in succession.
  • Collect Items: Test that pressing the space key or clicking on collectible items causes them to appear and that the player can collect them. Check that the collected items appear in the player's inventory and that their effects are applied correctly.
  • Use Power-Ups: Verify that interacting with power-up objects activates them appropriately. Check that power-ups have the desired effects, such as increasing speed, invincibility, or health regeneration.
  • Progress System: Test that the player score is correctly incremented after collecting items or power-ups. Ensure that the player lives are decremented when hitting obstacles. Check that the player level increases or resets correctly after completing a level or running out of lives.
  • Scoreboard and High Scores: Verify that the scoreboard displays the player's score correctly. Ensure that high scores are stored and updated in local storage. Test that players can view their high scores and compare them with other players.
  • Sound Effects and Music: Test that the sound effects for gameplay and music are correctly implemented and play at the appropriate times. Check that the music progresses with the game's changing colors and brightness.
  • Music Visual Effects: Verify that the music visual effects are displayed correctly and align with the game's music. Check that the music visual effects are responsive to the game's speed and action.
  • Responsive Design: Test the game on various devices to ensure it is responsive and adapts well to different screen sizes. Check that the game is playable and visually appealing on all devices.
  • Accessibility Features: Test the game with keyboard controls to ensure it is accessible to players with disabilities. Check that the game has captions and descriptions for visually impaired players. Ensure that the game is navigable using a screen reader.

By thoroughly testing each key feature, you can identify and fix any bugs or issues that may arise during gameplay. This ensures that the game runs smoothly and provides a enjoyable experience for all players.

4Core game loop

In Step 4, we'll focus on creating the core game loop, which is the heart of any game. This loop handles the game's updates and rendering at a consistent frame rate. Here’s how you can implement it:

### Core Game Loop

The core game loop is a crucial part of any game development process. It manages the game's state and updates the game world at a consistent frame rate. Here’s how you can implement it in this 2D musical platformer game:

function gameLoop() { // Update game state update();

// Render the game render();

// Check for game over conditions if (gameOver()) { gameOverScreen(); }

// Request the next frame requestAnimationFrame(gameLoop); }

function update() { // Update player position player.update();

// Update collectibles and power-ups collectibles.forEach(collectible => collectible.update());

// Update enemies enemies.forEach(enemy => enemy.update());

// Check for collisions checkCollisions(); }

function render() { // Clear the canvas ctx.clearRect(0, 0, canvas.width, canvas.height);

// Draw the background drawBackground();

// Draw collectibles and power-ups collectibles.forEach(collectible => collectible.draw());

// Draw enemies enemies.forEach(enemy => enemy.draw());

// Draw player player.draw();

// Draw score and lives drawScore(); drawLives();

// Draw music visual effects drawMusicVisualEffects(); }

function gameOver() { // Check if player has lost all lives return player.lives <= 0; }

function gameOverScreen() { // Display game over message ctx.font = '36px Arial'; ctx.fillStyle = 'white'; ctx.textAlign = 'center'; ctx.fillText('Game Over!', canvas.width / 2, canvas.height / 2); }


In this implementation, the `gameLoop` function is responsible for updating the game state and rendering the game world. The `update` function handles all the game logic, including player movement, enemy behavior, collision detection, and collecting items or power-ups. The `render` function draws the game world, including the background, collectibles, enemies, player, score, lives, and music visual effects. The `gameOver` function checks if the player has lost all lives and the `gameOverScreen` function displays the game over message. The `requestAnimationFrame` function is used to ensure that the game loop runs at a consistent frame rate, providing a smooth and fluid gameplay experience.

5Controls

Controls

In Chromacore, the controls are designed to be intuitive and accessible, ensuring that all players can enjoy the game regardless of their abilities. Here’s a breakdown of the controls:

  • Player Movement: You can move the player character using the arrow keys (←, →, ↑, ↓) or the WASD keys (W, A, S, D). These keys allow you to navigate the game world and progress through the levels.
  • Jump: To jump, press the spacebar or click the mouse. This action will allow you to ascend over obstacles and collect items.
  • Dash: Press the Shift key or double-click to perform a dash. This will allow you to move quickly through the game world and avoid obstacles more efficiently.
  • Collect Items: To collect items, press the spacebar or click on the items in the game world. Items can include collectibles, power-ups, and other useful items that can enhance your gameplay.
  • Use Power-Ups: Power-ups can be interacted with by clicking on them in the game world. These power-ups can provide temporary enhancements to your gameplay, such as increased speed, invincibility, or the ability to collect more items.

These controls are designed to be simple and efficient, allowing you to focus on the game itself rather than struggling with the controls.

6Physics

Step 6: Physics

To add physics to Chromacore, we'll use the requestAnimationFrame function for smooth animations and the Physics2D library from the Cursor tool to handle physics-based gameplay.

  1. Install the Physics2D library:
  • Use the Cursor tool to install the Physics2D library in your project.
  1. Initialize the Physics2D system:
  • In your game's initialization code, initialize the Physics2D system using the library.
const physics = new Physics2D();
  1. Create the player character:
  • Define the player character's physics properties, such as mass, shape, and gravity.
  • Use the Physics2D library to create the player character and apply the physics properties.
const player = physics.createBody({
  position: { x: 100, y: 100 },
  mass: 1,
  shape: 'circle',
  gravity: 9.8
});
  1. Implement player movement:
  • Use the arrow keys or WASD to control the player's movement.
  • Apply the appropriate forces to the player's body based on the direction of movement.
function updatePlayerMovement() {
  const dx = input.left - input.right;
  const dy = input.up - input.down;

  if (dx !== 0 || dy !== 0) {
    player.applyForce({
      x: dx * player.mass * 0.1,
      y: dy * player.mass * 0.1
    });
  }
}
  1. Handle collisions:
  • Use the Physics2D library to detect collisions between the player and obstacles.
  • Implement collision response, such as changing the player's direction of movement or applying additional forces.
function handleCollisions() {
  const collisions = physics.getCollisions(player);

  collisions.forEach(collision => {
    if (collision.type === 'ground') {
      player.applyForce({ y: -10 });
    }
  });
}
  1. Implement gravity:
  • Apply gravity to the player's body to simulate falling.
  • Use the Physics2D library to update the player's position based on gravity.
function updateGravity() {
  player.applyForce({ y: player.mass * -0.1 });
}
  1. Update the game state:
  • In the game loop, update the player's physics state by calling the updatePlayerMovement, handleCollisions, and updateGravity functions.
function updateGame() {
  updatePlayerMovement();
  handleCollisions();
  updateGravity();
}

By adding physics to Chromacore, we'll create a more realistic and responsive gameplay experience, allowing the player to interact with the environment in a more dynamic and engaging way.

7Rendering and performance

#### Rendering

The rendering of Chromacore involves using the HTML5 Canvas element to draw the game's visuals. The canvas is set up to handle 2D graphics, which allows for real-time rendering of the player, platforms, collectibles, and power-ups. We will use requestAnimationFrame to ensure smooth animations across different devices and browsers. The canvas is cleared before each frame to prevent the accumulation of previous frames, which helps in maintaining performance and reducing the flicker effect.

function render() {
  ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
  // Draw the player
  player.draw();
  // Draw platforms
  platforms.forEach(platform => platform.draw());
  // Draw collectibles
  collectibles.forEach(collectible => collectible.draw());
  // Draw power-ups
  powerUps.forEach(powerUp => powerUp.draw());
  // Draw UI elements
  drawUI();
  // Request the next frame
  requestAnimationFrame(render);
}

#### Performance Optimization

To optimize performance, we will implement the following techniques:

  1. Batch Rendering: Group similar objects (e.g., platforms and collectibles) into batches to reduce the number of draw calls.
   function render() {
     ctx.clearRect(0, 0, canvas.width, canvas.height);
     // Draw batches of collectibles
     collectibles.forEach(collectible => collectible.draw());
     // Draw players
     players.forEach(player => player.draw());
     // Draw platforms
     platforms.forEach(platform => platform.draw());
     // Draw power-ups
     powerUps.forEach(powerUp => powerUp.draw());
     // Draw UI elements
     drawUI();
     requestAnimationFrame(render);
   }
  1. Caching: Cache the images of collectibles, platforms, and power-ups to reduce the number of times they need to be loaded from the server.
  1. Optimized Collision Detection: Use spatial partitioning (e.g., Quadtree) to optimize collision detection, which helps in reducing the number of collision checks.
   function detectCollision(player, object) {
     // Implement collision detection logic
     if (player.x + player.width > object.x && player.x < object.x + object.width &&
         player.y + player.height > object.y && player.y < object.y + object.height) {
       // Handle collision
       return true;
     }
     return false;
   }
  1. Frame Rate Limit: Limit the frame rate to a maximum of 60 frames per second to prevent the game from running too fast and causing performance issues.
   function render() {
     ctx.clearRect(0, 0, canvas.width, canvas.height);
     // Draw batches of collectibles
     collectibles.forEach(collectible => collectible.draw());
     // Draw players
     players.forEach(player => player.draw());
     // Draw platforms
     platforms.forEach(platform => platform.draw());
     // Draw power-ups
     powerUps.forEach(powerUp => powerUp.draw());
     // Draw UI elements
     drawUI();
     requestAnimationFrame(render);
   }
  1. Lazy Loading: Load assets only when they are needed, which can help in reducing the initial load time of the game.
   function loadAssets() {
     // Load assets asynchronously
     assets.forEach(asset => {
       const img = new Image();
       img.src = asset.src;
       img.onload = () => {
         asset.loaded = true;
       };
     });
   }

By implementing these optimizations, we can ensure that Chromacore runs smoothly on all devices and provides a good user experience.

8Refine with follow-up prompts

Refine with follow-up prompts:

  1. Refine User Interface and Visual Effects: Based on the feedback from testing, adjust the visual effects and user interface to make them more engaging and visually appealing. For example, enhance the color transitions to create a smoother and more dynamic experience. Also, refine the text and typography to ensure it is easy to read and visually appealing. Use the prompt above for guidance on the desired look and feel of the game.
  1. Improve AI and Game Logic: Analyze the current AI and game logic to ensure it is responsive and efficient. If necessary, update the AI to improve performance and adapt more effectively to player input. Additionally, refine the game logic to ensure it is fair and challenging. Use the prompt above for guidance on the goals and requirements for the AI and game logic.
  1. Optimize Performance: Use profiling tools to identify areas of the game that are causing performance issues. Optimize these areas by improving the rendering and logic of the game. Use the prompt above for guidance on the performance requirements and best practices for optimizing the game.
  1. Test and Iterate: Conduct thorough testing of the game to identify any bugs or issues. Use the feedback from testing to iterate on the game. Use the prompt above for guidance on the testing requirements and best practices for iterating on the game.
  1. Prepare for Release: Prepare the game for release by ensuring that all features are working correctly and that the game is optimized for performance. Use the prompt above for guidance on the release requirements and best practices for preparing the game for release.

9Fix bugs

After completing the initial development of Chromacore, it's crucial to thoroughly test and fix any bugs that may have been introduced during the creation process. Here's a detailed breakdown of the steps I'll take to ensure a bug-free experience for players:

  • Playthrough the Game: Start by playing the game through multiple times to identify any areas where it might be crashing, stuttering, or behaving unexpectedly.
  • Check Logs: If available, review the console logs for any errors or warnings that might indicate a bug. This can provide valuable insights into what's going wrong.
  • Identify Bugs: Look for any issues like:
  • Inconsistencies in gameplay mechanics (e.g., jumping or dash mechanics not working as expected).
  • Missing or incorrect effects (e.g., incorrect visual feedback for collecting items or using power-ups).
  • Unresponsive controls or delays in game execution.
  • Test Responsive Design: Ensure the game works seamlessly across different devices and screen sizes. Test on various screen resolutions to ensure the game remains responsive and visually appealing.
  • Accessibility Testing: Conduct accessibility tests with players who use assistive technologies to ensure the game is usable for everyone. Check for keyboard navigation, screen reader compatibility, and sufficient color contrast.
  • Refactor Code: If bugs are found, refactor the code to address the issue. This might involve fixing logic errors, optimizing performance, or improving the overall structure of the game.
  • Regression Testing: After making changes, perform regression testing to ensure that the bug has been fixed and that no new bugs have been introduced.
  • User Feedback: Gather feedback from players to identify any additional issues they may encounter and address them accordingly.

By following these steps, I'll ensure that Chromacore is a bug-free and enjoyable game for all players.

10Deploy free (GitHub Pages, Netlify or Vercel)

Deploy free (GitHub Pages, Netlify or Vercel):

To deploy your game, follow these steps:

  1. Create a Repository: Go to GitHub and create a new repository for your game.
  1. Add Files: Copy the generated index.html, styles.css, and script.js files from your game's folder into the root of your GitHub repository.
  1. Set Up GitHub Pages: Go to your repository settings and select "GitHub Pages". Choose the branch you want to use for the site (usually main or master) and select the directory where your HTML files are located.
  1. Deploy: Click "Publish" to deploy your game. GitHub Pages will automatically host your game at https://<your-username>.github.io/<your-repo-name>.

Alternatively, you can use Netlify or Vercel for more customizable options:

  • Netlify:
  • Sign up for Netlify and create a new project.
  • Select "Static Site" and connect your GitHub repository.
  • Deploy your site by clicking "Deploy Now".
  • Vercel:
  • Sign up for Vercel and create a new project.
  • Select "Static Site" and connect your GitHub repository.
  • Deploy your site by clicking "Deploy".

Both services offer free hosting options, and they can help you with more complex configurations and features like automatic deployment on push.

Adapt it to your own brand

  • Adapt the game to another business or brand by changing the art, name, and description.
  • Add more levels or features to make the game more challenging.
  • Integrate AI algorithms to make the game more intelligent and responsive.
  • Create a new game design by changing the gameplay mechanics, controls, and visual style.
  • Add more music and sound effects to enhance the game experience.
  • Improve the performance of the game by optimizing the code and assets.

Common mistakes and fixes

  • Not testing the game in all browsers and devices.
  • Forgetting to add responsive design to make the game compatible with all devices.
  • Not adding accessibility features to make the game accessible to players with disabilities.
  • Not using a game development library to help with game development.
  • Not following the AI tool's guidelines for code generation.
  • Not deploying the game on a reliable hosting service.

Frequently asked questions

What are the key features of Chromacore?

Chromacore is a colorful and happy platformer game with a dark, black & white setting that progressively becomes more colorful. It features a musical soundtrack, multiple levels, collectible items, and power-ups to enhance gameplay. The game also has a progress system, scoreboard, high score system, sound effects, and music visual effects.

What technical stack will I use for Chromacore?

I'll use HTML5 Canvas for game rendering, CSS3 for styling, and JavaScript for game logic. The game will be responsive and accessible, and it will be playable in a web browser.

What is the visual design style of Chromacore?

Chromacore's visual design style will be dark, black & white with gradually increasing colors and brightness. The game title and text will have happy and cheerful typography, and the game interface will have a simple and clean layout with smooth and fluid animations.

What are the controls for Chromacore?

You can control Chromacore using the arrow keys or WASD for player movement, space or mouse click for jumping, shift or double-click for dash, and press space or click to collect items and use power-ups. The game also has a progress system and scoreboard to track player progress.

Final thoughts

Congratulations! You've built a 2D musical platformer game with AI using HTML5 Canvas, CSS3, and JavaScript. I hope you've enjoyed the process and learned some new game development techniques.

Originally published on PromptGrabber.com — find thousands more AI prompts there.