2017-05-16 43 views
1

我收到消息「此遊戲表示它是爲LOVE版本'0.9.1'製作的 它可能與正在運行的版本(0.10.2)不兼容。當我嘗試並運行我的比賽時。遊戲仍然有效,但消息讓我很煩惱。我如何將其更新至最新版本?我的代碼是在這裏: 調試=真 Main.lua - 定時器如何讓love2d遊戲兼容

-- We declare these here so we don't have to edit them multiple places 
canShoot = true 
canShootTimerMax = 0.2 
canShootTimer = canShootTimerMax 
createEnemyTimerMax = 0.4 
createEnemyTimer = createEnemyTimerMax 

-- Player Object 
player = { x = 200, y = 710, speed = 150, img = nil } 
isAlive = true 
score = 0 

-- Image Storage 
bulletImg = nil 
enemyImg = nil 

-- Entity Storage 
bullets = {} -- array of current bullets being drawn and updated 
enemies = {} -- array of current enemies on screen 

-- Collision detection taken function from http://love2d.org/wiki/BoundingBox.lua 
-- Returns true if two boxes overlap, false if they don't 
-- x1,y1 are the left-top coords of the first box, while w1,h1 are its width and height 
-- x2,y2,w2 & h2 are the same, but for the second box 
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2) 
    return x1 < x2+w2 and 
     x2 < x1+w1 and 
     y1 < y2+h2 and 
     y2 < y1+h1 
end 

-- Loading 
function love.load(arg) 
    player.img = love.graphics.newImage('assets/plane.png') 
    enemyImg = love.graphics.newImage('assets/enemy.png') 
    bulletImg = love.graphics.newImage('assets/bullet.png') 
end 


-- Updating 
function love.update(dt) 
    -- I always start with an easy way to exit the game 
    if love.keyboard.isDown('escape') then 
     love.event.push('quit') 
    end 

    -- Time out how far apart our shots can be. 
    canShootTimer = canShootTimer - (1 * dt) 
    if canShootTimer < 0 then 
     canShoot = true 
    end 

    -- Time out enemy creation 
    createEnemyTimer = createEnemyTimer - (1 * dt) 
    if createEnemyTimer < 0 then 
     createEnemyTimer = createEnemyTimerMax 

     -- Create an enemy 
     randomNumber = math.random(10, love.graphics.getWidth() - 10) 
     newEnemy = { x = randomNumber, y = -10, img = enemyImg } 
     table.insert(enemies, newEnemy) 
    end 


    -- update the positions of bullets 
    for i, bullet in ipairs(bullets) do 
     bullet.y = bullet.y - (250 * dt) 

     if bullet.y < 0 then -- remove bullets when they pass off the screen 
      table.remove(bullets, i) 
     end 
    end 

    -- update the positions of enemies 
    for i, enemy in ipairs(enemies) do 
     enemy.y = enemy.y + (200 * dt) 

     if enemy.y > 850 then -- remove enemies when they pass off the screen 
      table.remove(enemies, i) 
     end 
    end 

    -- run our collision detection 
    -- Since there will be fewer enemies on screen than bullets we'll loop them first 
    -- Also, we need to see if the enemies hit our player 
    for i, enemy in ipairs(enemies) do 
     for j, bullet in ipairs(bullets) do 
      if CheckCollision(enemy.x, enemy.y, enemy.img:getWidth(), enemy.img:getHeight(), bullet.x, bullet.y, bullet.img:getWidth(), bullet.img:getHeight()) then 
       table.remove(bullets, j) 
       table.remove(enemies, i) 
       score = score + 1 
      end 
     end 

     if CheckCollision(enemy.x, enemy.y, enemy.img:getWidth(), enemy.img:getHeight(), player.x, player.y, player.img:getWidth(), player.img:getHeight()) 
     and isAlive then 
      table.remove(enemies, i) 
      isAlive = false 
     end 
    end 


    if love.keyboard.isDown('left','a') then 
     if player.x > 0 then -- binds us to the map 
      player.x = player.x - (player.speed*dt) 
     end 
    elseif love.keyboard.isDown('right','d') then 
     if player.x < (love.graphics.getWidth() - player.img:getWidth()) then 
      player.x = player.x + (player.speed*dt) 
     end 
    end 

    if love.keyboard.isDown(' ', 'rctrl', 'lctrl', 'ctrl') and canShoot then 
     -- Create some bullets 
     newBullet = { x = player.x + (player.img:getWidth()/2), y = player.y, img = bulletImg } 
     table.insert(bullets, newBullet) 
     canShoot = false 
     canShootTimer = canShootTimerMax 
    end 

    if not isAlive and love.keyboard.isDown('r') then 
     -- remove all our bullets and enemies from screen 
     bullets = {} 
     enemies = {} 

     -- reset timers 
     canShootTimer = canShootTimerMax 
     createEnemyTimer = createEnemyTimerMax 

     -- move player back to default position 
     player.x = 50 
     player.y = 710 

     -- reset our game state 
     score = 0 
     isAlive = true 
    end 
end 

-- Drawing 
function love.draw(dt) 
    for i, bullet in ipairs(bullets) do 
     love.graphics.draw(bullet.img, bullet.x, bullet.y) 
    end 

    for i, enemy in ipairs(enemies) do 
     love.graphics.draw(enemy.img, enemy.x, enemy.y) 
    end 

    love.graphics.setColor(255, 255, 255) 
    love.graphics.print("SCORE: " .. tostring(score), 400, 10) 

    if isAlive then 
     love.graphics.draw(player.img, player.x, player.y) 
    else 
     love.graphics.print("Press 'R' to restart", love.graphics:getWidth()/2-50, love.graphics:getHeight()/2-10) 
    end 

    if debug then 
     fps = tostring(love.timer.getFPS()) 
     love.graphics.print("Current FPS: "..fps, 9, 10) 
    end 
end 

conf.lua

-- Configuration 
function love.conf(t) 
    t.title = "Scrolling Shooter Tutorial" -- The title of the window the game is in (string) 
    t.version = "0.9.1"   -- The LÖVE version this game was made for (string) 
    t.window.width = 480  -- we want our game to be long and thin. 
    t.window.height = 800 

    -- For Windows debugging 
    t.console = true 
end 
+2

您是否嘗試將conf.lua變量't.version'從「0.9.1」更改爲「0.10.2」? –

+0

謝謝!這是一個簡單的錯誤,但我剛開始學習。 –

+1

不兼容錯誤的原因可能是API更改。你可以檢查API的變化[在wiki上](https://love2d.org/wiki/0.10.2) –

回答

2

正如評論所指出的,在你的情況下,問題是在conf.lua中,版本被指定爲"0.9.1"。在某些情況下,將此值更改爲"0.10.2"就足夠了,但在0.9.0和0.10.0之間發生了大量更改。

要特別注意,鼠標輸入是絕對打算0.10.0前被打破,因爲在版本LOVE使用字符串來表示鼠標的按鍵,而在0.10.0及以後,數字被使用。要解決此問題,請查找與鼠標相關的功能(love.mouse.isDownlove.mousepressed等)並將"l"更改爲1,"r"2,依此類推。請參閱完整列表old valueslove.mousepressed瞭解更多信息。此外,鼠標滾輪的移動也發生了變化,並增加了love.wheelmoved回調,並刪除了傳遞到love.mousepressed的字符串。

此外,通過changelog讀取可能影響程序的任何更改。