Mario KLine Platformer
- Utilità
-
Yu Zhang
I am a senior practitioner in Fintech industry.
And I have done a lot of academic research on financial markets.
From 2012, I work as a Quant.
Forex, stock and futures are my main trading varieties.
I can use MQL4, MQL5, C++, MySql, and Python. - Versione: 1.0
- Attivazioni: 20
# Mario KLine Platformer - Side-scrolling Candlestick Platformer 🎮📊
`Mario KLine Platformer` is an incredibly creative side-scrolling platformer game for MetaTrader 5 (MT5). this script cleverly merges financial charts with classic Super Mario-style mechanics—**using the real-time candlestick data (OHLC) of the current chart as the level terrain**. Run, jump, and shoot fireballs across market trends in a unique "chart adventure"!
---
## 🌟 Key Concepts & Features
1. **Candlesticks as Playable Terrain (K-Line Terrain)**
* Upon launch, the game fetches historical candlestick data (Open, High, Low, Close) from the active chart and translates it into grounds and cliffs.
* Green bull candles and red bear candles form steps of various heights. The tops of the candle bodies serve as the walkable floor. Shadows and high-light borders add retro-style 3D aesthetics to the charts.
* **Market Trends Dictate Difficulty**: A strong uptrend creates steep "mountains" to climb, while a severe downtrend forms deep "gorges" that require precise jumps to cross.
2. **Upgrades & Power-Up System**
* Hitting the floating golden Question Blocks randomly spawns different power-ups:
* 🍄 **Super Mushroom**: Enlarges Mario's sprite (up to 40 pixels taller) and upgrades the growth level (up to 5). Each level acts as a shield, absorbing one hit of damage.
* 🔥 **Fire Flower**: Upgrades Mario's shooting capability up to level 5. Higher levels allow shooting more fireballs simultaneously (multi-directional spread), at faster speeds, and with reduced cooldown.
* 🪙 **Coins**: Hits the coin blocks to bounce gold coins and immediately gain 200 points.
3. **Diverse Enemies & Mini-Boss Encounters**
* **Goombas (Regular Enemies)**: Patrol between candlestick ledges, jump randomly, and shoot dark-purple energy bullets towards Mario.
* **Mini-Bosses**: Spawn at parameter-defined intervals of candlesticks. Boasting 5 HP (with a health bar displayed above), golden crowns, and purple armor, they shoot a 3-way spread of projectiles.
* **Combat Mechanics**: You can eliminate enemies by jumping on top of their heads (instantly kills Goombas, deals 1 damage to Bosses and triggers a high bounce) or by shooting them with fireballs.
4. **Advanced Movement Mechanics**
* **Step Assist**: Mario automatically steps onto low candle edges, saving you from constant jumping.
* **Wall Slide & Wall Jump**: When airborne next to a high wall, holding the direction key triggers a slow slide. Pressing the Jump key during a slide performs a Wall Jump off the wall in the opposite direction, allowing you to scale high walls easily.
5. **Built-in 2D Software Rasterizer**
* The game requires no external GDI dependencies. It utilizes MQL5's raw pixel buffer arrays (`g_image[]`) to draw pixels and shapes (`FillRect`), which are updated inside an `OBJ_BITMAP_LABEL` resource.
* Immersive background system: Gradient skies, a glowing sun, parallax scrolling clouds (0.3x speed) and far-mountains (0.5x speed), overlayed with trading grid lines.
---
## 🕹️ Controls Guide
* **←** and **→**: Move Mario left and right.
* **↑**: Jump. Press when sliding on a wall to trigger a "Wall Jump".
* **Ctrl (Control)**: Shoot fireballs (Requires Fire Flower level $\ge 1$).
* **Enter**: Restart/Reset the game.
* **ESC**: Exit the game and restore the normal chart view.
---
## 🛠️ Code Architecture
The codebase is clean and follows standard retro game loop designs:
1. **`BuildTerrain()` (Terrain Builder)**
* Downloads current candlestick OHLC data (up to 10,000 bars) and maps price ranges to screen pixels (a typical candlestick occupies 32 horizontal pixels and roughly 110 vertical pixels).
* Stores values into `g_highH`, `g_lowH`, `g_bodyTopH`, `g_bodyBotH` arrays.
2. **`SpawnEnemies()` & `SpawnBoxes()` (Scene Generators)**
* Spawns enemies, bosses, and items based on mathematical distributions across the candlesticks.
* Generates blocks at 110 pixels above the candle heights.
3. **`UpdateGame(double dt)` (Game State Tick)**
* Computes player positions, gravity physics, collision with the terrain, and wall slide inputs.
* Checks block-head-hits, updates power-up movements, and handles item collection.
* Handles bullet movements, bullet-to-enemy damage, and enemy-to-player collisions.
* Stage completion: If the player coordinates `g_px` reach the final candlestick, it triggers the victory state (+1,000 points and shows completion message).
4. **`RenderGame()` & `DrawMario()` (Pixel Rasterizer)**
* Draws sky gradients, shifts parallax mountains and clouds relative to camera `g_camX`.
* Loops through visible ranges to draw candlesticks, flags, blocks, particles, and health bars.
* Renders the animated Mario sprite (alternating leg frames for walk cycle) and flashes the sprite during invincibility frames.
---
## ⚙️ Configuration Parameters
Adjust these settings when launching the script:
* **InpMaxBars** (`Candlesticks Count`): Default `1000`. Set the total length of the level (up to 10,000 bars).
* **InpBossBars** (`Boss Interval`): Default `100`. Defines how many candlesticks pass before a Mini-Boss spawns.
---
## 🚀 How to Run
1. Open MetaTrader 5.
2. Select your desired symbol and chart timeframe (e.g., EURUSD, H1).
3. In the "Navigator" window, browse to **Scripts -> My_Scripts -> 3D动画 -> Mario_KLine_Platformer**.
4. Double-click or drag `Mario_KLine_Platformer` onto the chart.
5. Set the level parameters in the dialog box, then click "OK".
6. The chart will be hidden, and the game will begin. Press **ESC** at any time to return to your normal trading chart.
---

