Workshop › Mario-style Platformer › Step 35 of 37
The flag
What we are doing
The last piece is a goal. The F becomes a flagpole that reaches from row 3 down to the ground, so the player cannot miss
it by jumping over it.
```js
let flag
if (line[col] === 'F') flag = { x: x + 14, y: 3 * TILE, w: 4, h: y + TILE - 3 * TILE }
ctx.fillStyle = '#e5e7eb'
ctx.fillRect(flag.x, flag.y, flag.w, flag.h)
ctx.fillStyle = '#22c55e'
ctx.fillRect(flag.x + flag.w, flag.y, 24, 16)
```
What it means
- The pole is 4 pixels wide in the middle of its tile (14 in), from the top of row 3 to the bottom of the
F tile:
h = y + TILE - 3 * TILE.
- A light gray pole and a green 24×16 flag at its top right, in the world.
Your turn
- Under
let enemies write let flag.
- In
loadLevel, under the 'e' line, write the 'F' line.
- In
draw, above ctx.fillStyle = '#facc15', write the four flag lines and an empty line.
Skills: Game states, Drawing on a canvas
← Play again Reach the flag →
All steps
- The sky
- A level made of text
- Draw the tiles
- What is solid?
- Is a box touching anything?
- Find the start
- Draw the player
- Gravity
- Landing on tiles
- Which keys are held?
- Speed up
- Friction
- Walls
- Jump
- Bump your head
- Short hops
- A few frames of grace
- Coyote time
- A camera that follows
- Stop at the ends
- Draw only what is on screen
- Coins
- Collect them
- Count, and screen versus world
- Enemies
- Enemies that walk
- Do not walk off ledges
- Lives and a fresh start
- Falling into a pit
- Enemies hurt
- Stomp!
- Squashed enemies are gone
- Game over
- Play again
- The flag
- Reach the flag
- Build it yourself: jump buffering