diff --git a/_projects/2026-04-12-TransBlog.ipynb b/_projects/2026-04-12-TransBlog.ipynb new file mode 100644 index 000000000..b56e4d4ee --- /dev/null +++ b/_projects/2026-04-12-TransBlog.ipynb @@ -0,0 +1,169 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "fc5fb345", + "metadata": {}, + "source": [ + "---\n", + "layout: post\n", + "codemirror: true\n", + "title: Sprint 5 Transition Teaching Lesson\n", + "permalink: /sprintingsnails/transitions\n", + "author: Sophie Haas\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "ad84857b", + "metadata": {}, + "source": [ + "Have you ever wanted to know how to add a transition screen to your game? Maybe when the game ends, you want to keep the player connected to the experience by flashing a massive:\n", + "\n", + "

\n", + "G A M E   O V E R\n", + "

\n", + "\n", + "...or build anticipation for the next challenge with a bold:\n", + "\n", + "

\n", + "L E V E L   1\n", + "

\n", + "\n", + "Static games can feel \"stiff.\" Transition screens act as the theater curtain for your code—they hide the background logic, signal a change in state, and provide crucial feedback to the player.\n", + "\n", + "In this blog, we’re going to demonstrate how to use:\n", + "\n", + "Dynamic DOM Injection: Building UI elements on the fly.\n", + "\n", + "CSS Keyframe Animations: Adding movement and \"pulse\" to your screens.\n", + "\n", + "Logic Triggers: Timing your transitions to match game events." + ] + }, + { + "cell_type": "markdown", + "id": "e41d1cde", + "metadata": {}, + "source": [ + "
\n", + " \n", + "
\n", + " View Kirby Maze Example\n", + "
\n", + "
\n", + "
\n", + "\n", + "# Understanding UI Transitions & Overlays\n", + "\n", + "A transition screen is a **UI Overlay** that sits on a higher \"layer\" than your game world. In game development, we call this the **HUD (Heads-Up Display)** or **UI Layer**.\n", + "\n", + "---\n", + "\n", + "### The Primary Jobs of a Transition Screen\n", + "* **State Signaling:** Letting the player know exactly what happened—whether they won, lost, or paused.\n", + "* **Input Blocking:** Creating a \"logical wall\" that prevents the player from moving or interacting with the game world while the screen is visible.\n", + "* **Scene Management:** Providing the \"Escape Hatch\"—buttons to restart the level or move to the next stage.\n", + "\n", + "---\n", + "\n", + "# How it Works in Your Code\n", + "Your implementation uses a **\"CSS-in-JS\"** approach. Since we are working in a Notebook environment, we can't easily jump between different HTML files, so we manipulate the **DOM** (the webpage structure) directly.\n", + "\n", + "### The \"Ghost\" Element\n", + "In your constructor, you create the `lossOverlay`. Crucially, you set `display: none`. This makes it a **ghost element**—it exists in the code’s memory and the page’s structure, but the player cannot see or touch it yet.\n", + "\n", + "> **Code Insight:**\n", + "> ```javascript\n", + "> lossOverlay.style.cssText = \"display:none; position:fixed; width:100%; height:100%; z-index:20000;\";\n", + "> ```\n", + "\n", + "---\n", + "\n", + "# The Trigger (The \"Watcher\")\n", + "To make the screen appear, you need a **\"Watcher.\"** In your code, this is the `setInterval` timer that constantly evaluates the state of the game.\n", + "\n", + "| Step | Component | Logic |\n", + "| :--- | :--- | :--- |\n", + "| **1** | **The Condition** | The Watcher checks: `window.timeLeft <= 0` |\n", + "| **2** | **The Action** | The Watcher flips the CSS from `display: none` to `display: flex`. |\n", + "| **3** | **The Result** | The screen \"appears\" instantly, covering the game. |\n", + "\n", + "---\n", + "\n", + "# Key Concepts in the \"Kirby Maze\"\n", + "The implementation uses three advanced techniques to make the transition feel professional:\n", + "\"Image\"\n", + "\"Image\"\n", + "### 1. Z-Indexing\n", + "By setting `z-index: 20000`, we ensure the Game Over screen stays above Kirby, the walls, and the background. It is mathematically the \"top-most\" item on the page.\n", + "\n", + "### 2. Input Gating\n", + "We use a `window.isPaused` variable as a \"gatekeeper.\" Even if the player mashes the **WASD** keys during the Game Over screen, the code checks this variable and refuses to move the character.\n", + "\n", + "### 3. Visual Polish\n", + "We injected a `