UXInteract / task_049 /instruction.md
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
|
Raw History Blame Contribute Delete
2.97 kB

Build a deterministic Flappy Bird game

Create a single offline index.html in HTML/CSS/JavaScript. Draw a bird, scrolling pipe pairs with openings, and readable score and status. Use a canvas of at least 100×100 with data-testid="canvas", and mark the score, status, flap and new-game controls with corresponding data-testid values score, status, flap and new-game. Spacebar and the flap button perform the same action.

State and coordinates

Expose window.__game with init(config), getState(), flap() and step(dtMs). Initialization and stepping return the resulting state. Return an independent JSON snapshot from getState():

{bird:{y,vy}, pipes:[{x,gapY,gapH,passed}], score,status,width,height}

Coordinates start at the top left, with y increasing downward. Pipe x is the left edge, and the open interval from gapY to gapY + gapH is the gap. Document these conventions in the code. All init fields are optional:

  • seed (integer), gravity, flapImpulse, pipeSpeed, gapH, pipeInterval, width and height.
  • birdX and birdY locate the bird's center. birdX, birdR and pipeWidth default to 60, 12 and 52 pixels. Use the radius for drawing and pipe collisions. birdY defaults to height/2 and birdVy to 0.
  • An explicit pipes array supplies the initial layout unchanged. autoPipes defaults to false when pipes is supplied and true otherwise. Default initialization shows at least one upcoming pipe.
  • status: 'playing' starts in play immediately; otherwise initialize 'ready'. After collision use 'over'. Put the current state value as text in the status element, with any explanatory label outside it.

Acceptance Checklist

  • Flap starts play from ready and sets vertical velocity to -flapImpulse. Gravity pulls the bird down at fixed horizontal position; pipes move left. For each step(dtMs) in play, update vy += gravity * dtMs / 16, then y += vy * dtMs / 16, and subtract pipeSpeed * dtMs / 16 from each pipe's x.
  • A safe crossing of a pipe's right edge scores exactly one and sets its passed flag. A collision in the crossing step does not score. Passing through an opening is safe, and hitting a solid pipe ends play. With no pipe collision, play continues while the bird's center is inside 0 < y < height, including when the rendered bird overlaps the ground or ceiling. End play at y <= 0 or y >= height. After game over, flap and step are no-ops.
  • The same seed and actions give identical pipe sequences and trajectories; different seeds influence the sequence. Changing a returned snapshot cannot change the game.
  • Display actual injected geometry and state in the canvas, using distinct colors. Real inputs update the same simulation and display. A normal page load advances play through animation frames calling step(16). In a manually initialized scenario, elapsed wall time does not advance state; advance it only through explicit steps.