Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Game = {
- Ticks = 0,
- Window = {0, 0},
- VisibleTiles = {0, 0},
- Redraw = true
- }
- local UnitDraw = {}
- local Board = {}
- function NewBoard(width, height)
- local New = {}
- for y = 1, height do
- New[y] = {}
- for x = 1, width do
- New[y][x] = 0
- end
- end
- return New
- end
- function on.create()
- Board = NewBoard(100, 100)
- end
- function on.paint(gc)
- gc:setColorRGB(0, 0, 0)
- gc:setFont("serif", "r", 12)
- gc:drawString(DrawBoard(1, 1), 0, 0)
- gc:drawRect(0, 0, Game.Window[1] * 0.9, Game.Window[2] * 0.9)
- end
- function DrawBoard(fromx, fromy)
- local DrawString = ""
- for y = fromy, #Board do
- if (y - fromy > Game.VisibleTiles[2]) then
- break
- end
- for x = fromx, #Board[y] do
- if (x - fromx > Game.VisibleTiles[1]) then
- break
- end
- if (Board[y][x] == 0) then
- DrawString = DrawString .. math.random(0, 9)
- else
- --TODO: Draw other types
- end
- end
- DrawString = DrawString .. "\n"
- end
- return DrawString
- end
- function on.timer()
- Game.Ticks = Game.Ticks + 1
- Game.Redraw = true
- if (Game.Redraw) then
- Game.Redraw = false
- platform.window:invalidate()
- end
- end
- function on.activate()
- timer.start(1 / 30)
- Game.Redraw = true
- end
- function on.deactivate()
- timer.stop()
- end
- function on.resize(width, height)
- Game.Window = {width, height}
- CalculatePercents()
- end
- function CalculatePercents()
- local gc = platform.gc()
- gc:begin()
- Game.VisibleTiles = {math.floor((Game.Window[1] * 0.9) / gc:getStringWidth("0")), math.floor((Game.Window[2] * 0.9) / gc:getStringHeight("0"))}
- gc:finish()
- Game.Redraw = true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement