From 9fd2b0e21b424178d620cf8c0511dce016fba175 Mon Sep 17 00:00:00 2001 From: HyperOnion <> Date: Sat, 24 Jun 2023 12:03:08 +0200 Subject: [PATCH] create basic paint tile type and some controls for creating paint. --- js/graphics.mjs | 5 +++++ js/player.mjs | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/js/graphics.mjs b/js/graphics.mjs index ea9470c..d7e68f8 100644 --- a/js/graphics.mjs +++ b/js/graphics.mjs @@ -45,6 +45,11 @@ export function draw_world (box, start_x = 0, start_y = 0, scale = BASE_SCALE) { draw_world(tile.box, start_x + visual_x, start_y + visual_y, scale / world.BOX_SIZE); break; } + case "paint": { + graphics.set_color(tile.color); + draw_tile(start_x + visual_x, start_y + visual_y, scale); + break; + } } }); diff --git a/js/player.mjs b/js/player.mjs index c91f2d7..c15094d 100644 --- a/js/player.mjs +++ b/js/player.mjs @@ -4,7 +4,7 @@ import * as entity from "./entity.mjs"; -const player = entity.create(world.get_root(), 2, 1, "#0f0"); +const player = entity.create(world.get_root(), 2, 1, "#080"); @@ -35,3 +35,16 @@ on_press(" ", _ => { export function get_player_box () { return player.box; } + +function set_painting_key (key, color) { + on_press(key, _ => { + world.set_tile(player.box, player.x, player.y, { + type: "paint", + color, + }); + }); +} + +set_painting_key("q", "#f00"); +set_painting_key("w", "#0f0"); +set_painting_key("e", "#00f");