local x = 20 -- image code local images = {} local image local quad local t = 0 -- gen code local PI_QUARTER = math.pi/4 local TWO_PI = 2*math.pi local arc_start = PI_QUARTER local arc_end = TWO_PI - PI_QUARTER local animation_value = PI_QUARTER local animation_state = 1 function love.load() love.window.setTitle('Pacman') love.window.setMode( 800, 150) -- image code images[1] = love.graphics.newImage('pacman1.png') images[2] = love.graphics.newImage('pacman2.png') images[3] = love.graphics.newImage('pacman3.png') quad = love.graphics.newQuad(0, 0, 20, 20, 20, 20) image = images[1] end function love.draw() -- image code love.graphics.draw(image, quad, x, 100) -- gen code love.graphics.setColor(unpack({255, 255, 0})) love.graphics.arc("fill", x + 10, 60, 10, arc_start-animation_value, arc_end+animation_value, 100) end function love.update(dt) -- image code t = t + dt * 6 if t < 1 then image = images[1] elseif t < 2 then image = images[2] elseif t < 3 then image = images[3] elseif t < 4 then image = images[2] else t = 0 end -- gen code arc_start = PI_QUARTER arc_end = TWO_PI - PI_QUARTER if animation_value >= PI_QUARTER then animation_state = 2 elseif animation_value <= 0 then animation_state = 1 end if animation_state == 1 then -- close mouth animation_value = animation_value + dt * 3 elseif animation_state == 2 then -- open mouth animation_value = animation_value - dt * 3 end x = x + 50 * dt if x > 800 then x = -20 end end