-
-
Save monkeyman32123/3e52e88bfe08e6541f0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--# Main | |
displayMode(OVERLAY) | |
function setup() | |
allupdated = false | |
heroloc = vec2(WIDTH/2,HEIGHT/2) | |
herosize = 30 | |
perworldwidth = 768 | |
worldmap = worldmaps[1] | |
numwid = math.sqrt(#worldmap) | |
worlds={} | |
for i=0, numwid-1 do | |
for b=0,numwid-1 do | |
worlds[b+(i*numwid)] = World(worldmap[(b+(i*numwid))+1],vec2((WIDTH/2)+(b*perworldwidth)-1,(HEIGHT/2)+(i*perworldwidth)-1),perworldwidth) | |
end | |
end | |
for i = 0, #worlds do | |
worlds[i]:m2(vec2(-perworldwidth*math.floor(numwid/2),-perworldwidth*math.floor(numwid/2))) | |
end | |
j = Joystiqs() | |
rotangle = 0 | |
col = color(255,0,0,255) | |
blend = 0 | |
red = true | |
orange = false | |
yellow = false | |
green = false | |
teal = false | |
blue = false | |
purple = false | |
violet = false | |
end | |
function draw() | |
background(255, 255, 255, 255) | |
j:j1Calc() | |
if j:getmag() ~= nil and j:getang() ~= nil then | |
local m = j:getmag() | |
rotangle = j:getang() | |
for i = 0, #worlds do | |
worlds[i]:move(m,rotangle) | |
end | |
end | |
for i=0,#worlds do | |
worlds[i]:draw() | |
end | |
j:draw() | |
pushMatrix() | |
translate(heroloc.x,heroloc.y) | |
rotate(math.deg(rotangle)) | |
fill(col) | |
strokeWidth(1) | |
local r = 127.5+(127.5-col.r) | |
local g = 127.5+(127.5-col.g) | |
local b = 127.5+(127.5-col.b) | |
stroke(r,g,b,255) | |
colorCycle() | |
ellipse(0,0,herosize) | |
popMatrix() | |
fill(0, 0, 255, 255) | |
text(1/DeltaTime,WIDTH/2,HEIGHT-50) | |
j:cleanJoystickData() | |
allupdated = false | |
end | |
function touched(touch) | |
j:touched(touch) | |
end | |
worldmaps = { | |
{9,2,2,2,6, | |
5,1,1,1,3, | |
5,1,1,1,3, | |
5,1,1,1,3, | |
8,4,4,4,7}, | |
} | |
function colorCycle() | |
if red then | |
local c2 = color(255,0,0,255) | |
local c1 = color(255,125,0,255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
red = false | |
orange = true | |
end | |
elseif orange then | |
local c2 = color(255,125,0,255) | |
local c1 = color(255,255,0,255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
orange = false | |
yellow = true | |
end | |
elseif yellow then | |
local c2 = color(255,255,0,255) | |
local c1 = color(0,255,0,255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
yellow = false | |
green = true | |
end | |
elseif green then | |
local c2 = color(0,255,0,255) | |
local c1 = color(0, 255, 255, 255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
green = false | |
teal = true | |
end | |
elseif teal then | |
local c2 = color(0,255,255,255) | |
local c1 = color(0,0,255,255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
teal = false | |
blue = true | |
end | |
elseif blue then | |
local c2 = color(0, 0, 255, 255) | |
local c1 = color(125,0,255,255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
blue = false | |
purple = true | |
end | |
elseif purple then | |
local c2 = color(125,0,255,255) | |
local c1 = color(255, 0, 255, 255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
purple = false | |
violet = true | |
end | |
elseif violet then | |
local c2 = color(255, 0, 255, 255) | |
local c1 = color(255, 0, 0, 255) | |
col = c1:mix(c2,blend) | |
if blend >= 1 then | |
blend = 0 | |
violet = false | |
red = true | |
end | |
end | |
blend = blend + .01 | |
end | |
--# World | |
World = class() | |
function World:init(lvl, loc, wid) | |
self.loc = vec2(loc.x-wid/2,loc.y-wid/2) | |
self.leveltiles = levels[lvl] | |
self.leveltileslocs = {} | |
local numdir = math.sqrt(#self.leveltiles) | |
self.numdir = numdir | |
self.widhei = wid/numdir | |
for i=0, numdir-1 do | |
for b=0, numdir do | |
self.leveltileslocs[b+(i*numdir)] = vec2(b*self.widhei,i*self.widhei) | |
end | |
end | |
table.remove(self.leveltileslocs,#self.leveltileslocs) | |
self.active = nil | |
self:isActiveb() | |
self.xmove = true | |
self.ymove = true | |
self.add = nil | |
self.collided = false | |
self.visible = true | |
self.offs = vec2(0,0) | |
end | |
function World:draw() | |
if self.visible then | |
rectMode(CORNER) | |
strokeWidth(0) | |
if self:isActiveb() then | |
for i=0, #self.leveltileslocs do | |
if self.leveltiles[i+1] == 0 then | |
fill(255,255,255,255) | |
else | |
fill(0,0,0,255) | |
end | |
rect(self.leveltileslocs[i].x+self.loc.x,self.leveltileslocs[i].y+self.loc.y,self.widhei+2,self.widhei+2) | |
end | |
else | |
fill(0,0,0,255) | |
rect(self.loc.x,self.loc.y,self.widhei*self.numdir+2,self.widhei*self.numdir+2) | |
end | |
end | |
end | |
function World:touched(touch) | |
end | |
function World:isVisible() | |
local p = {} | |
p[1] = self.leveltileslocs[0]+self.loc | |
p[2] = vec2(self.leveltileslocs[self.numdir-1].x+self.widhei+self.loc.x,self.leveltileslocs[self.numdir-1].y+self.loc.y) | |
p[3] = vec2(self.leveltileslocs[self.numdir*(self.numdir-1)].x+self.loc.x,self.leveltileslocs[self.numdir*(self.numdir-1)].y+self.widhei+self.loc.y) | |
p[4] = vec2(self.leveltileslocs[#self.leveltileslocs].x+self.widhei+self.loc.x,self.leveltileslocs[#self.leveltileslocs].y+self.widhei+self.loc.y) | |
for i = 1,#p do | |
if p[i].x < WIDTH and p[i].x > -5 and p[i].y < HEIGHT and p[i].y > -5 then | |
return true | |
end | |
end | |
return false | |
end | |
function World:isActive() | |
if self.leveltileslocs[0].x+self.loc.x < (WIDTH/2)+(herosize/2) and | |
self.leveltileslocs[0].y+self.loc.y < (HEIGHT/2)+(herosize/2) and | |
self.leveltileslocs[#self.leveltileslocs].x+self.loc.x+self.widhei > (WIDTH/2)-(herosize/2) and | |
self.leveltileslocs[#self.leveltileslocs].y+self.loc.y+self.widhei > (HEIGHT/2)-(herosize/2) then | |
self.active = true | |
return true | |
else | |
self.active = false | |
return false | |
end | |
end | |
function World:isActiveb() | |
if self.leveltileslocs[0].x+self.loc.x < (WIDTH/2) and | |
self.leveltileslocs[0].y+self.loc.y < (HEIGHT/2) and | |
self.leveltileslocs[#self.leveltileslocs].x+self.loc.x+self.widhei > (WIDTH/2) and | |
self.leveltileslocs[#self.leveltileslocs].y+self.loc.y+self.widhei > (HEIGHT/2) then | |
self.active = true | |
return true | |
else | |
self.active = false | |
return false | |
end | |
end | |
function World:move(m,a) | |
if self.active then | |
self.temploc = self.loc | |
self.add = vec2(-m/10,0):rotate(a) | |
self.loc=self.loc+self.add | |
self.collided = false | |
local q = false | |
local i = 0 | |
while q == false do | |
if self.leveltiles[i+1] == 1 and (self.leveltileslocs[i]+self.loc):dist(heroloc) < 2*self.widhei then | |
self:colliding(self.leveltileslocs[i]+self.loc,self.temploc) | |
end | |
if self.xmove == false and self.ymove == false then | |
q = true | |
end | |
if i == #self.leveltileslocs then | |
q = true | |
end | |
i = i + 1 | |
end | |
local offset = self.loc-self.temploc | |
if not allupdated then | |
for i=0,#worlds do | |
if not worlds[i].active then | |
worlds[i]:m2(offset) | |
end | |
end | |
allupdated = true | |
end | |
else | |
self.visible = self:isVisible() | |
end | |
end | |
function World:m2(add) | |
self.loc = self.loc + add | |
end | |
function World:colliding(corner, prev) | |
if heroloc.x+(herosize/2)>corner.x and heroloc.x-(herosize/2)<corner.x+self.widhei then | |
if heroloc.y+(herosize/2)>corner.y and heroloc.y-(herosize/2)<corner.y+self.widhei then | |
self.collided = true | |
blah = vec2(corner.x-self.loc.x+(self.widhei/2)+prev.x,corner.y-self.loc.y+(self.widhei/2)+prev.y) | |
local ang = math.deg(math.atan2(blah.x-heroloc.x,blah.y-heroloc.y)) | |
if ang>45 and ang <=135 then | |
self.loc.x = self.temploc.x-((blah.x-heroloc.x)-(self.widhei/2+herosize/2))-1 | |
elseif ang<=45 and ang>-45 and (math.abs(corner.x-heroloc.x) < herosize/4 or corner.x-heroloc.x<0) then | |
self.loc.y = self.temploc.y-((blah.y-heroloc.y)-(self.widhei/2+herosize/2))-1 | |
elseif ang <=-45 and ang > -135 and (math.abs(corner.y-heroloc.y) < herosize/4 or corner.y-heroloc.y<0) then | |
self.loc.x = self.temploc.x+((-blah.x+heroloc.x)-(self.widhei/2+herosize/2)) | |
elseif (ang > 135 or ang <= -135) and (math.abs(corner.x-heroloc.x) < herosize/4 or (corner.x-heroloc.x<0 and heroloc.x-corner.x < self.widhei+(herosize/4))) then | |
self.loc.y = self.temploc.y+((-blah.y+heroloc.y)-(self.widhei/2+herosize/2)) | |
end | |
end | |
else | |
self.offs = vec2(0,0) | |
end | |
end | |
levels = { | |
{1,0,1,1,1,1,1,1,1,1,1,1,1,0,1, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,1,1,0,1,1,0,0,0,0,1, | |
1,0,0,0,0,1,0,0,0,1,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,1,0,0,0,1,0,0,0,0,1, | |
1,0,0,0,0,1,1,0,1,1,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
1,0,1,1,1,1,1,1,1,1,1,1,1,0,1}, | |
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
1,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | |
} | |
--# Joystiqs | |
Joystiqs = class() | |
touch = nil | |
originx = nil | |
originy = nil | |
originid = nil | |
touch2 = nil | |
originx2 = nil | |
originy2 = nil | |
originid2 = nil | |
function Joystiqs:init() | |
end | |
function Joystiqs:draw() | |
stroke(127, 127, 127, 25) | |
strokeWidth(0) | |
lineCapMode(SQUARE) | |
if originx ~= nil then | |
fill(0, 0, 255, 100) | |
ellipse(originx, originy, 150) | |
line(originx, originy, linelimiterx, linelimitery) | |
fill(0, 0, 0, 100) | |
ellipse(linelimiterx, linelimitery, 150) | |
end | |
--self:j2Calc() | |
--self:cleanJoystickData() | |
end | |
function Joystiqs:touched(touched) | |
if touched.x < WIDTH/2 and touch == nil and touched.state == BEGAN then | |
touch = touched | |
originid = touched.id | |
originx = touched.x | |
originy = touched.y | |
elseif touch ~= nil and touched.id == originid then | |
touch = touched | |
end | |
if (touched.state == ENDED) and (touched.id == originid) then | |
touch = nil | |
originx = nil | |
originy = nil | |
originid= nil | |
end | |
if touched.x > WIDTH/2 and touch2 == nil and touched.state == BEGAN then | |
touch2 = touched | |
originid2 = touched.id | |
originx2 = touched.x | |
originy2 = touched.y | |
elseif touch2 ~= nil and touched.id == originid2 then | |
touch2 = touched | |
end | |
if (touched.state == ENDED) and (touched.id == originid2) then | |
touch2 = nil | |
originx2 = nil | |
originy2 = nil | |
originid2 = nil | |
end | |
end | |
function Joystiqs:j1Calc() | |
if (touch ~= nil) then | |
offsetx = touch.x - originx | |
offsety = touch.y - originy | |
preangle = (math.atan((offsety)/(offsetx))) | |
if offsetx == 0 and offsety > 0 then | |
angle = math.pi/2 | |
else | |
if offsetx <= 0 and offsety > 0 then | |
angle = math.pi + preangle | |
elseif offsetx < 0 and offsety <= 0 then | |
angle = math.pi + preangle | |
elseif offsetx >=0 and offsety < 0 then | |
angle = (2*math.pi) + preangle | |
else | |
angle = preangle | |
end | |
end | |
if math.sqrt((offsetx*offsetx)+(offsety*offsety)) > 75 then | |
linelimiterx = (75*math.cos(angle)) + originx | |
linelimitery = (75*math.sin(angle)) + originy | |
else | |
linelimiterx = touch.x | |
linelimitery = touch.y | |
end | |
magnitude = math.sqrt(((linelimiterx-originx)^2)+((linelimitery-originy)^2)) | |
if magnitude < 25 and magnitude >10 then | |
magnitude = 0 | |
elseif magnitude <= 10 then | |
magnitude = 0 | |
angle = nil | |
else | |
magnitude = magnitude - 25 | |
end | |
end | |
end | |
function Joystiqs:j2Calc() | |
if (touch2 ~= nil) then | |
offsetx2 = touch2.x - originx2 | |
offsety2 = touch2.y - originy2 | |
preangle2 = (math.atan((offsety2)/(offsetx2))) | |
if offsetx2 == 0 and offsety2 > 0 then | |
angle2 = math.pi/2 | |
else | |
if offsetx2 <= 0 and offsety2 > 0 then | |
angle2 = math.pi + preangle2 | |
elseif offsetx2 < 0 and offsety2 <= 0 then | |
angle2 = math.pi + preangle2 | |
elseif offsetx2 >=0 and offsety2 < 0 then | |
angle2 = (2*math.pi) + preangle2 | |
else | |
angle2 = preangle2 | |
end | |
end | |
if math.sqrt((offsetx2*offsetx2)+(offsety2*offsety2)) > 75 then | |
linelimiterx2 = (75*math.cos(angle2)) + originx2 | |
linelimitery2 = (75*math.sin(angle2)) + originy2 | |
else | |
linelimiterx2 = touch2.x | |
linelimitery2 = touch2.y | |
end | |
magnitude2 = math.sqrt(((linelimiterx2-originx2)^2)+((linelimitery2-originy2)^2)) | |
fill(255, 255, 255, 100) | |
ellipse(originx2, originy2, 150) | |
line(originx2, originy2, linelimiterx2, linelimitery2) | |
fill(0, 0, 0, 100) | |
ellipse(linelimiterx2, linelimitery2, 150) | |
if magnitude2 < 10 then | |
magnitude2 = 0 | |
angle2 = nil | |
else | |
magnitude2 = magnitude2 - 25 | |
end | |
end | |
end | |
function Joystiqs:getmag() | |
return magnitude | |
end | |
function Joystiqs:getang() | |
return angle | |
end | |
function Joystiqs:cleanJoystickData() | |
offsetx=nil | |
offsety=nil | |
offsetx2=nil | |
offsety2=nil | |
preangle=nil | |
preangle2=nil | |
angle=nil | |
angle2=nil | |
linelimiterx=nil | |
linelimitery=nil | |
linelimiterx2=nil | |
linelimitery2=nil | |
magnitude=nil | |
magnitude2=nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment