Code: Select all
require "Levels/lev1.lua"
Code: Select all
lev1()
Code: Select all
require "Levels/lev1.lua"
Code: Select all
lev1()
Code: Select all
local function lev1()
print ("Working")
levdraw()
end
function levdraw()
love.graphics.clear()
love.graphics.setColor(255, 0, 0)
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY())
love.graphics.polygon("fill", objects.ground.shape:getPoints())
end
Code: Select all
function love.load()
require 'lev1.lua'
world = love.physics.newWorld(0, 0, 650, 650)
world:setGravity(0, 700)
world:setMeter(64)
objects = {}
objects.ground = {}
objects.ground.body = love.physics.newBody(world, 650/2, 625, 0, 0)
objects.ground.shape = love.physics.newRectangleShape(objects.ground.body, 0, 0, 650, 50, 0)
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, 15, 0)
objects.ball.shape = love.physics.newCircleShape(objects.ball.body, 0, 0, 20)
objects.ceiling = {}
objects.ceiling.body = love.physics.newBody(world, 650/2, 0, 0, 0)
objects.ceiling.shape = love.physics.newRectangleShape(objects.ceiling.body, 0, 0, 650, 50, 0)
love.graphics.setBackgroundColor(104, 136, 248)
love.graphics.setMode(650, 650, false, true, 0)
end
function love.update(dt)
world:update(dt)
xBall = objects.ball.body:getX()
yBall = objects.ball.body:getY()
if xBall >= 650 then
objects.ball.body:setX(0)
end
if xBall < 0 then
objects.ball.body:setX(650)
end
if yBall < 0 then
objects.ball.body:setY(650/2)
world:setGravity(0, 700)
objects.ball.body:applyForce(0, 0)
end
if love.keyboard.isDown("up") then
world:setGravity(0, -700)
objects.ball.body:applyForce(0, -100)
elseif love.keyboard.isDown("down") then
world:setGravity(0, 700)
elseif love.keyboard.isDown("right") then
objects.ball.body:applyForce(400, 0)
elseif love.keyboard.isDown("left") then
objects.ball.body:applyForce(-400, 0)
elseif love.keyboard.isDown("r") then
objects.ball.body:setY(650/2)
objects.ball.body:setX(650/2)
world:setGravity(0, 700)
elseif love.keyboard.isDown("enter") then
print ("Working")
lev1()
end
end
function love.draw()
love.graphics.setColor(0, 0, 0)
love.graphics.print("Press 'up' to reverse gravity", 0, 30)
love.graphics.print("Press 'down' to return gravity to it's original state", 0, 50)
love.graphics.print("Press 'left' or 'right' to move", 0, 70)
love.graphics.print("Please note that gravity changes do not apply until you move", 0, 90)
love.graphics.setColor(72, 160, 14)
love.graphics.polygon("fill", objects.ground.shape:getPoints())
love.graphics.setColor(0, 0, 0)
love.graphics.polygon("fill", objects.ceiling.shape:getPoints())
love.graphics.setColor(193, 47, 14)
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius(), 20)
end
Code: Select all
function love.keypressed(key, unicode --[[not needed now]])
if key == 'return' then
--do whatever you want to do
end
end
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests