-- fullscreen disp 01 function love.load() -- init -- set filter love.graphics.setDefaultFilter("nearest", "nearest") scr_w = 640 scr_h = 480 canvas = love.graphics.newCanvas(scr_w, scr_h) -- get window width and height wdw_w = love.graphics.getWidth() wdw_h = love.graphics.getHeight() -- load image bgimg = love.graphics.newImage("bg_640x480.png") playerimg = love.graphics.newImage("spaceship_001_64x64.png") -- player work player = {} player.x = scr_w / 2 player.y = scr_h / 2 player.speed = 250 player.imgw = playerimg:getWidth() player.imgh = playerimg:getHeight() end function love.update(dt) -- update -- key check local ang = -1 if love.keyboard.isDown("left") then ang = 180 elseif love.keyboard.isDown("right") then ang = 0 end if love.keyboard.isDown("up") then if ang < 0 then ang = 270 elseif ang == 0 then ang = 270 + 45 else ang = 180 + 45 end elseif love.keyboard.isDown("down") then if ang < 0 then ang = 90 elseif ang == 0 then ang = 45 else ang = 180 - 45 end end if ang >= 0 then local spd = player.speed * dt local ra = math.rad(ang) player.x = player.x + (spd * math.cos(ra)) player.y = player.y + (spd * math.sin(ra)) end -- move area check local wh = player.imgw / 2 local hh = player.imgh / 2 local xmin = wh local ymin = hh local xmax = scr_w - wh local ymax = scr_h - hh player.x = math.min(math.max(player.x, xmin), xmax) player.y = math.min(math.max(player.y, ymin), ymax) end function love.draw() -- set canvas love.graphics.setCanvas(canvas) -- draw BG love.graphics.setColor(255, 255, 255) love.graphics.draw(bgimg, 0, 0) -- love.graphics.rectangle("fill", 0, 465, scr_w, 150) love.graphics.setColor(255, 255, 255) -- draw player ofsx = player.imgw / 2 ofsy = player.imgh / 2 love.graphics.draw(playerimg, player.x - ofsx, player.y - ofsy) -- unset canvas love.graphics.setCanvas() -- draw canvas to window love.graphics.setColor(255, 255, 255) love.graphics.draw(canvas, 0, 0, 0, wdw_w / scr_w, wdw_h / scr_h) love.graphics.print("FPS: "..tostring(love.timer.getFPS()), 10, 10) end function love.keypressed(key, isrepeat) -- ESC to exit if key == "escape" then love.event.quit() end end