----------------------- -- Start of menu.lua -- ----------------------- -------------------------- -- Start of process.lua -- -------------------------- ----------------------- -- Start of glib.lua -- ----------------------- platform.apiLevel = '2.3' local disp=platform.window local dispX=disp:width() local dispY=disp:height() function centerText(gc, text, midX, midY) gc:drawString(text, midX-gc:getStringWidth(text)/2, midY-gc:getStringHeight(text)/2, "top") end function centerTextWithRect(gc, text, midX, midY, rectColor) centerText(gc, text, midX, midY) gc:setColorRGB(rectColor) gc:drawRect(midX-gc:getStringWidth(text)/2, midY-gc:getStringHeight(text)/2, gc:getStringWidth(text), gc:getStringHeight(text)) end function drawBoard(gc, sBX, sBY, sX, sY, bW, bH)--sB-sizeBoard, sX-startX, sY-startY, bW-boardWidth, bH-boardHeight local sizeRectX=bW/sBX local sizeRectY=bH/sBY for i=0, sBY do gc:drawLine(sX, sY+sizeRectY*i, sX+bW, sY+sizeRectY*i) end for i=0, sBX do gc:drawLine(sX+sizeRectX*i, sY, sX+sizeRectX*i, sY+bH) end end function fTriangle(gc, x1, y1, x2, y2, x3, y3)--f=fill local points={{x1, y1}, {x2, y2}, {x3, y3}} for i=1, 3 do for j=i,3 do if points[i][2]>points[j][2] then local tmp={points[i][1], points[i][2]} points[i][1]=points[j][1] points[i][2]=points[j][2] points[j][1]=tmp[1] points[j][2]=tmp[2] elseif points[i][2]==points[j][2] then if points[i][1]>points[j][1] then local tmp={points[i][1], points[i][2]} points[i][1]=points[j][1] points[i][2]=points[j][2] points[j][1]=tmp[1] points[j][2]=tmp[2] end end end end if points[1][2]==points[2][2] then--two points are smaller coords. increment y local xSlope1=(points[3][1]-points[1][1])/(points[3][2]-points[1][2]) local xSlope2=(points[3][1]-points[2][1])/(points[3][2]-points[2][2]) local startX=points[1][1] local endX=points[2][1] if endX=360 then self.coords[5]=self.coords[5]-360 end if self.coords[6]>=360 then self.coords[6]=self.coords[6]-360 end gc:drawArc(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5], self.coords[6]) elseif self.type==6 then self:moveCoords(1, x, y) gc:drawString(self.data, self.coords[1], self.coords[2]) elseif self.type==7 then self:moveCoords(1, x, y) gc:drawImage(self.data, self.coords[1], self.coords[2]) elseif self.type==8 then self:moveCoords(1, x, y) gc:drawRoundRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5]) elseif self.type==9 then for i=1, #self.coords, 2 do self:moveCoords(i, x, y) end gc:fillPolygon(self.coords) elseif self.type==10 then self:moveCoords(1, x, y) gc:fillRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4]) elseif self.type==11 then self.coords[1]=self.coords[1]+self.tx+x self.coords[2]=self.coords[2]+self.ty+y self.coords[5]=(self.coords[5]+self.rotAngle)%360 if self.coords[5]>=360 then self.coords[5]=self.coords[5]%360 end if self.coords[6]>=360 then self.coords[6]=self.coords[6]%360 end gc:fillArc(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5], self.coords[6]) elseif self.type==12 then self:moveCoords(1, x, y) gc:fillRoundRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5]) elseif self.type==13 then self:moveCoords(1, x, y) centerText(gc, self.data, self.coords[1], self.coords[2]) elseif self.type==14 then self:moveCoords(1, x, y) local tmpcolors1={math.floor(self.color/0x10000), math.floor((self.color%0x10000)/0x100), self.color%0x100} local tmpcolors2={math.floor(self.color2/0x10000), math.floor((self.color2%0x10000)/0x100), self.color%0x100} gc:fillGradientRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4], tmpcolors1, tmpcolors2) elseif self.type==15 then self:moveCoords(1, x, y) gc:fillCircle(self.coords[1], self.coords[2], self.coords[3]) elseif self.type==16 then self.coords[1]=self.coords[1]+self.tx+x self.coords[2]=self.coords[2]+self.ty+y local tmpcolors1={math.floor(self.color/0x10000), math.floor((self.color%0x10000)/0x100), self.color%0x100} local tmpcolors2={math.floor(self.color2/0x10000), math.floor((self.color2%0x10000)/0x100), self.color%0x100} gc:fillGradientCircle(self.coords[1], self.coords[2], self.coords[3], tmpcolors1, tmpcolors2) end for i=1, #self.coords do self.coords[i]=self.tmpCoords[i] end end end do glib=class() function glib:init(width, height) self.width=width self.height=height self.Shapes={} self.rotAngle=0 end function glib:addShape(s, x, y, rotAngle) self.Shapes[#self.Shapes+1]=shape.clone(s) self.Shapes[#self.Shapes]:translate(x, y) end function glib:rotate(angle) self.rotAngle=angle%360 end function glib:changeRot(angle) self.rotAngle=(self.rotAngle+angle)%360 end function glib:draw(gc, x, y, mode) local changeX=0 local changeY=0 if mode~=nil then if mode=="middle" then changeX=self.width/2 changeY=self.height/2 elseif mode=="midtop" then changeX=self.width/2 elseif mode=="midbottom" then changeX=self.width/2 changeY=self.height end end gc:clipRect("set", x-changeX, y-changeY, self.width, self.height) for i=1, #self.Shapes do local tmp=self.Shapes[i].rotAngle self.Shapes[i]:rotate(self.Shapes[i].rotAngle+self.rotAngle) self.Shapes[i]:draw(gc, x, y) self.Shapes[i]:rotate(tmp) end gc:clipRect("reset") end end --------------------- -- End of glib.lua -- --------------------- require ('physics') local vec=physics.Vect local mouse=vec(0,0) local millis=timer.getMilliSecCounter lockTopProcess=false process = class() process.name="" process.inputEnabled=true process.priority=0--1 is always. 2 is run at least once every two runs. 3 can't skip 4 runs in a row. 4 only runs if fps is above target. Also set 0 if disabling process. This only increments unsuc/sets unsuc to 0 upon timer run process.paintPriority=0--0 if a background process process.targetFPS=30--if fps dips below target, then if priority is not 1 it will skip running the process unless it meets the minimum run amount process.lastRun=0--set to millis() upon starting process process.lastPaint=0 process.numUnsucRuns=0--resets after a successful run process.numPaintUnsuc=0 function process:setDefaults() self.inputEnabled=true self.priority=1 self.paintPriority=1 self.targetFPS=30 self.lastRun=millis() self.lastPaint=millis() end function process:deactivate() self.priority=0 self.paintPriority=0 self.inputEnabled=false end function process:deactivatePrior() self.priority=0 self.paintPriority=0 end function process:setBackground(priority) if priority~=nil then self.priority=priority self.lastRun=millis() end self.paintPriority=0 end function process:setPaintable(priority) self.paintPriority=priority self.lastPaint=millis() end function process:setPriorities(prior, paintPrior, input) self.priority=prior self.paintPriority=paintPrior self.lastRun=millis() self.lastPaint=millis() if input~=nil then self.inputEnabled=input else self.inputEnabled=true end end function process:init() end function process:paint(gc, x, y, width, height) end function process:timer() end function process:charIn(ch) end function process:arrowKey(key) end function process:escapeKey() end function process:enterKey() end function process:tabKey() end function process:contextMenu() end function process:backtabKey() end function process:backspaceKey() end function process:clearKey() end function process:mouseMove(x, y) end function process:mouseDown(x, y) end function process:mouseUp() end function process:rightMouseDown(x, y) end function process:help() end function process:varChange(varList) end function process:Open() end function process:Close() end function process:activate() end function process:recovery() end local processes = {} function PushProcess(proc) table.insert(processes, proc) proc:setDefaults() proc:Open() disp:invalidate() end function PullProcess() if #processes > 1 then print("pulling: "..processes[#processes].name) processes[#processes]:Close() table.remove(processes) if #processes>0 then processes[#processes]:activate() end disp:invalidate() end end -- Link events to processManager function on.paint(gc, x, y, width, height) if not lockTopProcess then for _, proc in pairs(processes) do if proc.paintPriority==1 then proc:paint(gc, x, y, width, height) elseif proc.paintPriority==2 then if millis()-proc.lastPaint>=1000/proc.targetFPS then proc:paint(gc) proc.lastPaint=millis() else if proc.numPaintUnsuc>=1 then proc:paint(gc, x, y, width, height) proc.numPaintUnsuc=0 proc.lastPaint=millis() else proc.numPaintUnsuc=proc.numPaintUnsuc+1 proc.lastPaint=millis() end end elseif proc.paintPriority==3 then if millis()-proc.lastPaint>=1000/proc.targetFPS then proc:paint(gc, x, y, width, height) proc.lastPaint=millis() else if proc.numPaintUnsuc>=3 then proc:paint(gc, x, y, width, height) proc.numPaintUnsuc=0 proc.lastPaint=millis() else proc.numPaintUnsuc=proc.numPaintUnsuc+1 proc.lastPaint=millis() end end elseif proc.paintPriority==4 then if millis()-proc.lastPaint>=1000/proc.targetFPS then proc:paint(gc, x, y, width, height) proc.lastPaint=millis() end end end else processes[#processes]:paint(gc, x, y, width, height) processes[#processes].lastPaint=millis() end end function on.timer() if not lockTopProcess then for _, proc in pairs(processes) do if proc.priority==1 then proc:timer() proc.lastRun=millis() elseif proc.priority==2 then if millis()-proc.lastRun<=1000/proc.targetFPS then proc:timer() proc.lastRun=millis() else if proc.numPaintUnsuc>=1 then proc:timer() proc.numPaintUnsuc=0 proc.lastRun=millis() else proc.numPaintUnsuc=proc.numPaintUnsuc+1 proc.lastRun=millis() end end elseif proc.priority==3 then if millis()-proc.lastRun<=1000/proc.targetFPS then proc:timer() proc.lastRun=millis() else if proc.numPaintUnsuc>=3 then proc:timer() proc.numPaintUnsuc=0 proc.lastRun=millis() else proc.numPaintUnsuc=proc.numPaintUnsuc+1 proc.lastRun=millis() end end elseif proc.priority==4 then if millis()-proc.lastRun<=1000/proc.targetFPS then proc:timer() proc.lastRun=millis() end end end else processes[#processes]:timer() processes[#processes].lastRun=millis() end end function on.charIn(ch) if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:charIn(ch) end end end else processes[#processes]:charIn(ch) end --disp:invalidate() end function on.arrowKey(key) if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:arrowKey(key) end end end else processes[#processes]:arrowKey(key) end --disp:invalidate() end function on.escapeKey() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:escapeKey() end end end else processes[#processes]:escapeKey() end --disp:invalidate() end function on.enterKey() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:enterKey() end end end else processes[#processes]:enterKey() end --disp:invalidate() end function on.tabKey() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:tabKey() end end end else processes[#processes]:tabKey() end --disp:invalidate() end function on.contextMenu() for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:contextMenu() end end end --disp:invalidate() end function on.backtabKey() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:backtabKey() end end end else processes[#processes]:backtabKey() end --disp:invalidate() end function on.backspaceKey() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:backspaceKey() end end end else processes[#processes]:backspaceKey() end --disp:invalidate() end function on.clearKey() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:clearKey() end end end else processes[#processes]:clearKey() end --disp:invalidate() end function on.mouseDown(x, y) if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:mouseDown(x, y) end end end else processes[#processes]:mouseDown(x, y) end --disp:invalidate() end function on.mouseUp() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:mouseUp() end end end else processes[#processes]:mouseUp() end end function on.mouseMove(x, y) mouse=vec(x, y) if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:mouseMove(x, y) end end end else processes[#processes]:mouseMove(x, y) end end function on.rightMouseDown(x, y) if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:rightMouseDown(x, y) end end end else processes[#processes]:rightMouseDown(x,y) end --disp:invalidate() end function on.help() if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then proc=processes[i] if proc.inputEnabled then proc:help() end end end else processes[#processes]:help() end --disp:invalidate() end function on.varChange(varList) if not lockTopProcess then for i=1, #processes do if processes[i]~=nil then if proc.inputEnabled then proc:varChange(varList) end end end else processes[#processes]:varChange(varList) end --disp:invalidate() end function printProcessNames() for i=1, #processes do if processes[i]~=nil then print(processes[i].name) end end end function unLockProcesses() for _, proc in pairs(processes) do proc.lastRun=millis() proc.lastPaint=millis() end lockTopProcess=false end function procRecovery() for _, proc in pairs(processes) do proc:recovery() end end ------------------------ -- End of process.lua -- ------------------------ local milSecs=1000--seconds to milliseconds local minSecs=60--seconds to minutes do menu=process() menu.items={} menu.backs={} menu.x=1 menu.curBack=1 menu.prevBackTime=millis() menu.backSecs=5 do menu.menuItem=class() function menu.menuItem:init() self.items=menu.items self.backs=menu.backs self.x=menu.x self.curBack=menu.curBack self.prevBackTime=menu.prevBackTime self.backSecs=menu.backSecs end end function menu:reset() self.items={} self.back={} self.x=1 self.curBack=1 self.prevBackTime=millis() self.backSecs=5 end function menu:setMenuItem(item) self.items=item.items self.backs=item.backs self.x=item.x self.curBack=item.curBack self.prevBackTime=item.prevBackTime self.backSecs=item.backSecs end function menu:drawBackground(gc) if self.backs[self.curBack]~=nil then gc:drawImage(self.backs[self.curBack], -1,0) end end function menu:arrowKey(key) if key=="up" then if self.x>1 then self.x=self.x-1 else self.x=#self.items end elseif key=="down" then if self.x<#self.items then self.x=self.x+1 else self.x=1 end end disp:invalidate() end function menu:add(name, item) self.items[#self.items+1]={n=name, i=item, id=#self.items+1} end function menu:paint(gc) self:drawBackground(gc) for _, item in pairs(self.items) do gc:setColorRGB(0x000000) centerText(gc, item.n, dispX/2, dispY/2-gc:getStringHeight(item.n)*(#self.items/2-item.id+1/2)*2/3) if item.id==self.x then gc:drawRect(dispX/2-gc:getStringWidth(item.n)/2, dispY/2-gc:getStringHeight(item.n)*(#self.items/2-item.id+1)*2/3, gc:getStringWidth(item.n), gc:getStringHeight(item.n)*2/3) end end gc:setFont("sansserif", "r", 18) if self.title~=nil then if self.titleColor~=nil then gc:setColorRGB(self.titleColor) end centerText(gc, self.title, dispX/2, gc:getStringHeight(self.title)/2, "top") end end function menu:setBackSecs(secs) self.backSecs=secs end function menu:timer() if millis()-self.prevBackTime>self.backSecs*1000 then if self.curBack<#self.backs then self.curBack=self.curBack+1 else self.curBack=1 end self.prevBackTime=millis() end disp:invalidate() end function menu:addBackground(img) self.backs[#self.backs+1]=img:copy(dispX+1, dispY) end function menu:activate() self:setDefaults() end function menu:Open() self.name="menu" self:setDefaults() end function menu:Close() self:deactivate() end function menu:enterKey() self:deactivate() PushProcess(self.items[self.x].i) disp:invalidate() end function menu:mouseDown(x, y) self:deactivate() PushProcess(self.items[self.x].i) disp:invalidate() end function menu:setTitle(title, color) self.title=title self.titleColor=color end end do readme=process() readme.hlpInfo="" readme.dispHelp=D2Editor.newRichText() function readme:Open() --self:deactivate() --self.inputEnabled=true self.dispHelp:setVisible(false) self.dispHelp:setText(self.hlpInfo, 1) self.dispHelp:move(0, 0) self.dispHelp:setBorder(0) self.dispHelp:setReadOnly(true) self.dispHelp:resize(dispX, dispY) self.dispHelp:setVisible(true) end function readme:timer() self.dispHelp:setFocus(true) end function readme:Close() self.dispHelp:setFocus(false) self.dispHelp:setVisible(false) end function readme:escapeKey() PullProcess() end function readme:backspaceKey() PullProcess() end function readme:setText(text) self.hlpInfo=text end end do settings=process() local func=nil local list={} local x=1 function settings:setFunc(f) func=f end function settings:addSetting(name, amount) list[#list+1]={n=name, ant=amount, id=#list+1} end function settings:addSettings(setts) for _, i in pairs(setts) do self:addSetting(i.n, i.ant) end end function settings:arrowKey(key) if key=="up" then if x>1 then x=x-1 else x=#list end elseif key=="down" then if x<#list then x=x+1 else x=1 end elseif key=="left" or key=="right" then list[x].ant=func(list[x], key) end disp:invalidate() end function settings:paint(gc) for _, item in pairs(list) do gc:setColorRGB(0x000000) centerText(gc, item.n..item.ant, dispX/2, dispY/2-gc:getStringHeight(item.n..item.ant)*(#list/2-item.id+1/2)*2/3) if item.id==x then gc:drawRect(dispX/2-gc:getStringWidth(item.n..item.ant)/2, dispY/2-gc:getStringHeight(item.n..item.ant)*(#list/2-item.id+1)*2/3, gc:getStringWidth(item.n..item.ant), gc:getStringHeight(item.n..item.ant)*2/3) end end end function settings:escapeKey() PullProcess() end end --[[do hlpScreen=process() hlpScreen.hlpInfo="Going to be made" hlpScreen.dispHelp=D2Editor.newRichText() function hlpScreen:Open() --self:deactivate() --self.inputEnabled=true self.dispHelp:move(0,0) self.dispHelp:setBorder(0) self.dispHelp:setReadOnly(true) self.dispHelp:setText(self.hlpInfo) self.dispHelp:resize(318, 212) self.dispHelp:setVisible(true) end function hlpScreen:Close() self.dispHelp:setVisible(false) end function hlpScreen:escapeKey() PullProcess() end end function on.construction() --menu:setBackground(image.new(_R.IMG.background)) --game:setBackground(image.new(_R.IMG.background)) --menu:add("Play", game) --menu:add("Help Screen", hlpScreen) --menu:add("Settings", settings) PushProcess(menu) disp:invalidate() end function on.activate() timer.start(5) disp:invalidate() end function on.deactivate() timer.stop() end]] --------------------- -- End of menu.lua -- --------------------- ------------------------------- -- Start of errorHandler.lua -- ------------------------------- authorEmail="andyhsstudent@gmail.com" errorDetailsEnabled=true do errorHandler=process() local curError="" local line=0 local recovery=nil local dispHelp=D2Editor.newRichText() function errorHandler:setError(l, e) curError=e line=l end function errorHandler:Open() lockTopProcess=true dispHelp:setVisible(false) dispHelp:setText("Here is the technical info:\n"..curError, 1) dispHelp:move(0, 60) dispHelp:setBorder(5) dispHelp:setBorderColor(0xFF0000) dispHelp:setReadOnly(true) dispHelp:resize(dispX, 85) dispHelp:setVisible(true) disp:invalidate() end function errorHandler:Close() dispHelp:setFocus(false) dispHelp:setVisible(false) unLockProcesses() if recovery~=nil then recovery() end end function errorHandler:paint(gc) gc:setColorRGB(0x0000FF) gc:fillRect(0,0,dispX,dispY) gc:setColorRGB(0x000000) gc:setFont("serif", "r", 16) gc:drawString("Oops. Something happened :(", 0, 0) gc:drawString("Press enter to go back", 0, gc:getStringHeight("Oops. Something happened :(")) gc:setFont("serif", "r", 12) gc:drawString("Send the error message to:" , 0, 150) gc:drawString(authorEmail , 0, 150+gc:getStringHeight("Send the error message to:")) end function errorHandler:enterKey() PullProcess() end function errorHandler:setRecovery(func) recovery=func end end errorHandler:setRecovery(procRecovery) function handleError(l, e) if errorDetailsEnabled then errorHandler:setError(l, e) PushProcess(errorHandler) end end platform.registerErrorHandler(function(l,e,stack,locals) handleError(l, e) return true end) ----------------------------- -- End of errorHandler.lua -- ----------------------------- --------------------- -- Start of 3D.lua -- --------------------- --[[platform.apiLevel = '2.3' local disp=platform.window local dispX=disp:width() local dispY=disp:height()]] local rotAng={0,0,0} local position={0,0,20} local cube={ ver={{10,-10,-10}, {-10,-10,-10}, {-10,10,-10}, {10, 10,-10}, {10,10,10}, {-10,10,10}, {-10,-10,10}, {10,-10,10}}, line={{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 1}, {1, 4}, {2, 7}, {3, 6}, {5, 8}}, face={} } function sign(x) if x==math.abs(x) then return 1 else return -1 end end function c3D2D(coords, rot, pos, origin, scale, zSize, addDisp) local settings={ {'Angle Mode', 'Radian'} } math.setEvalSettings(settings) local Coords2D=nil local t={coords[1]-origin[1], coords[2]-origin[2], coords[3]-origin[3]} local mag=math.sqrt(t[1]*t[1]+t[2]*t[2]+t[3]*t[3]) local magyz=math.sqrt(t[3]*t[3]+t[2]*t[2]) local magxy=math.sqrt(t[1]*t[1]+t[2]*t[2]) local magxz=math.sqrt(t[1]*t[1]+t[3]*t[3]) local ang={math.atan2(t[1], magyz)+rot[2], math.atan2(t[2], magxz)+rot[1], math.atan2(t[3], magxy)+rot[3]} --local ang={math.atan2(z, y)+rot[1], math.atan2(x, z)+rot[2], math.atan2(y, x)+rot[3]} t[1]=math.sin(ang[1])*mag+pos[1] t[2]=math.sin(ang[2])*mag+pos[2] t[3]=math.sin(ang[3])*mag+pos[3] if t[3]>=0 then--math.sqrt(t[3]), (1+t[3]/zSize) local offset=1 Coords2D={} Coords2D[1]=t[1]/(1+t[3]/zSize)*scale Coords2D[2]=t[2]/(1+t[3]/zSize)*scale if addDisp==nil or addDisp then Coords2D[1]=Coords2D[1]+dispX/2 Coords2D[2]=Coords2D[2]+dispY/2 end --Coords2D={t[1]*yDist*25+dispX/2,dispY/2-t[3]*yDist*25} end return Coords2D end function drawShape(gc, shape, rot, pos, origin, scale, zSize, mode, colors, addDisp) local vertices2d={} for i=1, #shape.ver do vertices2d[i]=c3D2D(shape.ver[i], rot, pos, origin, scale, zSize, addDisp) end if mode==nil or mode=="point" then if colors~=nil and colors[1]~=nil then gc:setColorRGB(colors[1]) end for _, i in pairs(vertices2d) do if i~=nil then gc:drawRect(i[1], i[2], 1, 1) end end end if mode=="faces" then if colors~=nil and colors[2]~=nil then gc:setColorRGB(colors[2]) end for i=1, #shape.faces do local poly={} local drawPoly=true for f, j in pairs(shape.faces[i]) do if vertices2d[j]~=nil then poly[f*2-1]=vertices2d[j][1] poly[f*2]=vertices2d[j][2] else drawPoly=false break end end if drawPoly then gc:fillPolygon(poly) end end end if mode=="line" or mode=="faces" then if colors~=nil and colors[1]~=nil then gc:setColorRGB(colors[1]) end for i=1, #shape.line do if vertices2d[shape.line[i][1]]~=nil and vertices2d[shape.line[i][2]]~=nil then gc:drawLine(vertices2d[shape.line[i][1]][1], vertices2d[shape.line[i][1]][2], vertices2d[shape.line[i][2]][1], vertices2d[shape.line[i][2]][2]) end end end end function rotatePoint(point, axis, angle) local rotPoint={point[1], point[2], point[3]} local changePoints={} if axis=="x" then changePoints={3, 2} elseif axis=="y" then changePoints={1, 3} else changePoints={2, 1} end local mag=math.sqrt(math.pow(rotPoint[changePoints[1]], 2)+math.pow(rotPoint[changePoints[2]], 2)) local ang=math.atan2(rotPoint[changePoints[1]], rotPoint[changePoints[2]])+angle rotPoint[changePoints[1]]=math.sin(ang)*mag rotPoint[changePoints[2]]=math.cos(ang)*mag return rotPoint end function rotateShape(shape, axis, angle) local rotShape={} for i=1, #shape do rotShape[i]=rotatePoint(shape[i], axis, angle) end return rotShape end --[[function on.paint(gc) drawShape(gc, cube, rotAng, position, origin, 5, 50, "line") end function on.arrowKey(key) if key=="up" then rotAng[1]=rotAng[1]+math.pi/32 elseif key=="down" then rotAng[1]=rotAng[1]-math.pi/32 elseif key=="left" then rotAng[2]=rotAng[2]-math.pi/32 else rotAng[2]=rotAng[2]+math.pi/32 end disp:invalidate() end function on.mouseDown() rotAng[3]=rotAng[3]+math.pi/32 disp:invalidate() end function on.charIn(c) print(c) if c=="a" or c=="4" then origin[1]=origin[1]-1 elseif c=="d" or c=="6" then origin[1]=origin[1]+1 elseif c=="w" or c=="8" then origin[2]=origin[2]+1 elseif c=="s" or c=="2" then origin[2]=origin[2]-1 elseif c=="7" then origin[3]=origin[3]-0 elseif c=="9" then origin[3]=origin[3]+0.1 end disp:invalidate() end]] ------------------- -- End of 3D.lua -- ------------------- local adder=40 local curvThingy={ ver={{0, dispY, 0}, {dispX, dispY, 0}, {dispX, 0, 0}, {0,0,0}, {0,0,adder}, {dispX,0, adder}, {dispX,dispY, adder}, {0, dispY, adder}}, line={{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 1}, {1, 4}, {2, 7}, {3, 6}, {5, 8}}, face={} } --[[local ball={ ver={{-8, 8, 0}, {8, 8, 0}, {8, -8, 0}, {-8,-8,0}, {-8,-8,80}, {8,-8, 80}, {8,8, 80}, {-8, 8, 80}}, line={{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 1}, {1, 4}, {2, 7}, {3, 6}, {5, 8}} }]] local paddle={20, 15} local paddleDisp={ ver={{-paddle[1], -paddle[2], 0}, {-paddle[1], paddle[2], 0}, {paddle[1], paddle[2], 0}, {paddle[1], -paddle[2], 0}}, line={{1, 2}, {2, 3}, {3, 4}, {4, 1}}, faces={{1,2,3,4}} } local originCurv={dispX/2,dispY/2,0} local origin={0,0,0} local zScale=80 local boxSize={dispX, dispY, 160} local settList={ mouse={n="Movement type: ", ant="mouse"} } do game=process() local ballCoords={0,0,0} local maxBallSize=24 local ballVelocity={40,30,60} local player={0,0,0} local enemCoords={0,0,boxSize[3]} local ballSpdZ=30 local moveAmount=15 local moveMode="mouse" local difficulty=2 local speeds={ {30, 30}, {40, 40}, {55, 55}, {75, 75}, {100, 100}, {150, 150}, {300, 300} } function game:editSettings(item, key) if item.n==settList.mouse.n then if moveMode=="keys" then moveMode="mouse" elseif moveMode=="mouse" then moveMode="keys" end return moveMode end end function drawArea(gc) local pos={0,0,0} local rect={ ver={{-dispX/2, -dispY/2, 0}, {-dispX/2, dispY/2, 0}, {dispX/2, dispY/2, 0}, {dispX/2, -dispY/2, 0}}, line={{1,2}, {2,3}, {3,4}, {4,1}} } for i=0, boxSize[3]-adder, adder do pos[3]=i drawShape(gc, curvThingy, {0,0,0}, pos, originCurv, 1, zScale, "line", {0x00FF00}) end drawShape(gc, rect, {0,0,0}, {0,0, ballCoords[3]}, origin, 1, zScale, "line", {0x00FFFF}) originCurv[3]=0 end function drawBall(gc) local tmpRd={maxBallSize, maxBallSize, ballCoords[3]} local tmp=c3D2D(ballCoords, {0,0,0}, {0,0,0}, origin, 1, zScale) local rd=c3D2D(tmpRd, {0,0,0}, {0,0,0}, origin, 1, zScale, false) gc:setColorRGB(0x00FF00) gc:fillArc(tmp[1]-rd[1]/2, tmp[2]-rd[2]/2, rd[1], rd[2], 0, 360) end function game:Open() timer.start(1/30) end function game:Close() timer.stop() end function game:paint(gc) gc:setColorRGB(0x000000) gc:fillRect(0,0,dispX, dispY) drawArea(gc) drawShape(gc, paddleDisp, {0,0,0}, enemCoords, origin, 1, zScale, "faces", {0x00FF00, 0x0000FF}) drawBall(gc) drawShape(gc, paddleDisp, {0,0,0}, player, origin, 1, zScale, "faces", {0x00FF00, 0xFF0000}) end function collisionTest(enem) local coords={player[1], player[2]} if enem then coords={enemCoords[1], enemCoords[2]} end if math.abs(coords[1]-ballCoords[1])originCurv[i] then player[i]=originCurv[i]-paddle[i] end end for i=1, 2 do if enemCoords[i]-paddle[i]<-originCurv[i] then enemCoords[i]=-originCurv[i]+paddle[i] end if enemCoords[i]+paddle[i]>originCurv[i] then enemCoords[i]=originCurv[i]-paddle[i] end end for i=1, #ballCoords do ballCoords[i]=ballCoords[i]+ballVelocity[i]*(t-self.lastRun)/1000 if ballVelocity[i]<0 and ballCoords[i]<=-originCurv[i] then ballVelocity[i]=ballVelocity[i]*(-1) if i==3 and (not collisionTest(false)) then PullProcess() end ballCoords[i]=ballCoords[i]+ballVelocity[i]*(t-self.lastRun)/500 elseif ballVelocity[i]>=0 and ballCoords[i]>=boxSize[i]-originCurv[i] then ballVelocity[i]=ballVelocity[i]*(-1) if i==3 and (not collisionTest(true)) then PullProcess() end ballCoords[i]=ballCoords[i]+ballVelocity[i]*(t-self.lastRun)/500 end end moveAi(t, self.lastRun) disp:invalidate() end function game:mouseMove() if moveMode=="mouse" then player[1]=mouse:x()-originCurv[1] player[2]=mouse:y()-originCurv[2] end end function game:charIn(c) if moveMode~="mouse" then if c=="8" then player[2]=player[2]-moveAmount elseif c=="2" then player[2]=player[2]+moveAmount elseif c=="4" then player[1]=player[1]-moveAmount elseif c=="6" then player[1]=player[1]+moveAmount elseif c=="7" then player[1]=player[1]-moveAmount player[2]=player[2]-moveAmount elseif c=="9" then player[1]=player[1]+moveAmount player[2]=player[2]-moveAmount elseif c=="1" then player[1]=player[1]-moveAmount player[2]=player[2]+moveAmount elseif c=="3" then player[1]=player[1]+moveAmount player[2]=player[2]+moveAmount end end end function game:escapeKey() PullProcess() end end function editSettings(item, key) return game:editSettings(item, key) end function on.construction() settings:setFunc(editSettings) settings:addSettings(settList) menu:add("play", game) menu:add("readme", readme) menu:add("settings", settings) menu:setTitle("Curvball") PushProcess(menu) end