I have been trying for days to import my game.lua to my main.lua. It just won't work
I want game.lua to run after pressing the start game...
I have been trying by watching videos, reading tutorials but IDK how to ! I know how to import simple var like x=1 from other script but dont know how to execute the entire script! Please help...
ps: sorry for the mess in the code.. I have been trying too much
my main.lua
Code: Select all
fullscreen = false
require "game"
Menu = require 'library/menu'
function love.load()
start = game.f1()
player = game.f2()
game = game.f3()
testmenu = Menu.new()
testmenu:addItem{
name = 'Start Game',
action = function()
start.game.f1()
end
}
testmenu:addItem{
name = 'Load Game',
action = function()
-- do something
end
}
testmenu:addItem{
name = 'Options',
action = function()
-- do something
end
}
testmenu:addItem{
name = 'Quit',
action = function()
love.event.quit()
end
}
end
function love.update(dt)
testmenu:update(dt)
end
function love.draw()
testmenu:draw(250, 250)--menu table position(x,y)
end
function love.keypressed(key)
testmenu:keypressed(key)
end
my game.lua
Code: Select all
game = {}
game.f1 = function()
anim8 = require 'library/anim8'
love.graphics.setDefaultFilter("nearest","nearest")
player = {} --empty table
player.x = 400
player.y = 200
player.speed = 2
player.spritesheet = love.graphics.newImage('pic/lady.png')
player.sprite = love.graphics.newImage('pic/parrot.png')
player.grid = anim8.newGrid(103, 121, player.spritesheet: getWidth(), player.spritesheet: getHeight() )--create grid
--get grid by dividing resolution with 4
player.animations = {}
player.animations.down = anim8.newAnimation(player.grid('1-4',1),0.2 )
player.animations.left = anim8.newAnimation(player.grid('1-4',2),0.2 )
player.animations.right = anim8.newAnimation(player.grid('1-4',3),0.2 )
player.animations.up = anim8.newAnimation(player.grid('1-4',4),0.2 )
player.anim = player.animations.down
background = love.graphics.newImage('pic/background.png')
end
game.f2 = function(dt)
local isMoving = false
if love.keyboard.isDown("right") then
player.x = player.x + player.speed
player.anim = player.animations.right
isMoving = true
end
if love.keyboard.isDown("left")then
player.x = player.x - player.speed
player.anim = player.animations.left
isMoving = true
end
if love.keyboard.isDown("up")then
player.y =player.y - player.speed
player.anim = player.animations.up
isMoving = true
end
if love.keyboard.isDown("down")then
player.y =player.y + player.speed
player.anim = player.animations.down
isMoving = true
end
if isMoving == false then
player.anim:gotoFrame(2)
end
player.anim:update(dt)
end
game.f3 = function()
love.graphics.draw(background,0,0)
--player.anim:draw(player.spritesheet,player.x, player.y, nil, 5)
player.anim:draw(player.spritesheet,player.x, player.y)
end
return game
Thank you *sobs*