--{Load}--

function love.load()
    target = {}
    target.x = 300
    target.y = 300
    target.radius = 50

    score = 0
    timer = 0

    gameFont = love.graphics.newFont('fonts/Daydream.ttf', 40)

    math.randomseed(os.time())
    red = math.random(1, 255)
    green = math.random(1, 255)
    blue = math.random(1, 255)

    anim8 = require 'libraries/anim8'
    love.graphics.setDefaultFilter("nearest", nearest)

    sti = require 'libraries/sti'
    gameMap = sti('maps/mainMap.lua')

    player = {} 
    player.x = 400
    player.y = 400
    player.speed = 4
    player.runSpeed = 6
    player.spriteSheet = love.graphics.newImage('sprites/Slime1_Walk_full.png')
    player.runSpriteSheet = love.graphics.newImage('sprites/Slime1_run_full.png')
    player.runGrid = anim8.newGrid(64, 64, player.runSpriteSheet:getWidth(), player.runSpriteSheet:getHeight())
    player.grid = anim8.newGrid(64, 64, player.spriteSheet:getWidth(), player.spriteSheet:getHeight())

    player.animations = {}
    player.animations.down = anim8.newAnimation(player.grid('1-8', 1), 0.05)
    player.animations.up = anim8.newAnimation(player.grid('1-8', 2), 0.05) 
    player.animations.left = anim8.newAnimation(player.grid('1-8', 3), 0.05) 
    player.animations.right = anim8.newAnimation(player.grid('1-8', 4), 0.05)
    player.animations.run_down = anim8.newAnimation(player.runGrid('1-8', 1), 0.05)
    player.animations.run_up = anim8.newAnimation(player.runGrid('1-8', 2), 0.05)
    player.animations.run_left = anim8.newAnimation(player.runGrid('1-8', 3), 0.05)
    player.animations.run_right = anim8.newAnimation(player.runGrid('1-8', 4), 0.05)
    
    player.anim = player.animations.left

end


--{Update}--

function love.update(dt)
    local isMoving = false
    local isRunning = love.keyboard.isDown("lshift")

    --{PlayerMovements}--

    if love.keyboard.isDown("d") then
        if isRunning then
            player.x = player.x + player.runSpeed
            player.anim = player.animations.run_right
        else
            player.x = player.x + player.speed
            player.anim = player.animations.right
        end
        isMoving = true
    end

    if love.keyboard.isDown("a") then
        if isRunning then
            player.x = player.x - player.runSpeed
            player.anim = player.animations.run_left
        else
            player.x = player.x - player.speed
            player.anim = player.animations.left
        end
        isMoving = true
    end

    if love.keyboard.isDown("s") then
        if isRunning then
            player.y = player.y + player.runSpeed
            player.anim = player.animations.run_down
        else
            player.y = player.y + player.speed
            player.anim = player.animations.down
        end
        isMoving = true
    end

    if love.keyboard.isDown("w") then
        if isRunning then
            player.y = player.y - player.runSpeed
            player.anim = player.animations.run_up
        else
            player.y = player.y - player.speed
            player.anim = player.animations.up
        end
        isMoving = true
    end

    if love.keyboard.isDown("backspace") then
        player.x = 100
        player.y = 100
        isMoving = true
    end

    if isMoving == false then
        player.anim:gotoFrame(1)
    end

    player.anim:update(dt)
end

function love.draw()
    gameMap:draw(160, 65)

    love.graphics.setBackgroundColor(0, 0, 0)

    love.graphics.circle("fill", target.x, target.y, target.radius)

    love.graphics.setColor(1, 1, 1)
    love.graphics.setFont(gameFont)
    love.graphics.print(score, 0, 0)

    if love.keyboard.isDown("lshift") then
        player.anim:draw(player.runSpriteSheet, player.x, player.y, nil, 1.5, 1.5)
    else
        player.anim:draw(player.spriteSheet, player.x, player.y, nil, 1.5, 1.5)
    end
end

function love.mousepressed( x, y, button, istouch, presses )
    if button == 1 then
        local mouseToTarget = distanceBetween(x, y, target.x, target.y)
        if mouseToTarget < target.radius then
            score = score + 1
            target.x = math.random(target.radius, love.graphics.getWidth() - target.radius)
            target.y = math.random(target.radius, love.graphics.getHeight() - target.radius)
        end
    end
end

function distanceBetween(x1, y1, x2, y2)
    return math.sqrt( (x2 - x1)^2 + (y2 - y1)^2 )
end

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: