Syntax Error: main.lua:252: end expected (to close function at line 44) near <eof>
Traceback
[C]: at ox6b1740
[C]: in function require
[C]: in function xpcall
Code: Select all
require "camera"
require "player/coin"
--require "player/SpriteAnimation"
require "Player/player"
function love.load()
g = love.graphics
f = love.graphics
a = love.audio
p = Player:new()
c.x = math.floor(p.x - 800 / 2)
c.y = math.floor(p.y - 600 / 2)
p.x = 300
p.y = 300
p.width = 32
p.height = 64
p.jumpSpeed = -400
p.runSpeed = 250
bulletgravity = 150
gravity = 1000
yFloor = 506
imagePlayer1 = g.newImage( "textures/Player/Guy11.png" )
imageGround = g.newImage( "textures/ground1.png" )
imagePause = g.newImage( "textures/Pause.png" )
imageTitle = g.newImage( "textures/titlemenu.png" )
imageOptions = g.newImage( "textures/Options.png" )
xCloud = 0
xCloud2 = 0
xCloud3 = 0
imageCloud = g.newImage( "textures/Cloud.png" )
imageCloud2 = g.newImage( "textures/Cloud2.png" )
imageCloud3 = g.newImage( "textures/Cloud3.png" )
xCoord = 5
yCoord = 5
imageRex = g.newImage( "textures/rex.png" )
imageEnemy = g.newImage( "textures/enemy1.png" )
music = a.newSource("music.WAV")
music:play()
camera:setBounds(0, 0, 1600, math.floor(600 / 8))
bulletSpeed = 250
bullets = {}
gamestate = "title"
end
function love.update(dt)
if gamestate == "title" then
if love.keyboard.isDown("return", "enter") then --if player presses the enter key, play the game
gamestate = "play"
end
if love.keyboard.isDown("o") then --if player presses the O key, open the options menu
gamestate = "options"
end
if love.keyboard.isDown("q") then
love.event.quit()
end
elseif gamestate == "play" then
if love.keyboard.isDown("right") then
p:moveRight()
end
if love.keyboard.isDown("left") then
p:moveLeft()
end
if love.keyboard.isDown(" ") then
p:jump()
end
p:update(dt, gravity)
if p.x > 1600 - p.width then p.x = 1600 - p.width
end
if p.x < 0 then p.x = 0
end
if p.y < 0 then p.y = 0
end
if p.y > yFloor - p.height then
p:hitFloor(yFloor)
end
xCloud = xCloud + 36*dt
if xCloud >= (1800 + 256) then
xCloud = -256
end
xCloud2 = xCloud2 + 24*dt
if xCloud2 >= (1800 + 384) then
xCloud2 = -384
end
xCloud3 = xCloud3 + 42*dt
if xCloud3 >= (1800 + 360) then
xCloud3 = -360
end
--[[xCoord = xCoord + 0
if xCoord ~= 1 then
xCoord = p.x-295
end
yCoord = yCoord + 0
if yCoord ~= 1 then
yCoord = p.y-395
end--]]
if p.x >= 300 then
xCoord = p.x - 200
elseif p.x <= 125 then
xCoord = 25
end
if p.y <= 450 then
yCoord = p.y - 200
elseif p.y >= 450 then
yCoord = 125
end
for i,v in ipairs(bullets) do
v.x = v.x + (v.dx * dt)
v.y = v.y + (v.dy * dt)
end
if p.x == 1568 then
c.x = 1200
camera:setPosition(c.x, c.y)
end
if gamestate == "options" then --Allows the player to exit the options menu to the title menu
if love.keyboard.isDown(" ") then
gamestate = "title"
end
end
if gamestate == "play" then
if love.keyboard.isDown("p") then
gamestate = "pause"
end
end
if gamestate == "pause" then
if love.keyboard.isDown("tab") then
gamestate = "play"
end
if love.keyboard.isDown("o") then
gamestate = "options"
end
end
end
function love.draw()
if gamestate == "title" then --Draw the title menu
f.setColor(255,255,255,255)
f.draw(imageTitle,0,0,0,1,1,0,0)
elseif gamestate == "options" then --Draw the options menu
f.setColor(255,255,255,255)
f.draw(imageOptions,0,0,0,1,1,0,0)
elseif gamestate == "pause" then
f.setColor(255,255,255,255)
f.draw(imagePause,0,0,0,1,1,0,0)
else
camera:set()
local x = math.floor(p.x)
local y = math.floor(p.y)
g.setColor( 73, 176, 255, 255 )
g.rectangle( "fill", 0, 0, 2000, 500)
g.setColor( 255, 255, 255, 255 )
g.draw( imagePlayer1, p.x, p.y, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageGround, 0, 496, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageGround, 601, 496, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageGround, 800, 496, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageGround, 1400, 496, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageRex, 1700, 284, 0, 1, 1, 0, 0 )
g.setColor( 175, 175, 175, 255 )
g.draw( imageCloud, xCloud - 256, 148, 0, 1, 1, 0, 0 )
g.setColor( 150, 155, 150, 255 )
g.draw( imageCloud2, xCloud2 + 384, 186, 0, 1, 1, 0, 0 )
g.setColor( 233, 233, 233, 255 )
g.draw( imageCloud3, xCloud3 + 420, 133, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageCloud, xCloud - 100, 128, 0, 1, 1, 0, 0 )
g.setColor( 200, 200, 200, 255 )
g.draw( imageCloud2, xCloud2 + 800, 24, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageCloud3, xCloud3 - 350, 68, 0, 1, 1, 0, 0 )
g.setColor( 90, 105, 90, 255 )
g.draw( imageCloud, xCloud + 256, 220, 0, 1, 1, 0, 0 )
g.setColor( 100, 100, 100, 255 )
g.draw( imageCloud2, xCloud2 + 500, 384, 64, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageCloud3, xCloud3 + 216, 32, 0, 1, 1, 0, 0 )
g.setColor( 50, 50, 50, 255 )
g.draw( imageCloud, xCloud - 444, 135, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageCloud2, xCloud2 + 16, 106, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageCloud3, xCloud3 + 105, 54, 0, 1, 1, 0, 0 )
g.setColor( 255, 255, 255, 255 )
g.draw( imageEnemy, -xCloud - 1600, 496 - 64, 0, 1, 1, 0, 0 )
g.setColor( 0, 0, 0, 255 )
local isTrue = ""
g.print( "Player coordinates: ("..x..","..y..")", xCoord, yCoord )
g.print( "Current state: "..p.state, xCoord, yCoord + 8 )
love.graphics.setColor(255, 0, 0)
for i,v in ipairs(bullets) do
love.graphics.circle("fill", v.x, v.y, 2)
end
camera:unset()
end
end
function love.keypressed(key)
if key == "down" then
gravity = 3500
imagePlayer1 = g.newImage( "textures/Player/Guy1111.png" )
end
if key == "left" then
imagePlayer1 = g.newImage( "textures/Player/Guy111.png" )
end
if key == "right" then
imagePlayer1 = g.newImage( "textures/Player/Guy11.png" )
end
if key ~= "left" then
imagePlayer1 = g.newImage( "textures/Player/Guy11.png" )
end
if key == " " then
imagePlayer1 = g.newImage( "textures/Player/Guy1111.png" )
end
end
function love.keyreleased(key)
if (key == "right") or (key == "left") then
p:stop()
end
if key == "down" then
gravity = 1000
end
if key == " " then
imagePlayer1 = g.newImage( "textures/Player/Guy11.png" )
end
end
function math.clamp(x, min, max)
return x < min and min or (x > max and max or x)
end
function love.mousepressed(x, y, button)
if button == "l" then
local startX = p.x + p.width / 2
local startY = p.y + p.height / 2
local mouseX = x
local mouseY = y
local angle = math.atan2((mouseY - startY), (mouseX - startX))
local bulletDx = bulletSpeed * math.cos(angle)
local bulletDy = bulletSpeed * math.sin(angle)
local bulletDy = bulletDy + bulletgravity
table.insert(bullets, {x = startX, y = startY, dx = bulletDx, dy = bulletDy})
end
end
function love.focus(bool)
if bool == false then
love.event.quit()
end
end