Lua Love2D Ошибка: синтаксическая ошибка: main.lua: 1: '=' ожидается - PullRequest
0 голосов
/ 11 декабря 2018

Я пытался создать игру love2d для 2 человек, когда столкнулся с этой ошибкой.Я понятия не имею, как это исправить, и я новичок в love2d.Я пытался просмотреть свой код много раз, но, похоже, не смог найти ответ.Я думал, что это была проблема с моими знаками равенства, поэтому я просматриваю это, и они были в порядке.Итак, кто-нибудь может объяснить, как я получил эту ошибку?Заранее спасибо!

   function love.load()

-- Border Data
    b = {}
    b.y = 0
    b.x = 0

-- Player Data
    p1 = {}
    p2 = {}
    -- Player Positions 
    p1.x = 105
    p1.y = 920
    p2.x = 355
    p2.y = 920
    -- Player Points
    p1.points = 0
    p2.points = 0

    -- Extra Data
    Level = 1
    candrawenemys = true
    p1.won = false
    p2.won = false
    candrawin = false

    function playerWon(player)
        if player == p1 then
            candrawenemys = false
            p1.won = true
            candrawin = true
        elseif player == p2 then
            candrawenemys = false
            candrawin = true
            p2.won = true
        end
    end

-- Enemy Data
    e1 = {}
    e2 = {}
    e3 = {}
    e4 = {}
    e5 = {}
    enemy = {}
    enemy.speed = 2

-- Enemy 1 Data
    e1.y = 170
    e1.x = 0
    e1.speed = enemy.speed
    e1.direction = "front"

-- Enemy 2 Data
    e2.y = 340
    e2.x = 480
    e2.speed = enemy.speed
    e2.direction = "back"

-- Enemy 3 Data
    e3.y = 510
    e3.x = 0
    e3.speed = enemy.speed
    e3.direction = "front"

-- Enemy 4 Data
    e4.y = 680
    e4.x = 480
    e4.speed = enemy.speed
    e4.direction = "back"

-- Enemy 5 Data
    e5.y = 850
    e5.x = 0
    e5.speed = enemy.speed
    e5.direction = "front"

end




function love.update(dt)

-- KEYBOARD Functions
    if love.keyboard.isDown("w") then
        p1.y = p1.y - 3
    end
    if love.keyboard.isDown("s") then
        p1.y = p1.y + 3
    end 
    if love.keyboard.isDown("a") then
        p1.x = p1.x - 3
    end
    if love.keyboard.isDown("d") then
        p1.x = p1.x + 3
    end
    if love.keyboard.isDown("up") then
        p2.y = p2.y - 3 
    end
    if love.keyboard.isDown("down") then
        p2.y = p2.y + 3
    end 
    if love.keyboard.isDown("left") then
        p2.x = p2.x - 3 
    end
    if love.keyboard.isDown("right") then
        p2.x = p2.x + 3
    end

    if candrawin == true then
        if love.keyboard.isDown("r") then
            print("button pressed")
            candrawenemys = true
            p1.won = false
            p2.won = false
            enemy.speed = 2
            e1.y = 170
            e1.x = 0
            e2.y = 340
            e2.x = 480
            e3.y = 510
            e3.x = 0
            e4.y = 680
            e4.x = 480
            e5.y = 850
            e5.x = 0
            p1.x = 105
            p1.y = 920
            p2.x = 355
            p2.y = 920
            candrawin = false
        end
    end

-- Winning
    if p1.points == 1 then
        playerWon(p1)
    elseif p2.points == 1 then
        playerWon(p2)
    end




-- Finish Line Collision
    if p1.x < b.x+500 and b.x < p1.x+20 and p1.y < b.y+50 and b.y < p1.y+30 then
        p1.points = p1.points + 1
        Level = Level + 1
        p1.x = 105
        p1.y = 920
        p2.x = 355
        p2.y = 920
        enemy.speed = enemy.speed + 2
        end
    if p2.x < b.x+500 and b.x < p2.x+20 and p2.y < b.y+50 and b.y < p2.y+30 then
        p2.points = p2.points + 1
        Level = Level + 1
        p1.x = 105
        p1.y = 920
        p2.x = 355
        p2.y = 920
        enemy.speed = enemy.speed + 2
        end

-- Enemies Moving

-- Enemy 1
    if e1.direction == "front" then
        e1.x = e1.x + enemy.speed
    end
    if e1.direction == "back" then

        e1.x = e1.x - enemy.speed
    end

    if e1.x >= 480 then
        e1.direction = "back"
    elseif e1.x <= 0 then
        e1.direction = "front"
    end




-- Enemy 2
    if e2.direction == "front" then
        e2.x = e2.x + enemy.speed
    end
    if e2.direction == "back" then
        e2.x = e2.x - enemy.speed
    end

    if e2.x >= 480 then
        e2.direction = "back"
    elseif e2.x <= 0 then
        e2.direction = "front"
    end




-- Enemy 3
    if e3.direction == "front" then
        e3.x = e3.x + enemy.speed
    end
    if e3.direction == "back" then

        e3.x = e3.x - enemy.speed
    end

    if e3.x >= 480 then
        e3.direction = "back"
    elseif e3.x <= 0 then
        e3.direction = "front"
    end




-- Enemy 4
    if e4.direction == "front" then
        e4.x = e4.x + enemy.speed
    end
    if e4.direction == "back" then

        e4.x = e4.x - enemy.speed
    end

    if e4.x >= 480 then
        e4.direction = "back"
    elseif e4.x <= 0 then
        e4.direction = "front"
    end




-- Enemy 5
    if e5.direction == "front" then
        e5.x = e5.x + enemy.speed
    end
    if e5.direction == "back" then

        e5.x = e5.x - enemy.speed
    end

    if e5.x >= 480 then
        e5.direction = "back"
    elseif e5.x <= 0 then
        e5.direction = "front"
    end

end




function love.draw()
-- Basic Setup

-- Drawing if Won
    if candrawin == true then
        if p1.won == true then
            p1.x = 250
            p1.y = 275
            love.graphics.print("Player 1 Won!", 200, 200, 0, 2,2)
            love.graphics.print("Press 'r' to play again!", 125, 700, 0, 2, 2)
        end
    end
    if candrawin == true then
        if p2.won == true then
            p2.x = 250
            p2.y = 275
            love.graphics.print("Player 2 Won!", 200, 200, 0, 2,2)
            love.graphics.print("Press 'r' to play again!", 125, 700, 0, 2, 2)
        end 
    end

-- Draw Score
    if candrawenemys == true then
        love.graphics.print("Player 1 Points: ".. p1.points, 0, 0, 0, 2, 2)
        love.graphics.print("Player 2 Points: ".. p2.points, 280, 0, 0, 2, 2)
    end

-- Draw Finish Line
    if candrawenemys == true then
        love.graphics.rectangle("line", b.x, b.y, 500, 50)
    end

-- Draw Players
    love.graphics.setColor(0,0,255)
    if p2.won == false then
    love.graphics.rectangle("fill", p1.x, p1.y, 30,30)
    end
    love.graphics.setColor(255,0,0)
    if p1.won == false then
    love.graphics.rectangle("fill", p2.x, p2.y, 30,30)
    end

-- Draw all enemies
    if candrawenemys == true then
        love.graphics.setColor(0,255,0)
        love.graphics.rectangle("fill", e1.x, e1.y, 20,20)
        love.graphics.rectangle("fill", e2.x, e2.y, 20,20)
        love.graphics.rectangle("fill", e3.x, e3.y, 20,20)
        love.graphics.rectangle("fill", e4.x, e4.y, 20,20)
        love.graphics.rectangle("fill", e5.x, e5.y, 20,20)
    end

end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...