Last active
August 29, 2015 14:01
-
-
Save denisdefreyne/53b58182e8e1966f2fd3 to your computer and use it in GitHub Desktop.
CoderDojo Berlin cheat sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- variables | |
distance = 370.52 | |
-- objects (tables) | |
hero = { | |
strength = 7, | |
dexterity = 8, | |
endurance = 6, | |
charisma = 4, | |
wisdom = 4, | |
perception = 8, | |
} | |
star = { | |
x = 430, | |
y = 20, | |
} | |
-- lists a.k.a. arrays (also tables) | |
stars = { | |
{ x = 200, y = 300 }, | |
{ x = 240, y = 40 }, | |
{ x = 360, y = 120 }, | |
{ x = 60, y = 590 }, | |
} | |
-- looping over elements of a list a.k.a. array | |
for index, star in ipairs(stars) do | |
drawStar(star) | |
end | |
-- graphics | |
love.graphics.setColor(r, g, b, a) | |
love.graphics.rectangle("fill", x, y, width, height) | |
love.graphics.polygon("fill", -width/2, 0, width/2, 0, 0, -height) | |
love.graphics.circle("line", x, y, radius, numberOfSides) | |
love.graphics.line(x1, y1, x2, y2) | |
love.graphics.push() | |
love.graphics.translate(x, y) | |
love.graphics.rotate(math.pi/4) | |
love.graphics.pop() | |
love.graphics.getHeight() | |
love.graphics.getWidth() | |
love.graphics.print("Hello world!", 40, 40) | |
love.graphics.printf("Hello world!", 40, 40, love.graphics.getWidth(), "center") | |
-- entry points | |
function love.update(delta) | |
end | |
function love.draw() | |
end | |
-- events ('left', 'right', 'up', 'down', ' ') | |
if love.keyboard.isDown("left") then | |
rect.x = rect.x - 100 * delta | |
end | |
-- math | |
love.math.random(0, 100) | |
math.sin(math.pi/2) | |
math.cos(math.pi/2) | |
math.sqrt(4) | |
math.pow(2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment