lua Ошибка: попытка вызвать глобальный класс (логическое значение) - PullRequest
0 голосов
/ 18 апреля 2020

Я новичок в lua языке. Я скачал файл класса. lua из github. Я написал код для разработки игры, создав классы в lua с помощью фреймворка love2d. Я делал игру в понг, которая требует весла и мяча, но она выдает мне такую ​​ошибку:

Ошибка

Ball.lua:2: attempt to call global 'Class' (a boolean value)


Traceback  
Ball.lua:2: in main chunk  
[C]: in function 'require'  
main.lua:6: in main chunk  
[C]: in function 'require'  
[C]: in function 'xpcall'  
[C]: in function 'xpcall'  

Я потратил так много времени, чтобы решить, но ничего не происходит.

main. lua

код:

push =require 'push'
Class=require 'class'

require  "Ball"
require  "Paddle"
WINDOW_WIDTH=1280
WINDOW_HEIGHT=720

VIRTUAL_WIDTH=432
VIRTUAL_HEIGHT=243

--speed at which we will move our paddles; multiplied by dt in update
PADDLE_SPEED=200

function love.load()


    love.graphics.setDefaultFilter('nearest','nearest')
    --more 'retro-looking' font object we can use for any text
    --os.time() give the time from 1 jan 1970
    math.randomseed(os.time())
    smallFont=love.graphics.newFont('font.ttf',8)
    --set love2d active font to the small font object
    scoreFont=love.graphics.newFont('font.ttf' , 32)
    --larger font for drawing the score on the screen
    love.graphics.setFont(smallFont)
    --initialize window with virtual resolution 
    push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT,WINDOW_WIDTH,WINDOW_HEIGHT,{
        fullscreen=false,
        resizable=false,
        vsync=true
    })
    --Paddle(x,y,width,height)
    player1=Paddle(10,30,5,20)
    player2=Paddle(VIRTUAL_WIDTH-10,VIRTUAL_HEIGHT-30,5,20)
    --place a  ball in the middle of the screen 
    ball=Ball(VIRTUAL_WIDTH/2-2,VIRTUAL_HEIGHT/2-2,4,4)

    gameState='start'
end 
function love.update(dt)
    --player 1 movement
    if love.keyboard.isDown('w') then
        --add negative paddle speed to current Y scaled by deltaTime
        player1.dy=-PADDLE_SPEED
        --player1Y= math.max ( 0, player1Y + -PADDLE_SPEED * dt)
    elseif love.keyboard.isDown('s') then
        --add positive paddle speed to current Y scaled by deltaTime    
        player1.dy=PADDLE_SPEED
    else
        player.dy=0        
        --player1Y = math.min ( VIRTUAL_HEIGHT -20 , player1Y + PADDLE_SPEED * dt)    
    end
    --player 2 movement
    if love.keyboard.isDown('up') then
        --add negative paddle speed to current Y scaled by deltaTime
        player2.dy=-PADDLE_SPEED
        --player2Y=math.max( 0, player2Y + -PADDLE_SPEED * dt)
    elseif love.keyboard.isDown('down') then
        player2.dy=PADDLE_SPEED
    else
        player2.dy=0
    end

    if gameState=='play' then 
        ball:update(dt)
    end
    player1:update(dt)
    player2:update(dt)
end                 
function love.keypressed(key)
   --key can be acessed by sting name
   if key=='escape' then
         --function love give us to terminate application
         love.event.quit()
   elseif key == 'enter' or key == 'return' then
       if gameState == 'start' then
           gameState = 'play'
       else
           gameState = 'start'

           ball:reset()
       end   
   end     
end
function love.draw()
   --begin rendering at virtual screen
   push:apply('start')
   --recent versions  of pong has grey color it sets grey color
   love.graphics.clear( 0 , 0 , 0 , 255)
   --note we are now using virtual width and height now for text placement
   --draw welcome text  on top of the screen 
   love.graphics.setFont(smallFont)
   if gameState == 'start' then
      love.graphics.printf('hello start state!', 0 , 20 , VIRTUAL_WIDTH , 'center' )
   else
      love.graphics.printf('hello play state!', 0 , 20 , VIRTUAL_WIDTH , 'center')
   end
   love.graphics.setFont(scoreFont)
   love.graphics.print(tostring(player1Score),VIRTUAL_WIDTH / 2 - 50 , VIRTUAL_HEIGHT / 3)
   love.graphics.print(tostring(player2Score),VIRTUAL_WIDTH / 2 + 30 , VIRTUAL_HEIGHT / 3)

   player1:render()
   player2:render()

   ball:render()
   --end rendering at virtual resolution 
   push:apply('end')
end             

Ball. lua

код:

--making a Ball class
Ball = Class{}
function Ball:init(x,y,width,height)
    self.x=x
    self.y=y
    self.width=width
    self.height=height
    self.dy=math.random(2) ==1 and -100 or 100
    self.dx=math.random(-50,50)
end

--[[places the ball in the middle of the screen with an
initial random velocity on both axes.]]

function Ball:reset()
    self.x=VIRTUAL_WIDTH/2-2
    self.y=VIRTUAL_HEIGHT/2-2
    self.dy=math.random(2) == 1 and -100 or 100
    self.dx=math.random(-50,50)
end
function Ball:update(dt)
    self.x=self.x+self.dx * dt
    self.y=self.y+self.dy * dt
end
function Ball:render()
    love.graphics.rectangle('fill',self.x,self.y,self.width,self.height)
end     
return Ball

PLZ, помогите мне в этом вопросе.
Заранее спасибо.

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