163 : Platform patterns

Balthazar:

We need to set a transform. We already have code for this for the player (and monters), but it needs a dir attribute to know if it needs to flip the transform. Since we never flip platforms, we can set the dir to 1 and never change it.

function create_platform(x, y, width, height, pattern) { ... p.width = width; p.height = height; p.origin_x = 0; p.origin_y = 0; p.dir = 1; ... }
function draw_platforms(ctx) { var level = _levels[_game.current_level]; var platforms = level.platforms; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; ctx.fillStyle = "rgb(153, 102, 51)"; ctx.fillRect(platform.x, platform.y, platform.width, platform.height); set_transform(ctx, platform); if (platform.background_color) { ctx.fillStyle = platform.background_color; ctx.fillRect(0, 0, platform.width, platform.height); ctx.strokeStyle = "rgba(0,0,0,0.5)"; ctx.strokeRect(0, 0, platform.width, platform.height); } else { var pat = ctx.createPattern(platform.pattern, "repeat"); ctx.fillStyle = pat; ctx.fillRect(0, 0, platform.width, platform.height); } reset_transform(ctx); } }

Congratulations! You've earned the Platform III - Pattern badge!

GOTO 114 if you already have the Treasure II - Finish badge.

GOTO 100