[solved]issues with an isometric map

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Pospos
Citizen
Posts: 68
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

[solved]issues with an isometric map

Post by Pospos » Sun Jun 17, 2018 9:17 pm

Hi, i'm working on an isometric game engine and i have stumbled upon some issues,
especially with the height map. I wanted to make a height map such as these

Image

So, ive been dealing with a progamming problem, which is that i know how to draw the tiles
according to a for loop, but i want to draw them multiple times according to a value.
Attachments
isometric_heightmap.love
(16.67 KiB) Downloaded 21 times
Last edited by Pospos on Wed Jun 20, 2018 8:52 pm, edited 1 time in total.
ⵜⴰⵎⴰⵣⵉⵖⵜ(https://en.wikipedia.org/wiki/Berbers)

Nelvin
Prole
Posts: 40
Joined: Mon Sep 12, 2016 7:52 am

Re: issues with an isometric map

Post by Nelvin » Mon Jun 18, 2018 5:22 am

You just have a typo (I guess) as, in Map:draw you use the height instead of height_size to calculate the yoffset and color gradient of your tiles.

User avatar
Pospos
Citizen
Posts: 68
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

Re: issues with an isometric map

Post by Pospos » Mon Jun 18, 2018 11:29 am

this doesn't work because it creates a block where everything is the same size like this

Image
https://imgsafe.org/image/7973d22185

i want everything to match the height listed here
ⵜⴰⵎⴰⵣⵉⵖⵜ(https://en.wikipedia.org/wiki/Berbers)

Nelvin
Prole
Posts: 40
Joined: Mon Sep 12, 2016 7:52 am

Re: issues with an isometric map

Post by Nelvin » Mon Jun 18, 2018 2:25 pm

Ah yeah, I just guessed the solution as that was the obvious problem with regards to the height.

Here's a kind of "fixed" version that does remotely what you aim for (only quick fixed in terms of, a hacky version to show off how it's basically down, it's not a version to keep building upon, does just use a single tile etc.)
I highly recommend you start doing some simpler stuff first though.

Code: Select all


local Map = {} -- Map object

Map.MAP = {}
Map.heightmap = {}
Map.Img_Tiles = {} -- Tiles name

Map.Img_Tiles[1] = love.graphics.newImage("assets/tile1.png")
Map.Img_Tiles[2] = love.graphics.newImage("assets/tile2.png")
Map.Img_Tiles[3] = love.graphics.newImage("assets/tile3.png")

local MAX_HEIGHT = 8

function Map:set()
    self.mapWidth = 30
    self.mapHeight = 30
    self.MAP = {}
    for y = 1, self.mapHeight do
        self.MAP[y] = {}
        local row = self.MAP[y]
        for x = 1, self.mapWidth do
            local h = math.min( love.math.noise(1.13+x*0.056, 1.76 + y*0.047)*MAX_HEIGHT+1, MAX_HEIGHT )
            row[x] = math.floor(h)
        end
    end
end

function Map:draw(camera, tile_size)
    local num, edge
    edge = tile_size[2]/2
    local num = 1

    for line =1, self.mapHeight do
        for column =1, self.mapWidth do
            local height = Map.MAP[line][column]

            if height >= 0 then
                local x =  (column - line)* tile_size[1]/2
                local y =  (column+1 + line+1)* tile_size[2]/2

                 -- draws the map according to the tiles and camera position
                for tileZ = 0, height do -- draws a the height according to the height map
                    local col = 100 + tileZ * 30
                    love.graphics.setColor( col, col, col ) -- sets a color according to height
                    love.graphics.draw(Map.Img_Tiles[num], x + camera.x, (y - tileZ * edge) + camera.y, 0, 1/camera.scale)

                    love.graphics.setColor(255, 255, 255)
                end
            end
        end
    end
end

return Map

User avatar
Pospos
Citizen
Posts: 68
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

Re: issues with an isometric map

Post by Pospos » Wed Jun 20, 2018 8:50 pm

Thank you!
ⵜⴰⵎⴰⵣⵉⵖⵜ(https://en.wikipedia.org/wiki/Berbers)

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests