How to make a Tile?
Posted: Wed Aug 26, 2015 8:56 pm
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:
help-me!!
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