Skip to content

Instantly share code, notes, and snippets.

@robinp
Created Apr 13, 2020
Embed
What would you like to do?
Source for Lua+Löve game programming tutorial, part 01
print("Hello")
kartyak = 8
kartyaFelforditva = {
[1] = false,
[2] = false,
[3] = false,
[4] = false,
[5] = false,
[6] = false,
[7] = false,
[8] = false
}
kartyaSzin = {
[1] = "sarga",
[2] = "sarga",
[3] = "kek",
[4] = "kek",
[5] = "lila",
[6] = "lila",
[7] = "piros",
[8] = "piros"
}
function shuffle(array)
-- fisher-yates
local output = { }
local random = math.random
for index = 1, #array do
local offset = index - 1
local value = array[index]
local randomIndex = offset*random()
local flooredIndex = randomIndex - randomIndex%1
if flooredIndex == offset then
output[#output + 1] = value
else
output[#output + 1] = output[flooredIndex + 1]
output[flooredIndex + 1] = value
end
end
return output
end
math.randomseed(os.time()) -- be sure to set randomseed somewhere for better randomness
kartyaSzin = shuffle(kartyaSzin)
function love.mousepressed(egerX, y)
for i=1,kartyak do
local xEleje = 10 + i*70
local xVege = xEleje + 50
if egerX > xEleje and egerX < xVege
then
kartyaFelforditva[i] = not kartyaFelforditva[i]
end
end
end
function love.draw()
love.graphics.setColor(0, 0.5, 0)
love.graphics.rectangle("fill", 0, 0, 600, 500)
love.graphics.setColor(1.0, 0, 1.0)
love.graphics.print('Hello World!', 400, 300)
for i=1,kartyak do
local x = 10 + i*70
local y = 200
if kartyaFelforditva[i]
then
if kartyaSzin[i] == "kek" then love.graphics.setColor(0.0, 0.0, 1.0)
elseif kartyaSzin[i] == "sarga" then love.graphics.setColor(1.0, 1.0, 0.0)
elseif kartyaSzin[i] == "piros" then love.graphics.setColor(1.0, 0.0, 0.0)
elseif kartyaSzin[i] == "lila" then love.graphics.setColor(1.0, 0.0, 1.0)
else love.graphics.setColor(0.0, 0.0, 0.0)
end
else
love.graphics.setColor(1, 1, 1)
end
love.graphics.rectangle("fill", x, y, 50, 50)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment