Okay, so, I’ll probably end up beating my face into a wall until the wall caves in, but, I’m having more trouble understanding angles(yay!). In the calcshiploc() function I commented out some code which does not work to update the location (to see how not-working it is, simply I uncomment it and comment out the “shiploc = shipVelocity:rotate(anglerad) + shiploc” line. I’m sure either @andrew_stacey or @ignatz will promptly make me feel like a total buffoon this time around (as they so often do, but, I’m not complaining, I appreciate the self-scorn they give me the power to apply, love you guys). But really, the day I understand angles will be the day pigs fly and whales grow legs…
function setup()
stroke(255, 0, 0, 139)
smooth()
textMode(CORNER)
lineCapMode(ROUND)
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_LEFT)
lasso, originid = nil, nil
simpveloc=3
shipVelocity = vec2(simpveloc,0)
shiploc = vec2(WIDTH/2, HEIGHT/2)
anglerad = math.pi/2
dots = {}
numdots = math.deg(math.pi*.5)
dotang=0
b=0
dotfx= true
controlswitch = 3
--768 width
--1024 height
--256 difference
drawguides = false
guidevec= vec2(0,0)
end
function draw()
background(0,0,0,255)
calcshiploc()
fxdraw()
drawship()
end
function drawship()
pushMatrix()
strokeWidth(1)
stroke(0, 255, 0, 255)
fill(0,0,0,0)
translate(shiploc.x,shiploc.y)
if drawguides==true or lasso == nil then
ellipse(0,0,60,60)
ellipse(0,0,240,240)
end
rotate(math.deg(anglerad)-90)
sprite("Space Art:Red Ship", 0,0, 30)
popMatrix()
strokeWidth(3)
stroke(0,255,0,255)
fill(0, 0, 0, 255)
rect(768,0-1,256,768+1.5)
end
function fxdraw()
if drawguides then
dist = guidevec:dist(shiploc)
if dist >30 and dist <120 then
strokeWidth(1)
stroke(0, 255, 6, 255)
line(guidevec.x-40, guidevec.y, guidevec.x+40, guidevec.y)
line(guidevec.x, guidevec.y-40, guidevec.x, guidevec.y+40)
fill(0,0,0,0)
ellipse(guidevec.x, guidevec.y, 60,60)
ellipse(guidevec.x, guidevec.y, dist*2,dist*2)
end
end
if lasso ~= nil then
stroke(255, 0, 0, 138)
strokeWidth(3)
line(lasso.x,lasso.y, shiploc.x,shiploc.y)
if b<lassolength then
calcdots()
end
strokeWidth(10)
pushMatrix()
translate(lasso.x, lasso.y)
for i=1, #dots do
if i%2 == 0 then
rotate(dotang)
ellipse(dots[i].x,dots[i].y, 5)
rotate(-dotang)
else
rotate(-dotang)
ellipse(dots[i].x,dots[i].y, 5)
rotate(dotang)
end
end
dotang=dotang+.05
popMatrix()
end
fill(255,255,255,255)
text(math.floor(1/DeltaTime), WIDTH/2-15, HEIGHT-30)
text(math.floor(ElapsedTime), WIDTH/2-15, HEIGHT-50)
end
function touched(touch)
if controlswitch == 1 then
if touch.state == BEGAN and originid == nil then
initlasso(touch)
elseif touch.state == ENDED and touch.id == originid then
lasso = nil
originid = nil
dots = nil
dots = {}
end
elseif controlswitch == 2 then
if touch.state == BEGAN and originid == nil then
initlasso(touch)
elseif touch.state == BEGAN and originid ~= nil and b==lassolength then
lasso=nil
originid=nil
dots = nil
dots = {}
initlasso(touch)
end
elseif controlswitch == 3 then
guidevec= vec2(touch.x,touch.y)
if touch.state == BEGAN and originid == nil and touch.x < 768 then
drawguides = true
originid = touch.id
elseif touch.state == ENDED and originid == touch.id and (vec2(touch.x,touch.y):dist(shiploc) < 120 and vec2(touch.x,touch.y):dist(shiploc) >30) then
dots = nil
dots = {}
drawguides = false
initlasso(touch)
originid = nil
elseif touch.state == ENDED and originid == touch.id then
drawguides = false
originid = nil
end
end
end
function initlasso(t)
b=0
lassolength = vec2(t.x,t.y):dist(shiploc)
if lassolength < 30 or lassolength > 120 then
lasso = nil
originid = nil
return
end
originid = t.id
lasso = vec2(t.x,t.y)
local circumf = 2*math.pi*lassolength
angleaddrad = 2*math.pi*simpveloc/circumf
local offset = lasso - shiploc
local anglebet = math.atan2(offset.y,offset.x)
local tangent = anglebet - (math.pi/2)
if (anglerad - anglebet)%(2*math.pi) > math.pi then
anglerad = tangent
else
anglerad = tangent + math.pi
angleaddrad = -angleaddrad
end
end
function calcshiploc()
if lasso ~= nil then
anglerad = anglerad+ angleaddrad
end
shiploc = shipVelocity:rotate(anglerad) + shiploc
--if lasso ~= nil then
-- local offset = lasso - shiploc
-- local anglebet = math.atan2(offset.y,offset.x)
-- anglebet=anglebet+angleaddrad
-- shiploc.x = (math.cos(anglebet)*lassolength)+shiploc.x
-- shiploc.y = (math.sin(anglebet)*lassolength)+shiploc.y
--else
-- shiploc = shipVelocity:rotate(anglerad) + shiploc
--end
end
function calcdots()
if dotfx == true then
b=b+lassolength/math.sqrt(lassolength*4)
if b>lassolength then
b= lassolength
end
else
b=lassolength
end
for i=0, numdots do
--dots[i] = vec2(lasso.x+(b*math.cos(math.rad(i*(360/numdots)))), lasso.y+(b*math.sin(math.rad(i*(360/numdots))))) (for if i change my mind about animations)
if i%2 == 0 then
b=b+3
dots[i] = vec2((b*math.cos(math.rad(i*(360/numdots)))),(b*math.sin(math.rad(i*(360/numdots)))))
b=b-3
else
dots[i] = vec2((b*math.cos(math.rad(i*(360/numdots)))),(b*math.sin(math.rad(i*(360/numdots)))))
end
end
end
function turnaround()
if lasso~=nil then
anglerad = anglerad + math.pi
if anglerad > 2*math.pi then
anglerad = anglerad-(2*math.pi)
end
angleaddrad = -angleaddrad
end
end
P.S. I’m really proud of some of the purdy effects I put on there, so, you could comment on those too and I wouldn’t complain casually whistles
P. double-S. It’s meant to be run in LANDSCAPE mode. Is there a way to force it to start in landscape? I have supported orientations set to landscape, but if you press the run button while codea is in portrait it’ll still start in portrait, much to my chagrin. Is there a fix for that? If so, that’d be much appreciated to alleviate my minor annoyance.