How to make a Tile?

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
CloudyYard
Prole
Posts: 12
Joined: Fri Jul 03, 2015 8:54 pm

How to make a Tile?

Post 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!!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to make a Tile?

Post 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.
Help us help you: attach a .love.
CloudyYard
Prole
Posts: 12
Joined: Fri Jul 03, 2015 8:54 pm

Re: How to make a Tile?

Post by CloudyYard »

I do not know how to translate this:

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

does someone help me ?.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to make a Tile?

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: How to make a Tile?

Post 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.
CloudyYard
Prole
Posts: 12
Joined: Fri Jul 03, 2015 8:54 pm

Re: How to make a Tile?

Post by CloudyYard »

Ok, sorry.

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

Thanks for all.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Semrush [Bot] and 3 guests