From acf365bf02315225d52995d1216d48313fb16c0d Mon Sep 17 00:00:00 2001 From: Trey Tomes Date: Sun, 31 Dec 2023 22:41:34 -0600 Subject: [PATCH] Simple minimap. --- main.ms | 49 ++++++++++++++++++++++++++++++------------------- src/map.ms | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 19 deletions(-) diff --git a/main.ms b/main.ms index cddbce0..805997d 100644 --- a/main.ms +++ b/main.ms @@ -82,39 +82,48 @@ Display = {} Display.initialize = function() MapDisplay = require("MapDisplay") - // HUD = 0 - // HUD_BACK = 1 - // PARTICLES_0 = 2 - // PARTICLES_1 = 3 - // MAP_0 = 4 - // MAP_1 = 5 - - activate = function(n) - display(n).mode = displayMode.text - display(n).delimiter = "" - return display(n) - end function + PIXEL_0 = 1 - deactivate = function(n) - display(n).mode = displayMode.off - return display(n) - end function + HUD = 2 + HUD_BACK = 3 + + PARTICLES_0 = 4 + PARTICLES_1 = 5 + + MAP_0 = 6 + MAP_1 = 7 - Display.hud = ui.HeadsUpDisplay.make(0, 1) + Display.hud = ui.HeadsUpDisplay.make(HUD, HUD_BACK) + + // display(PIXEL_0).install Display.pixels + // Display.pixels = new PixelDisplay + // Display.pixels.mode = displayMode.pixel + Display.pixels = new PixelDisplay + Display.pixels.install PIXEL_0 - Display.particles = MapDisplay.make(2, 3) + Display.particles = MapDisplay.make(PARTICLES_0, PARTICLES_1) - Display.map = MapDisplay.make(4, 5) + Display.map = MapDisplay.make(MAP_0, MAP_1) end function Display.clear = function() Display.hud.clear() + // Display.pixels.clear() + if display(1).mode == displayMode.off then + Display.pixels = new PixelDisplay + Display.pixels.install 1 //PIXEL_0 + // display(2).mode = displayMode.pixel + // display(2).color = color.clear + // Display.pixels = display(2) + end if + Display.pixels.clear color.clear // Why is this set to "off"??? Display.particles.clear() end function Service = {} // TODO: This may become redundant soon. +// The map owns the entity collection. The rendering should happen there too. drawEntities = function(display, map, renderOffset) // First draw entities that you can step on. for e in map.entities @@ -141,6 +150,8 @@ drawHUD = function(display, player) // display.color = color.white // display.backColor = color.black + // drawMiniMap() + statusBar = "HP: {0}/{1} LVL: {2} XP: {3}/{4} world: {5}".fill([player.currentHP, player.maxHP, player.level, player.xp, player.xpToNextLevel, Service.world.currentLevel]) statusBar = statusBar + " " * (constants.UI_DISPLAY_WIDTH - statusBar.len) diff --git a/src/map.ms b/src/map.ms index f487ec9..7e837c1 100644 --- a/src/map.ms +++ b/src/map.ms @@ -149,16 +149,56 @@ Map.drawTile = function(dsp, x, y, renderOffset=null) if t.isCurrentlyVisible then t.draw(dsp, rx, ry) + + // // Draw minimap. + // c = t.foregroundColor.str() + // Display.pixels.setPixel constants.PIXEL_WIDTH - x - 1, constants.PIXEL_HEIGHT - y - 1, c else if t.hasBeenVisited then t.drawDim(dsp, rx, ry) + + // // Draw minimap. + // c = t.foregroundColor.str() + // Display.pixels.setPixel constants.PIXEL_WIDTH - x - 1, constants.PIXEL_HEIGHT - y - 1, c else dsp.setCell rx, ry, "#", color.black, color.gray + + // // Draw minimap. + // c = color.gray + // Display.pixels.setPixel constants.PIXEL_WIDTH - x - 1, constants.PIXEL_HEIGHT - y - 1, c end if end function +Map.drawMiniMap = function() + Display.pixels.drawRect constants.PIXEL_WIDTH - self.width - 2, constants.PIXEL_HEIGHT - self.height - 2, self.width + 2, self.height + 2, color.brown, 2 + + for y in range(0, self.height) + for x in range(0, self.width) + if self.getTile(x, y).hasBeenVisited then + tile = self.getTile(x, y) + c = tile.foregroundColor.str() + Display.pixels.setPixel constants.PIXEL_WIDTH - (self.width - x) - 1, constants.PIXEL_HEIGHT - (self.height - y) - 1, c + else + c = color.gray + Display.pixels.setPixel constants.PIXEL_WIDTH - (self.width - x) - 1, constants.PIXEL_HEIGHT - (self.height - y) - 1, c + end if + end for + end for + + for e in self.entities + x = e.position.x + y = e.position.y + c = e.tile.foregroundColor.str() + + Display.pixels.setPixel constants.PIXEL_WIDTH - (self.width - x) - 1, constants.PIXEL_HEIGHT - (self.height - y) - 1, c + end for +end function + Map.draw_v1 = function(display, player, renderOffset) halfHeight = constants.TILE_DISPLAY_HEIGHT / 2 - 1 halfWidth = constants.TILE_DISPLAY_WIDTH / 2 - 1 + + self.drawMiniMap() + for y in range(player.position.y - halfHeight, player.position.y + halfHeight + 1 - 1) // The -1 at the end here accounts for a HUD rendering problem. for x in range(player.position.x - halfWidth, player.position.x + halfWidth + 1) self.drawTile display, x, y, renderOffset