Skip to content

Instantly share code, notes, and snippets.

-- Test
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
function setup()
--first the rectangle
rect_width=100 --size of rectangle
rect_height=50
--now create the physics object, we feed it the location
--of the four corners, relative to the centre of the
--rectangle, which is why all the measurements below
--are for half the height or width
function setup()
--first the rectangle
rect_width=100 --size of rectangle
rect_height=50
--now create the physics object, we feed it the location
--of the four corners, relative to the centre of the
--rectangle, which is why all the measurements below
--are for half the height or width
@dermotbalson
dermotbalson / Classes
Created April 9, 2013 14:29
8. Classes
--# Main
-- class
-- Use this function to perform your initial setup
function setup()
b={}
for i=1,5 do
b[i]=Ball()
end
r={}
@dermotbalson
dermotbalson / 9. Coroutines
Created April 9, 2013 14:32
9. Coroutines
function setup()
parameter.action('Run_without_coroutine',bigJob)
parameter.action('Run_with_coroutine',WithCoroutine)
end
function WithCoroutine()
cos=coroutine.create(bigJobCos)
coroutine.resume(cos)
end
@dermotbalson
dermotbalson / 10. Images
Created April 9, 2013 14:34
10. Images
-- Use this function to perform your initial setup
function setup()
print("Please wait while I load the images from the internet")
http.request("https://img1.minebook.me/gallery/48755_mordor.png",
function(i,a,b) mordor=i print("loaded") end)
http.request("http://www.portent.com/images/2012/04/nazgul-cyclery-logo-long.png",
function(i,a,b) nazgul=i print("loaded") end)
state="LOADING"
end
-- test
-- Use this function to perform your initial setup
function setup()
if backup then Backup("pinch") end
img=readImage("Small World:Mine Medium")
p=pinch()
end
function draw()
function setup()
--set up normal sprite
img=readImage("Tyrian Remastered:Space Ice 3")
w,h=img.width,img.height
--set up mesh alternative
g=mesh()
g.texture="Tyrian Remastered:Flame 2" --name of the image we want to use
parameter.boolean("Mesh",false)
parameter.integer("NumberOfObjects",50,200,50)
end
--[[
This demo is where it starts to get more complicated, even though we'll only create
a 3D block with just 8 triangles. There are several parts to this
1. creating 3D objects
2. placing them in 3D space
3. choosing our viewpoint in 3D space
CREATING THE BLOCK
I've put the code that creates the block in its own class underneath, so you can use it easily
in your own projects. (Trust me, you will never want to write this code yourself. It took me
--# Main
--[[
In this demo, I've added a texture from the internet to make the dice more interesting
I've also added a fake highlight to the dice spots to give them some depth
--]]