I’ve been having some problems with my project. My character can’t move when I place a portal let alone travel through it. Here is my code:
-- My Little Portal Demo 0.87
-- Simple Physics
-- Use this function to perform your initial setup
function setup()
touches = {}
function touched(touch)
-- When you touch the screen, create a random portal
function draw()
-- Store current style
function touched(touch)
function draw()
ellipse(CurrentTouch.x, CurrentTouch.y, 70, 125)
stroke(0, 75, 255, 255)
strokeWidth(4)
fill(118, 190, 211, 255)
end
function touched(touch)
function draw()
ellipse(CurrentTouch.x, CurrentTouch.y, 70, 125)
stroke(255, 128, 0, 255)
strokeWidth(4)
fill(211, 162, 118, 255)
end
end
end
end
end
-- Table to store our physics bodies
bodies = {}
-- Create some static boxes (not effected by gravity or collisions)
local left = makeBox(WIDTH/4, HEIGHT/2, WIDTH/3, 10, 0)
left.type = STATIC
local right = makeBox(WIDTH - WIDTH/4, HEIGHT/2, WIDTH/3, 10, 0)
right.type = STATIC
table.insert(bodies, left)
table.insert(bodies, right)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(49, 49, 84, 255)
-- Draw all our physics bodies
for k,body in pairs(bodies) do
drawBody(body)
end
for i = 1,8 do
sprite("Documents:Floor", 0, 0, 10000, 200)
end
parameter.number("X", 0, WIDTH, X)
sprite("Documents:Chell", X, 110, 200, 200)
end
function touched(touch)
-- If the user drags their finger we'll
-- update the number slider controlling 'X'
-- This shows how code can affect parameter widgets
if touch.state == MOVING then
X = touch.x
end
end
-- Helper function to create a box using a polygon body
function makeBox(x,y,w,h,r)
-- Points are defined in counter-clockwise order
local body = physics.body(POLYGON,vec2(-w/2, h/2),
vec2(-w/2, -h/2), vec2(w/2, -h/2), vec2(w/2, h/2))
-- Set the body's transform (position, angle)
body.x = x
body.y = y
body.angle = r
-- Make movement smoother regardless of framerate
body.interpolate = true
return body
end
-- Helper function to draw a physics body
function drawBody(body)
-- Push style and transform matrix so we can restore them after
pushStyle()
pushMatrix()
strokeWidth(5)
stroke(255, 255, 255, 255)
translate(body.x, body.y)
rotate(body.angle)
-- Draw body based on shape type
if body.shapeType == POLYGON then
strokeWidth(3.0)
local points = body.points
for j = 1,#points do
a = points[j]
b = points[(j % #points)+1]
line(a.x, a.y, b.x, b.y)
end
elseif body.shapeType == CHAIN or body.shapeType == EDGE then
strokeWidth(3.0)
local points = body.points
for j = 1,#points-1 do
a = points[j]
b = points[j+1]
line(a.x, a.y, b.x, b.y)
end
elseif body.shapeType == CIRCLE then
strokeWidth(3.0)
line(0,0,body.radius-3,0)
ellipse(0,0,body.radius*2)
end
-- Restore style and transform
popMatrix()
popStyle()
end