Beginner Game Programming Workshop (With LÖVE) PDF
Beginner Game Programming Workshop (With LÖVE) PDF
6 function love.draw ()
7 love.graph ic s. dr aw ( bild_aktuell , 0 , 0 )
8 end
love.update() calculates, which of the images is the current one. love.draw() draws it. Both
functions work 60 times per second. The image doesn’t quite fit but we will take care of that later.
16 function love.draw ()
17 love.graph ic s. dr aw ( grasBild , 0 , 0 )
18 love.graph ic s. dr aw ( katzeBild , katzeX , katzeY )
19 love.graph ic s. dr aw ( mausBild , mausX , mausY )
20 end
The code in love.load() changes the screen resolution, loads the images and music, sets position
variables and plays the msuic. love.draw() draws the images, 60 times per second. They don’t quite
fit but we will take care of that later.
7 function love.update ()
8 mausX = mausX + 7
9 if mausX > 800 then
10 mausX = -48
11 mausY = math.random ( 20 , 400 )
12 end
13 if distanz ( katzeX , katzeY , mausX , mausY ) < 40 then
14 quietsch : play ()
15 mausX = 999
16 end
17 if distanz ( katzeX , katzeY , klickX , klickY ) > 8 then
18 diffX = klickX - katzeX
19 diffY = klickY - katzeY
20 norm = math.sqrt ( diffX ^2 + diffY ^2 )
21 einhX = diffX / norm
22 einhY = diffY / norm
23 katzeX = katzeX + einhX * 5
24 katzeY = katzeY + einhY * 5
25 end
26 end
27
21 function love.draw ()
22 for i , zeile in ipairs ( instr ) do -- i is the index , zeile is the value
23 for j , instrument in ipairs ( zeile ) do
24 lg.setColor ( instrument.farbe ) -- Instruments have own colors
25 lg.rectangle ( " fill " , (j -1) * feldb , (i -1) * feldh , feldb , feldh )
26 if instrument.snd : getVolume () == 1 then
27 lg.setColor ( 255 , 255 , 255 , 95 ) -- on / off state is displayed
28 lg.circle ( " fill " , (j -0 .5 ) * feldb , (i -0 .5 ) * feldh , feldb *0 .4 )
29 end
30 end
31 end
32 end
33
LÖVE draws pictures and shapes using positions in a coordinate system, which originates from the top
left corner towards right and down.
LÖVE is the game engine used in this workshop. More information about LÖVE programming is available
at love2d.org/wiki/love .