DEV Community

Cover image for Day 101 of Learning MERN Stack
Ali Hamza
Ali Hamza

Posted on

Day 101 of Learning MERN Stack

Hello Dev Community! 👋

It is officially Day 101 of my engineering timeline! After hitting the triple-digit milestone yesterday by designing visual components, today I completed the absolute core: Writing the complete structural physics, dynamic key bindings, and status handlers for my Flappy Bird Clone using Pure Vanilla JavaScript! 🎮⚡

Building dynamic gaming logic close to the browser engine means passing coordinate states cleanly and avoiding lag during intensive repaint frames.


🧠 Deconstructing the Day 101 Game Engine Logic

As captured across my development environment inside "Screenshot (227).png", "Screenshot (228).png", and the running execution output in "Screenshot (230).jpg", here is how the engine functions under the hood:

1. Unified Audio Integration & Pipeline Tracking

  • Set up clear variables targeting layout structures (.player, .score, .game-status) via querySelector setups ("Screenshot (227).png").
  • Integrated native HTML5 Audio() class constructors (BackgroundSound, gameOverSound, collisionSound) to tie immersive spatial audio triggers to specific lifecycle collision events.
  • Instantiated absolute spacing markers for upper and lower hurdle rows spanning incremental positions ($300\text{px}$ up to $1400\text{px}$).

2. Multi-Directional Key Control & Realtime CSS Variable Injection

  • Registered a global 'keydown' listener targeting the player's navigation inputs ("Screenshot (228).png").
  • Inside the ControlPlayer(e) engine, arrow controls intercept movement intents:
    • Modifies coordinate increments ($\Delta x, \Delta y = 5$) directly.
    • Encapsulates rigid bounds checkings (e.g., stopping $y$ from dipping under $-70$ or pushing over $430$).
    • Feeds computed metrics back into the template layout via real-time element style mutations using native property overwrites:

javascript
  player.style.setProperty('--playerX', `${x}px`);
  player.style.setProperty('--playerY', `${y}px`);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)