Add some files about lua
After Width: | Height: | Size: 3.4 KiB |
|
@ -0,0 +1,3 @@
|
|||
function love.conf(t)
|
||||
t.title = "Avalanche of LÖVE"
|
||||
end
|
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.1 KiB |
|
@ -0,0 +1,98 @@
|
|||
-- Example: Avalanche of LOVE
|
||||
|
||||
-- Contains all the balls.
|
||||
balls = {}
|
||||
|
||||
-- Contains all the boxes. (Terrain)
|
||||
boxes = {}
|
||||
|
||||
function love.load()
|
||||
|
||||
-- Fat lines.
|
||||
love.graphics.setLineWidth(2)
|
||||
|
||||
-- Load images.
|
||||
images = {
|
||||
green = love.graphics.newImage("green_ball.png"),
|
||||
big_love = love.graphics.newImage("big_love_ball.png"),
|
||||
love = love.graphics.newImage("love_ball.png"),
|
||||
}
|
||||
|
||||
-- Image / radius pairs.
|
||||
balldefs = {
|
||||
{ i = images.green, r = 32 , ox = 36, oy = 36},
|
||||
{ i = images.big_love, r = 46 , ox = 48, oy = 48},
|
||||
{ i = images.love, r = 28 , ox = 32, oy = 32},
|
||||
}
|
||||
|
||||
-- Create the world.
|
||||
world = love.physics.newWorld(0, 300)
|
||||
|
||||
-- Create ground body.
|
||||
ground = love.physics.newBody(world, 0, 0, "static")
|
||||
|
||||
-- Add all the balls.
|
||||
addball(balldefs[1], 50) -- Add 100 green.
|
||||
addball(balldefs[2], 5) -- Add 5 big.
|
||||
addball(balldefs[3], 25) -- Add 50 pink.
|
||||
|
||||
-- This generates the terrain.
|
||||
for i = 0, 10 do
|
||||
addbox(i*50, i*50+100)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
|
||||
-- Update the world.
|
||||
world:update(dt)
|
||||
|
||||
-- Check whether we need to reset some balls.
|
||||
-- When they move out of the screen, they
|
||||
-- respawn above the screen.
|
||||
for i,v in ipairs(balls) do
|
||||
local x, y = v.b:getPosition()
|
||||
if x > 850 or y > 650 then
|
||||
v.b:setPosition(math.random(600, 1400), -math.random(100, 1500))
|
||||
v.b:setLinearVelocity(-math.random(100,1000), math.random(100,1000))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
-- Draw all the balls.
|
||||
for i, v in ipairs(balls) do
|
||||
love.graphics.draw(v.i, v.b:getX(), v.b:getY(), v.b:getAngle(), 1, 1, v.ox, v.oy)
|
||||
end
|
||||
-- Draw all the boxes.
|
||||
for i, v in ipairs(boxes) do
|
||||
love.graphics.polygon("line", v.s:getPoints())
|
||||
end
|
||||
love.graphics.print("Click and drag the cake around or use the arrow keys", 10, 10)
|
||||
end
|
||||
|
||||
-- Adds a static box.
|
||||
function addbox(x, y)
|
||||
local t = {}
|
||||
t.b = ground
|
||||
t.s = love.physics.newRectangleShape(x, y, 50, 50)
|
||||
t.f = love.physics.newFixture(t.b, t.s)
|
||||
table.insert(boxes, t)
|
||||
end
|
||||
|
||||
|
||||
-- Adds X balls.
|
||||
function addball(def, num)
|
||||
for i = 1, num do
|
||||
local x, y = math.random(0, 400), -math.random(100, 1500)
|
||||
local t = {}
|
||||
t.b = love.physics.newBody(world, x, y, "dynamic")
|
||||
t.s = love.physics.newCircleShape(def.r)
|
||||
t.f = love.physics.newFixture(t.b, t.s)
|
||||
t.i = def.i
|
||||
t.ox = def.ox
|
||||
t.oy = def.oy
|
||||
table.insert(balls, t)
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 3.4 KiB |
|
@ -0,0 +1,3 @@
|
|||
function love.conf(t)
|
||||
t.title = "Avalanche of LÖVE"
|
||||
end
|
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.1 KiB |
|
@ -0,0 +1,98 @@
|
|||
-- Example: Avalanche of LOVE
|
||||
|
||||
-- Contains all the balls.
|
||||
balls = {}
|
||||
|
||||
-- Contains all the boxes. (Terrain)
|
||||
boxes = {}
|
||||
|
||||
function love.load()
|
||||
|
||||
-- Fat lines.
|
||||
love.graphics.setLineWidth(2)
|
||||
|
||||
-- Load images.
|
||||
images = {
|
||||
green = love.graphics.newImage("green_ball.png"),
|
||||
big_love = love.graphics.newImage("big_love_ball.png"),
|
||||
love = love.graphics.newImage("love_ball.png"),
|
||||
}
|
||||
|
||||
-- Image / radius pairs.
|
||||
balldefs = {
|
||||
{ i = images.green, r = 32 , ox = 36, oy = 36},
|
||||
{ i = images.big_love, r = 46 , ox = 48, oy = 48},
|
||||
{ i = images.love, r = 28 , ox = 32, oy = 32},
|
||||
}
|
||||
|
||||
-- Create the world.
|
||||
world = love.physics.newWorld(0, 50)
|
||||
|
||||
-- Create ground body.
|
||||
ground = love.physics.newBody(world, 0, 0, "static")
|
||||
|
||||
-- Add all the balls.
|
||||
addball(balldefs[1], 50) -- Add 100 green.
|
||||
addball(balldefs[2], 5) -- Add 5 big.
|
||||
addball(balldefs[3], 25) -- Add 50 pink.
|
||||
|
||||
-- This generates the terrain.
|
||||
for i = 0, 10 do
|
||||
addbox(i*50, i*50+100)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
|
||||
-- Update the world.
|
||||
world:update(dt)
|
||||
|
||||
-- Check whether we need to reset some balls.
|
||||
-- When they move out of the screen, they
|
||||
-- respawn above the screen.
|
||||
for i,v in ipairs(balls) do
|
||||
local x, y = v.b:getPosition()
|
||||
if x > 850 or y > 650 then
|
||||
v.b:setPosition(math.random(0, 400), -math.random(100, 1500))
|
||||
v.b:setLinearVelocity(0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
-- Draw all the balls.
|
||||
for i, v in ipairs(balls) do
|
||||
love.graphics.draw(v.i, v.b:getX(), v.b:getY(), v.b:getAngle(), 1, 1, v.ox, v.oy)
|
||||
end
|
||||
-- Draw all the boxes.
|
||||
for i, v in ipairs(boxes) do
|
||||
love.graphics.polygon("line", v.s:getPoints())
|
||||
end
|
||||
end
|
||||
|
||||
-- Adds a static box.
|
||||
function addbox(x, y)
|
||||
local t = {}
|
||||
t.b = ground
|
||||
t.s = love.physics.newRectangleShape(x, y, 50, 50)
|
||||
t.f = love.physics.newFixture(t.b, t.s)
|
||||
table.insert(boxes, t)
|
||||
end
|
||||
|
||||
|
||||
-- Adds X balls.
|
||||
function addball(def, num)
|
||||
for i = 1, num do
|
||||
local x, y = math.random(0, 400), -math.random(100, 1500)
|
||||
local t = {}
|
||||
t.b = love.physics.newBody(world, x, y, "dynamic")
|
||||
t.s = love.physics.newCircleShape(def.r)
|
||||
t.f = love.physics.newFixture(t.b, t.s)
|
||||
t.i = def.i
|
||||
t.ox = def.ox
|
||||
t.oy = def.oy
|
||||
table.insert(balls, t)
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 1.0 KiB |
|
@ -0,0 +1,4 @@
|
|||
|
||||
function love.conf(t)
|
||||
t.title = "ParticleSystem Demo"
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
-------------------------------------------------
|
||||
-- LOVE: ParticleSystem demo.
|
||||
-- Website: http://love2d.org
|
||||
-- Licence: ZLIB/libpng
|
||||
-- Copyright (c) 2006-2009 LOVE Development Team
|
||||
-------------------------------------------------
|
||||
|
||||
systems = {}
|
||||
current = 1
|
||||
|
||||
function love.load()
|
||||
cloud = love.graphics.newImage("cloud.png")
|
||||
x = 50
|
||||
y = 50
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.draw(cloud, x, y)
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
if love.keyboard.isDown("up") then
|
||||
y = y - 1000 * dt
|
||||
elseif love.keyboard.isDown("down") then
|
||||
y = y + 1000 * dt
|
||||
elseif love.keyboard.isDown("right") then
|
||||
x = x + 1000 * dt
|
||||
elseif love.keyboard.isDown("left") then
|
||||
x = x - 1000 * dt
|
||||
end
|
||||
end
|