Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function love.load()
- tiles = { --random map with the "tiles"
- {0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,0,0,0},
- }
- mouselock = false -- you can ignore this mouse lock stuff, its just a trick i use to force a single click...
- function random(mx,my)
- local x1 = math.random(-1,1) --random function to get the x variation
- local x2 = math.random(-1,1) --random function to get the y variation
- local rmx = mx+x1
- local rmy = my+x2
- -- some checks to not crash the code with a outside position
- if rmx < 1 then rmx = 1 end
- if rmx > 5 then rmx = 5 end
- if rmy < 1 then rmy = 1 end
- if rmy > 5 then rmy = 5 end
- return rmx,rmy
- end
- end
- function love.update()
- if love.mouse.isDown(1) and not mouselock then -- random stuff is triggered with a mouse click
- mouselock = true
- local mx,my = love.mouse.getPosition() -- using the mouse position as the center
- mx = math.floor(mx/160)+1 -- converting mouse x to a map coordenate
- my = math.floor(my/120)+1 -- converting mouse y to a map coordenate
- tiles[my][mx] = 1 -- changing the center red to visualize the origin
- local rmx,rmy = random(mx,my) --function gets the mouse coordenate, and return a valid random position around it
- tiles[rmy][rmx] = 2 -- changing a random tile around the center
- end
- function love.mousereleased()
- mouselock = false
- end
- end
- function love.draw()
- local x,y = 0,0
- for j=1,5,1 do
- for i=1,5,1 do
- if tiles[j][i] == 0 then -- empty "tile"
- love.graphics.setColor(1,1,1)
- love.graphics.rectangle("fill",x,y,160,120)
- love.graphics.setColor(0,0,0)
- love.graphics.rectangle("line",x,y,160,120)
- end
- if tiles[j][i] == 1 then -- center "tile"
- love.graphics.setColor(1,0,0)
- love.graphics.rectangle("fill",x,y,160,120)
- love.graphics.setColor(0,0,0)
- love.graphics.rectangle("line",x,y,160,120)
- end
- if tiles[j][i] == 2 then -- random generated "tile"
- love.graphics.setColor(0,0,1)
- love.graphics.rectangle("fill",x,y,160,120)
- love.graphics.setColor(0,0,0)
- love.graphics.rectangle("line",x,y,160,120)
- end
- x = x+160
- end
- x = 0
- y = y+120
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement