$ESC = [char]27 $CLR_RESET = "$ESC[0m" $CLR_RED = "$ESC[31m" # Mario / Goombas $CLR_GREEN = "$ESC[32m" # Platforms $CLR_YELLOW = "$ESC[33m" # Coins / Score $CLR_CYAN = "$ESC[36m" # UI Box $CLR_GROUND = "$ESC[32m" # Ground [Console]::CursorVisible = $false Clear-Host # Set a fixed, fast performance grid size to prevent terminal lag $width = 80 $height = 22 $score = 0 $coins = 0 $lives = 3 $px = 4.0 $py = 2.0 $vx = 0.0 $vy = 0.0 $speed = 1.1 $gravity = 0.25 $jumpForce = 1.6 $isGrounded = $false # Level Platforms (X1, X2, Y-level) $platforms = @( @{X1=10; X2=26; Y=6}, @{X1=30; X2=48; Y=10}, @{X1=52; X2=72; Y=7}, @{X1=18; X2=38; Y=15} ) # Enemies (Goombas) $enemies = @( @{X=15.0; Y=7.0; Dir=-1}, @{X=38.0; Y=11.0; Dir=1}, @{X=60.0; Y=8.0; Dir=-1} ) # Coins $itemCoins = @( @{X=14; Y=7}, @{X=38; Y=11}, @{X=62; Y=8} ) $running = $true while ($running) { # 1. Zero Input Lag: Drain the entire key buffer instantly $moveInput = 0 $jumpRequested = $false while ([Console]::KeyAvailable) { $key = [Console]::ReadKey($true) if ($key.Key -eq 'Q') { $running = $false } if ($key.Key -eq 'A' -or $key.Key -eq 'LeftArrow') { $moveInput = -1 } if ($key.Key -eq 'D' -or $key.Key -eq 'RightArrow') { $moveInput = 1 } if ($key.Key -eq 'W' -or $key.Key -eq 'UpArrow' -or $key.Key -eq 'Spacebar') { $jumpRequested = $true } } # Apply movement velocity instantly based on input if ($moveInput -ne 0) { $vx = $moveInput * $speed } else { $vx *= 0.6 # Quick friction stop when keys are let go } # 2. Physics & Jump Execution $px += $vx if ($px -lt 2) { $px = 2; $vx = 0 } if ($px -gt ($width - 3)) { $px = $width - 3; $vx = 0 } if ($jumpRequested -and $isGrounded) { $vy = $jumpForce $isGrounded = $false } $py += $vy if (-not $isGrounded) { $vy -= $gravity } # Floor collision if ($py -le 1.0) { $py = 1.0 $vy = 0.0 $isGrounded = $true } # Platform collisions $isGrounded = $false foreach ($p in $platforms) { if ($px -ge ($p.X1 - 0.9) -and $px -le ($p.X2 + 0.9)) { if ($py -ge ($p.Y - 0.4) -and $py -le ($p.Y + 0.8) -and $vy -le 0) { $py = [double]$p.Y $vy = 0.0 $isGrounded = $true } } } # 3. Enemy AI & Stomp Detection for ($i=0; $i -lt $enemies.Count; $i++) { $enemies[$i].X += 0.45 * $enemies[$i].Dir if ($enemies[$i].X -lt 2 -or $enemies[$i].X -gt ($width - 3)) { $enemies[$i].Dir *= -1 } # Check collision with Mario if ([Math]::Abs($px - $enemies[$i].X) -lt 0.9 -and [Math]::Abs($py - $enemies[$i].Y) -lt 0.9) { # Stomp Goomba if falling down if ($vy -lt 0 -and $py -ge ($enemies[$i].Y + 0.3)) { $score += 100 $vy = 1.3 # Bounce up off the enemy! $enemies[$i].X = Get-Random -Minimum 10 -Maximum ($width - 10) } else { # Hit by enemy $lives -= 1 $score = [Math]::Max(0, $score - 50) $px = 4.0 $py = 2.0 if ($lives -le 0) { $running = $false } } } } # 4. Coin Collection for ($i=0; $i -lt $itemCoins.Count; $i++) { if ([Math]::Abs($px - $itemCoins[$i].X) -lt 1.0 -and [Math]::Abs($py - $itemCoins[$i].Y) -lt 1.0) { $coins += 1 $score += 200 $itemCoins[$i].X = -999 # Collect coin } } # 5. High-Performance Frame Rendering $sb = [System.Text.StringBuilder]::new() [void]$sb.AppendLine("$CLR_CYAN┌" + ("─" * ($width - 2)) + "┐$CLR_RESET") [void]$sb.AppendLine("$CLR_CYAN│$CLR_RESET $CLR_YELLOW★ COINS: $coins | ❤️ LIVES: $lives | 🏆 SCORE: $score | CONTROLS: A/D/Arrows to Move, W/SPACE to Jump, Q to Quit$CLR_CYAN│$CLR_RESET") [void]$sb.AppendLine("$CLR_CYAN├" + ("─" * ($width - 2)) + "┤$CLR_RESET") $intPx = [int][Math]::Round($px) $intPy = [int][Math]::Round($py) for ($r = $height; $r -ge 1; $r--) { $line = [System.Text.StringBuilder]::new() [void]$line.Append("$CLR_CYAN│$CLR_RESET") for ($c = 1; $c -lt ($width - 1); $c++) { $char = " " $color = "$CLR_RESET" # Draw Mario if ($c -eq $intPx -and $r -eq $intPy) { $char = "M" $color = "$CLR_RED" } else { # Draw Platforms $onPlatform = $false foreach ($p in $platforms) { if ($c -ge $p.X1 -and $c -le $p.X2 -and $r -eq $p.Y) { $char = "▒" $color = "$CLR_GREEN" $onPlatform = $true break } } if (-not $onPlatform) { # Draw Enemies (Goombas) $isEnemy = $false foreach ($e in $enemies) { if ([int][Math]::Round($e.X) -eq $c -and [int][Math]::Round($e.Y) -eq $r) { $char = "G" $color = "$CLR_RED" $isEnemy = $true break } } if (-not $isEnemy) { # Draw Coins foreach ($co in $itemCoins) { if ($co.X -eq $c -and $co.Y -eq $r) { $char = "★" $color = "$CLR_YELLOW" break } } } } } [void]$line.Append("$color$char$CLR_RESET") } [void]$line.Append("$CLR_CYAN│$CLR_RESET") [void]$sb.AppendLine($line.ToString()) } # Ground floor [void]$sb.AppendLine("$CLR_GROUND└" + ("▓" * ($width - 2)) + "┘$CLR_RESET") [Console]::SetCursorPosition(0, 0) [Console]::Write($sb.ToString()) # Ultra-fast tick rate for buttery-smooth motion (approx ~60 FPS feel) Start-Sleep -Milliseconds 10 } [Console]::CursorVisible = $true Clear-Host Write-Host "$CLR_RED========================================" Write-Host " GAME OVER! Final Score: $score | Coins: $coins" Write-Host "========================================"$CLR_RESET