Page 1 of 1

How to make a Tile?

Posted: Wed Aug 26, 2015 8:56 pm
by CloudyYard
Hello everyone!,
i need help how to make a tile in Love2D!!

i made the game in Quby with play my code but i do not how to make in Love2D!

code in quby:

Code: Select all

$tile = new Image("tile.png")

$size = 20

$w = 31
$h = 20

$blocks = {
    :stone : [2, 0],
    :air : [0, 0],
    :dirt : [1, 0]
}

class Block
    def new(id)
        @id = id
    end
    def getId()
        return @id
    end
    def setId(id)
        @id = id
    end
end

class Level
    def new(w, h)
        @map = []
        @w = w
        @h = h
        initLevel()
        //generateLevel()
    end
    def initLevel()
        @map = []
        @w.times() do |x|
            @map[x] = []
            @h.times() do |y|
                @map[x][y] = new Block($blocks[:stone])
                if rand(10) >= 5
                    @map[x][y] = new Block($blocks[:dirt])
                end
            end
        end
    end
    def generateLevel()
        @w.times() do |x|
            @h.times() do |y|
                if x == y
                    @map[x][y].setId($blocks[:stone])
                end
            end
        end
    end
    def tick()
    end
    def render()
        @w.times() do |x|
            @h.times() do |y|
                id = @map[x][y].getId()
                drawImage( $tile,  id[0]*$size, id[1]*$size, $size, $size, x*$size, y*$size )
            end
        end
    end
end

level = new Level($w, $h)

onEachFrame() do
    fill( :blue )
    
    level.tick()
    level.render()
end
help-me!!

Re: How to make a Tile?

Posted: Thu Aug 27, 2015 11:07 pm
by Robin
Do you know Lua? If so, simply translate the code from Quby to Lua and you'll be 90% there, and we can help you with the final 10%. If not, you'll need to learn Lua first. I suggest reading Programming in Lua.

Re: How to make a Tile?

Posted: Fri Aug 28, 2015 5:00 am
by CloudyYard
I do not know how to translate this:

$ blocks = {
     : stone: [2 0]
     : air: [0, 0]
     : dirt: [1, 0]
}

does someone help me ?.

Re: How to make a Tile?

Posted: Fri Aug 28, 2015 5:56 am
by zorg
yes, i can, and i will: here.
Let me give you a hint, you will need to use the same thing for the classes as well... at least, that would be the easiest solution.

Re: How to make a Tile?

Posted: Fri Aug 28, 2015 9:38 am
by Roland_Yonaba
I just think I'll second Robin's advice, and strongly insist upon it.
Robin wrote:Do you know Lua? If so, simply translate the code from Quby to Lua and you'll be 90% there, and we can help you with the final 10%. If not, you'll need to learn Lua first. I suggest reading Programming in Lua.
Yeah, go learn Lua first. At least, the basics.
Learn a bit about programmng, in general.
Then, come back on your game, and try to port it to Lua. At this time we can help. Otherwise, you will keep asking everytime to translate portions of your code for you, and obviously you are not going to learn anything.

Re: How to make a Tile?

Posted: Fri Aug 28, 2015 2:18 pm
by CloudyYard
Ok, sorry.

It is that I am a Newbie in programming and I am thrilled to create my game!

Thanks for all.