JIT
Game code
code to a game

Okay, let's create a simple Snake game using HTML, CSS, and JavaScript.

You can now open the index.html file. Use the arrow keys to control the snake. Eat the red food to grow and increase your score. The game ends if you hit the wall or your own tail.

Updated files
v1
cooler type of game advanced

Okay, let's create a more advanced game: a basic Asteroids clone. This involves physics for movement, rotation, shooting, and collision detection.

This sets up an Asteroids game where you can:

  • Rotate the ship (Left/Right Arrows).
  • Thrust forward (Up Arrow).
  • Shoot bullets (Space).
  • Destroy asteroids, which break into smaller pieces.
  • Asteroids and the ship wrap around the screen edges.
  • Basic scoring and lives system.
  • Ship invincibility for a short time after respawning.
  • Game over screen with restart option (Enter key).

Open index.html to play.

Updated files
v2
more advanced

Okay, let's build a more advanced game: a basic 2D Platformer. This will involve gravity, jumping mechanics, collision detection with platforms, and simple level design.

This creates a platformer with:

  • A player character affected by gravity.
  • Movement using Left/Right arrow keys.
  • Jumping using the Up arrow key (only when grounded).
  • Collision detection with rectangular platforms (landing on top, hitting sides/bottom).
  • Basic level structure defined by Platform objects.
  • Boundary collision with the canvas edges.
  • Simple air friction when movement keys are released.

Open index.html to play. You can move the orange rectangle around and jump on the green and brown platforms.*

Updated files
v3
more advanced game

Okay, let's create a more advanced Top-Down Shooter game. This will involve player movement controlled by keyboard, aiming/shooting with the mouse, basic enemy AI, health, and scoring.

This Top-Down Shooter includes:

  • Player movement with WASD keys.
  • Aiming based on mouse cursor position.
  • Shooting with mouse click (includes a cooldown).
  • Enemies that spawn off-screen and move towards the player.
  • Health systems for both player and enemies, displayed as bars.
  • Collision detection between bullets/enemies and player/enemies.
  • Scoring system for defeating enemies.
  • A Game Over screen with a restart option.

Open index.html to play. Move with WASD, aim with the mouse, and click to shoot the red enemies.

Updated files
v4
MORE ADVANCED GAME

Okay, let's build a more complex game: a basic Tile-Based Dungeon Crawler. This will involve navigating a map made of tiles, camera scrolling, simple enemies, and collecting items.

This Dungeon Crawler features:

  • Tile-Based Map: Defined in map.js, easily modifiable.
  • Player Control: Move with WASD or Arrow Keys.
  • Camera Scrolling: The view follows the player.
  • Wall Collision: Prevents moving through wall tiles.
  • Simple Enemies: They chase the player within a certain range if they have line-of-sight and deal damage on contact.
  • Health System: Player and enemies have health.
  • Items: Collectible keys.
  • Locked Exit: Requires a key to open.
  • Win/Loss Conditions: Reach the unlocked exit or run out of health.
  • Basic UI: Displays health, keys collected, and temporary messages.
  • Restart Functionality: Buttons on the Game Over/Win screens.

Open index.html to explore the dungeon! Navigate the corridors, avoid or defeat the red enemies, find the gold key, and reach the exit (initially red, turns green when unlocked).*

Updated files
v5
a bit more advanced type of game 3D

Okay, let's create a basic 3D game using Three.js. This will be a simple "collect the spinning cubes" game where you control a sphere in a 3D environment.

Since we are in a browser environment and cannot easily install packages, we'll load Three.js via a CDN.

This sets up a 3D scene where:

  • You control a red sphere using WASD or Arrow Keys on a green plane.
  • The camera follows the player from a third-person perspective.
  • There are several yellow cubes scattered around.
  • Moving the sphere over a cube collects it and increases your score.
  • Basic lighting and shadows are included.
  • A simple UI shows the score.
  • A win message appears when all items are collected, with a button to restart.

Open index.html to play. Move the sphere to collect all the spinning yellow cubes!*

Updated files
v6
3d game advanced

Okay, let's create a more advanced 3D game using Three.js and incorporating a physics engine (cannon-es). This will be a simple physics-based shooter where you control a sphere, navigate obstacles, and shoot targets.

We'll load both three and cannon-es via CDN using import maps.

This creates a more involved 3D game with:

  • Physics Engine: Uses cannon-es for realistic movement, gravity, and collisions.
  • Physics-Based Movement: Player sphere is controlled by applying forces (WASD) and velocity changes (Space for Jump).
  • Environment: A ground plane with static obstacle boxes.
  • Shooting: Click the mouse to shoot small physics-based bullets in the direction the camera is facing.
  • Targets: Static red cubes that can be destroyed after taking multiple hits (basic health system).
  • Collision Handling: Uses cannon-es contact materials and collision events to detect bullet-target hits and player-ground contact (for jumping).
  • Win Condition: Game ends when all targets are destroyed.
  • UI: Shows remaining targets and a win message with a restart button.
  • Camera: Third-person camera that follows the player.

Open index.html to play. Use WASD to apply force to the blue sphere, Space to jump (when touching the ground), and click to shoot yellow bullets at the red targets. Destroy all targets to win!*

Updated files
v7
advanced game

Okay, let's build a Basic Tower Defense game using HTML Canvas and JavaScript. This involves placing towers to defend against waves of enemies moving along a predefined path.

This sets up a Tower Defense game with:

  • Pathfinding: Enemies follow a predefined path across the canvas.
  • Waves: Enemies spawn in waves, initiated by the player clicking "Start Next Wave". Waves get progressively harder (more enemies, more health).
  • Tower Placement: Players can select a tower type (only one basic type for now) and click on valid grid squares (not on the path or other towers) to build, spending money.
  • Tower Targeting: Towers automatically find the nearest enemy within range and shoot at it.
  • Combat: Towers deal damage to enemies; enemies lose health and disappear when health reaches zero, rewarding the player with money.
  • Lives: Players lose lives if enemies reach the end of the path.
  • Economy: Start with money, earn money by defeating enemies, spend money on towers.
  • UI: Displays money, lives, current wave, and provides buttons for starting waves and selecting towers.
  • Win/Loss: Game ends if lives reach zero. (No explicit win condition yet, waves continue indefinitely).

Open index.html to play. Click the "Basic Tower" button to enter build mode (cursor changes), then click on a valid green square to place a tower. Click "Start Next Wave" to begin the onslaught!*

Updated files
v8