Sure thing:
Brick = class()
function Brick:Setup(x,y,w,h,r,bounciness)
-- you can accept and set parameters here
self.x = x
self.y = y
self.w = w
self.h = h
self.r = r
self.body = physics.body(POLYGON,
vec2(0,0),vec2(0,h),vec2(w,h),vec2(w,0))
self.body.x = x
self.body.y = y
self.body.angle = r
self.body.restitution = bounciness
end
function Brick:Update()
self.x = self.body.x
self.y = self.body.y
self:draw()
end
function Brick:draw()
pushMatrix()
strokeWidth(0)
fill(255, 45, 0, 255)
translate(self.body.x, self.body.y)
rotate(self.body.angle)
rect(0,0,self.w,self.h)
popMatrix()
end
And then main
function SetupBricks()
b1 = Brick -- create the brick
-- setup the brick.
-- arguments: x position, y position, width, height, rotation
--(in degrees), bouciness
-- about bounciness - 1 would mean it bounces as high as where it
--fell from.
-- colour coming soon, just working on an easy to use system
b1:Setup(300,300,30,150,40, 0.2)
b2 = Brick
b2:Setup(450,450,30,150,40,0.3)
end
-- This function gets called once every frame
function draw()
-- This sets a sky blue background color
background(124, 164, 176, 255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
DrawEnvironment()
b1:Update()
b2:Update()
end
function DrawEnvironment()
strokeWidth(0)
fill(148, 114, 56, 255)
rect(-1,-1,WIDTH+30,80)
fill(40, 130, 29, 255)
rect(-1,75,WIDTH+2, 20)
end
function setup()
supportedOrientations(LANDSCAPE_ANY)
physics.gravity(0,-200)
SetupBricks()
local floor = physics.body(POLYGON, vec2(0,0),vec2(WIDTH,0),vec2(WIDTH,95), vec2(0, 95))
floor.type = STATIC
floor.angle=0
floor.y = -1.5
end
Thanks in advance.