0Y<,±>Sï}WÿÍu§ðp8·d%qyâYÎ;]ÉAŠösï÷ôôô”°ÂVl†3????????????????????55 3 1 0011345 5 6 7 7 89:;;;<=====>>>¿?DD@DDDDÌÌ ÌÌ @@ÌÌ ÌÀÌ@DDÌÀ ÌÌÌ ÌÌ@ÀÌÀÀ ÀÀ ÌÀ ÀÌÌ ÌÌ@ÌÌ @DÐÝÝÝÝÝÝÝÝÝ ÝÝ ÐÝÐÝÝ Ý ÝÐ PUÝÐ UUPÝÐ UUPÝÐ pUUUÐÐUUUÐ ÝUUU PUÐÐÐ pÝ  ÐÐ ÐÐ ppp ÐÐ ÐÐppppppÐÐ @ÐÐ @Ð Ð@   @ ÐÐÐÐ °  »» Ð@»»ÐÐ p@° ÐÐp@Ð ppp@  ppp  ÐÐÝÝppÐÐÐÝÝ ÐÐÝÝÝÝÐÐÝÝÝÐÐÐÝÝÝÐpp ÝÝ Ðp ÝÐ ÐÝÝ   ª ÝÝ ªª ÐÝÝ   ªªª ÝÝÝÝ pªª ÝÝÝÐ ª ÝÝÝÐ  ªª ÝÝ Ð  ª ÝÐ pp    ÐÝÝ  ÝÝ  ÐÝÝ  ÝÝÝÝ p ÝÝÝÐÿÐÿÐÝÝÝÐÿÐÿÐÝÝ ÐÐÐÝÐÐppÐÐÝÝ ÐÐ   pÐÐÐÐÐÐ pp ÐÐÐÐ  ÐÐÐÐ ÐÐÐÐ ÐpÐ pý pppýÐpppÐ ÐÐ Ð ÝÐÐ Ð ÝÐÐÝÐ UUÝÐ PPUÝÐ PPUÝÐ PUUpÝ Ý PUUÐÝÐÝPUUÝÝ ÝÝ UUÐÝÝÝÝÝÝÝppÝÝÝÝÝÝÐÝÝ ÐÝÝ ÐÝÝ ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÐÝÝÝÐÝÝÝÐÝÝÝÐÝÝÝÐÝÝÝÐÝÝ ÐÝÝ ÐÝÝ ÐÝÐÝÐÝÐÐÝÝ ÐÝÝ ÐÝÝ pj-- title: Lil'Wiz Aventure -- author: Edmaul -- desc: A wip short dungeon crawling -- site: website link -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua --joystick values are stored in x and y --from -1 to 1 palette_map=0x3ff0 joysticks={ {pos={ x=3*8, y=12*8, r=10 }, x=0, y=0, use=false, color=5}, {pos={ x=3*8, y=12*8, r=20 }, x=0, y=0, use=false, color=12}, {pos={ x=180, y=68, r=30 }, x=0, y=0, use=false, color=11} } joystickinuse=false x=120 y=30 mx,my,mp=mouse() maux=false v=joysticks[2] function updatejoystick(j) xdif=mx-j.pos.x ydif=my-j.pos.y if mp == true and maux == false then maux=true j.pos.x=mx j.pos.y=my elseif mp == false and maux == true then maux=false end if mp==true then drawjoystick(j) end if not joystickinuse and mp and (xdif^2+ydif^2)1 then local angle=math.atan2(j.y,j.x) j.x=math.cos(angle) j.y=math.sin(angle) end end function drawjoystick(j) if maux then circb(j.pos.x,j.pos.y,j.pos.r,15) circ(j.pos.x,j.pos.y,j.pos.r/4,15) --for i=0,1,0.1 do -- circ(j.pos.x+j.x*j.pos.r*i,j.pos.y+j.y*j.pos.r*i,j.pos.r/(4-i),0) --end circ(j.pos.x+j.x*j.pos.r,j.pos.y+j.y*j.pos.r,j.pos.r/2,j.color) else return end end ---------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------- solidos={[1]=true,[2]=true,[3]=true,[4]=true ,[20]=true,[21]=true,[19]=true,[33]=true,[34]=true,[35]=true ,[49]=true,[48]=true,[16]=true,[17]=true,[18]=true ,[19]=true,[32]=true} telaAtual={x=0,y=0} cam={x=120,y=68} iniNaTela = 0 gamestate='m' function init() sync(0,0,false) plr=p plr.xx=0 plr.yy=0 telaAtual={x=0,y=0} arm=a e={} inimigos={} bs={} itens={} cam={x=120,y=68} iniNaTela = 0 t=0 spwEnts() spwPorta() chaves=0 end --t=0 cos=math.cos sin=math.sin pi=math.pi tau=2*pi atan2=math.atan2 sqrt=math.sqrt flr=math.floor ceil=math.ceil rnd=math.random e={} function e:new(o) o=o or {} setmetatable(o,self) self.__index=self return o end function e:draw() if self.xx and self.yy and self.xx==telaAtual.x and self.yy==telaAtual.y then sprol(self.img+t%30//15*ceil(self.w/8),self.x,self.y,8,1,self.f,0,ceil(self.w/8),ceil(self.h/8)) end end p=e:new{ x=120, y=64, xx=0, yy=0, w=8, h=8, vx=0, vy=0, vec={x=1,y=0}, img=256, f=0, v=0.5, state='i', animaux=1, vidaMax=5, vida=5, htmr=0, htmp=30, msg='', msgTmr=0, isdash=true, dv=2.5, dTmr=0, dTmp=10, dCd=70, dCdT=0 } function p:update() self:takehit() local x,y=self.x,self.y if self.state~='d' then if self.isdash then self:dash() end if v.y < 0 or btn(0) and not solido(x+1,y-self.v+1) and not solido(x+self.w-1,y-self.v+1) then self.vy=-1 elseif v.y > 0 or btn(1) and not solido(x+1,y+self.v+self.h) and not solido(x+self.w-4,y+self.v+self.h) then self.vy=1 else self.vy=0 end if v.x < 0 or btn(2) and not solido(x+1-self.v,y+1) and not solido(x+1-self.v,y+self.h) then self.vx=-1 self.f=1 elseif v.x > 0 or btn(3) and not solido(x+self.v+self.w-1,y+1) and not solido(x+self.v+self.w-1,y+self.h) then self.vx=1 self.f=0 else self.vx=0 end --self.vx=v.x --self.vy=v.y -- --local x,y=self.x,self.y --if (self.vec.x~=0 and --(self.vec.x < 0 and not solido(self.x-1,self.y) --and not solido(self.x-1,self.y+self.h)) --or --(self.vec.x > 0 and not solido(self.x+1+self.w,self.y) --and not solido(self.x+1+self.w,self.y+self.h)) --) --then -- self.x=self.x+(self.vx*self.v) --end -- --if (self.vec.y~=0 and --(self.vec.y < 0 and not solido(self.x,self.y-1) --and not solido(self.x+self.w,self.y-1)) --or --(self.vec.y > 0 and not solido(self.x,self.y+1+self.h) --and not solido(self.x+self.w,self.y+1+self.h)) --) --then -- self.y=self.y+(self.vy*self.v) --end if self.vx==0 and self.vy==0 then self.state='i' else self.state='m' end if self.vx==0 and self.vy==0 then self.animaux=0 else self.animaux=1 end self.x=self.x+self.vx*self.v self.y=self.y+self.vy*self.v end if self.x > 240 then self.x = self.w+1 self.xx= self.xx+1 end if self.x < 0 then self.x = 240-self.w-1 self.xx=self.xx-1 end if self.y > 136 then self.y = self.h+1 self.yy=self.yy+1 end if self.y < 0 then self.y = 136-self.h-1 self.yy=self.yy-1 end if (self.vx~=0 and self.vy~=0) then if self.vx > 0 then self.vec.x = 1/sqrt(2) else self.vec.x = -1/sqrt(2) end if self.vy > 0 then self.vec.y = 1/sqrt(2) else self.vec.y = -1/sqrt(2) end --self.anim =self.animacoes.move elseif(self.vx==0 and self.vy~=0) or (self.vx~=0 and self.vy==0) then --self.anim =self.animacoes.move self.vec.x=self.vx self.vec.y=self.vy end end function p:dash() if btnp(4) and self.dash and self.dCdT<=0 then self.dTmr=self.dTmp self.dCdT=self.dCd end if self.dCdT > 0 then self.dCdT=self.dCdT-1 end if self.dTmr>0 then self.dTmr=self.dTmr-1 self.state='d' local x,y=self.x,self.y if (self.vec.x~=0 and (self.vec.x < 0 and not solido(self.x-self.v,self.y) and not solido(self.x-self.v,self.y+self.h)) or (self.vec.x > 0 and not solido(self.x+self.v+self.w,self.y) and not solido(self.x+self.v+self.w,self.y+self.h)) ) then self.x=self.x+(self.vec.x*self.dv) end if (self.vec.y~=0 and (self.vec.y < 0 and not solido(self.x,self.y-self.v) and not solido(self.x+self.w,self.y-self.v)) or (self.vec.y > 0 and not solido(self.x,self.y+self.v+self.h) and not solido(self.x+self.w,self.y+self.v+self.h)) ) then self.y=self.y+(self.vec.y*self.dv) end else -- print(self.dCdT,self.x,self.y-4 end print(self.dCdT,self.x,self.y-4) end function p:takehit() if self.htmr>0 then self.htmr=self.htmr-1 -- if self.htmr>self.htmp/2 then -- self.x=self.x+self.kbx*self.kb -- self.y=self.y+self.kby*self.kb --end end for j=1,#inimigos do if col(self,inimigos[j]) and inimigos[j].dano and self.htmr<=0 and self.dTmr<=0 then parts(self.x+self.w/2,self.y+self.h/2,20,12) self.kb=inimigos[j].kb self.kbx=inimigos[j].vec.x self.kby=inimigos[j].vec.y self.htmr = self.htmp self.vida=self.vida-inimigos[j].dano if inimigos[j].isbala then inimigos[j].ativo=false end if self.vida <= 0 then self.y=68 self.vida=self.vidaMax self.x=120 self.yy=0 self.xx=0 gamestate='g' --sync() end end end end function p:draw() --hud local x,y=0*8,0*8 rect(x,y,46,10,0) print(self.vida..'/'..self.vidaMax,x+2,y+2,12) print(':'..chaves,x+32,y+2,12) spr(274,x+22,y+0,8) -- if self.dTmr>0 then part(self.x+self.w/2-self.vec.x*4,self.y+self.h/2-self.vec.y*4,13,10) end if self.htmr>0 then if t%(60*0.3)//(30*0.3)==0 then return end end local x,y=self.x,self.y if self.state=='m' then self.img=258 elseif self.state=='i' then --self.animaux = 0 self.img=256 end if self.msgTmr>0 then self.msgTmr=self.msgTmr-1 print(self.msg,x,y-9,12) end --print(self.vec.x..'/'..self.vec.y,x,y-9) sprol(self.img+t%15//7.5*ceil(self.w/8),x,y,8,1,self.f,0,ceil(self.w/8),ceil(self.h/8)) end bs={} b=e:new{--tiro base x=0, y=0, w=4, h=4, a=0, v=1, kb=1, vec={x=0,y=0}, c=12, ativo=true, dano=0, target=nil, isbala=true, tmr=60 } b2=b:new{--ataque melee w=2, h=2, v=2, atravessa=true, tmr=20, trac=true, x0=0, y0=0, } b3=b:new{--ataque do boss1 w=10, h=10, v=0.6, tmr=20 } b4=b:new{--ataque do boss1 v=0.6, tmr=60*8, isbalist=true } function b:update() --print(self.target.x..'/'..self.target.y,self.x,self.y-4) if self.isbalist then self:steering() else self:move() end if solido(self.x+self.w/2,self.y+self.h/2) then self.ativo=false end if self.tmr>0 then self.tmr=self.tmr-1 else self.ativo=false end end function b:steering() if self.target and self.a==0 then self.a=angEntre(self,self.target) self.vec=ang2vec(self.a) end local vel={x=self.vec.x*self.v,y=self.vec.y*self.v} local dvel={x=self.vec.x*(self.v+self.v/4),y=self.vec.y*(self.v+self.v/4)} local ste = {x=dvel.x-vel.x,y=dvel.y-vel.y} if ste.x>0 then ste.x=math.min(ste.x,self.v) elseif ste.x<0 then ste.x=math.max(ste.x,-self.v) end if ste.y>0 then ste.y=math.min(ste.y,self.v) elseif ste.x<0 then ste.y=math.max(ste.y,-self.v) end if vel.x>0 then vel.x=math.min(vel.x+ste.x,self.v+self.v/4) elseif ste.x<0 then vel.x=math.max(vel.x+ste.x,self.v+self.v/4) end if vel.y>0 then vel.y=math.min(vel.x+ste.x,self.v+self.v/4) elseif vel.y<0 then vel.y=math.max(vel.x+ste.x,self.v+self.v/4) end self.x=self.x+vel.x self.y=self.y+vel.y end function b:move() if self.target and self.a==0 then self.a=angEntre(self,self.target) self.vec=ang2vec(self.a) end self.x=self.x+self.vec.x*self.v self.y=self.y+self.vec.y*self.v end function b:draw() local x,y =self.x,self.y if self.trac then if self.x0==0 then self.x0=self.x end if self.y0==0 then self.y0=self.y end line(self.x0,self.y0,self.x,self.y,self.c) end rect(x,y,self.w,self.h,self.c) pix(x,y,0) pix(x+self.w-1,y,0) pix(x,y+self.h-1,0) pix(x+self.w-1,y+self.h-1,0) end function tiro(x,y,obj,tbl,t,d,c) tbl[#tbl+1]={} tbl[#tbl]=obj:new{x=x,y=y,ativo=true,target=t,dano=d,c=c} table.insert(tbl,i) end as={} a=e:new{ x=0, y=0, cd=60, cdTmr=0, range=50, target=nil, blt=b, dmg=1 } a2=a:new{ cd=40, blt=b2, plrdir=true, melee=true } function a:update() if self.cdTmr > 0 then self.cdTmr=self.cdTmr-1 end self.x=plr.x+(plr.w/2) self.y=plr.y+(plr.h/2) for j=1,#inimigos do if inimigos[j].naTela and (distEntre(self.x,self.y,inimigos[j].x+inimigos[j].w/2,inimigos[j].y+inimigos[j].h/2)<= self.range)or(self.melee) then if self.cdTmr <= 0 then local trgt = {x=inimigos[j].x+inimigos[j].w/2 ,y=inimigos[j].y+inimigos[j].h/2} if self.plrdir==true then trgt.x=self.x+(plr.vec.x*16) trgt.y=self.y+(plr.vec.y*16) end local x,y = self.x-self.blt.w/2, self.y-self.blt.h/2 sfx(0) tiro(x,y,self.blt,bs,trgt,self.dmg) self.cdTmr=self.cd end end end if #inimigos== 0 then self.target=nil end end function a:draw() local c=13 if self.target ~= nil then c=5 end circb(self.x,self.y,self.range,c) end inimigos={} ini=e:new{--goblin x=100, y=50, xx=telaAtual.x, yy=telaAtual.y, naTela=true, w=8, h=7, a=0, vec={x=0,y=0}, v=0.4, img=304, f=0, ativo=true, vida=2, htmr=0, htmp=15, kb=0, kbx=0, kby=0, state='m', dano=1 } ini2=ini:new{--slime rndcont=0, wtmp=60, img=288, rnddir={x=0,y=0} } ini4=ini:new{--slime spawnado pelo big vida=1, v=0.5, img=288 } ini3=ini2:new{--big slime vida=5, w=13, h=12, img=290, spw=true, spwi=ini4 } ini5=ini:new{--morcego vida=2, v=0.5, img=353, state='p', isbat=true } ini6=ini:new{--planta vida=3, img=387, dist=90, tiroTmr=0, tiroTmp=60*3, atktmr=0, blt=b, c=2 } ini7=ini6:new{--kobold vida=3, img=403, dist=60, } boss1=ini7:new{--demonho vida=20, w=16, h=16, img=264, dist=60, isboss=true, blt=b3, c=12 } boss2=ini2:new{--slm vida=20, w=22, h=16, img=294, isboss=true, isslimeking=true, spwi=ini4, spwtmr=0 } function ini:update() self:taNaTela() if self.naTela then if self.state~='p'then self:seek(plr) elseif distEntre(self.x,self.y,plr.x+plr.w/2,plr.y+plr.h/2)<50 then self.state='m' end self:takehit() end end function ini2:update() self:taNaTela() if self.naTela then if self.rndcont > 0 then self.rndcont=self.rndcont-1 else local dires={{x=240,y=self.y},{x=0,y=self.y}, {x=self.x,y=130},{x=self.x,y=0}} local aux = rnd(1,4) self.rnddir.x=dires[aux].x self.rnddir.y=dires[aux].y self.ang=angEntre(self,self.rnddir) self.vec=ang2vec(self.ang) self.rndcont=30*rnd(1,2) end self:move() self:takehit() if self.isslimeking and self.spwi~=nil then if self.spwtmr>0 then self.spwtmr=self.spwtmr-1 else local n = flr(2,4) for i=0,n,1 do local x = rnd(-10,10) local y = rnd(-10,10) spwEnt(self.x+(self.w/2)+x,self.y+(self.h/2)+y,self.spwi,inimigos) end self.spwtmr=rnd(120,180) end end end end function ini6:update() self:taNaTela() if self.naTela then self:takehit() self:atira() end end function ini7:update() self:taNaTela() if self.naTela then if self.state~='p'then if self.state=='m' then self:seek(p) end self:atira() elseif distEntre(self.x,self.y,plr.x+plr.w/2,plr.y+plr.h/2)<50 then self.state='m' end self:takehit() end end function ini:takehit() if self.htmr>0 then self.htmr=self.htmr-1 -- if self.htmr>self.htmp/2 then local kbf = 1 if not self.isboss then if (self.vec.x~=0 and (self.vec.x < 0 and not solido(self.x-kbf,self.y) and not solido(self.x-kbf,self.y+self.h)) or (self.vec.x > 0 and not solido(self.x+kbf+self.w,self.y) and not solido(self.x+kbf+self.w,self.y+self.h)) ) then self.x=self.x+self.kby*self.kb end if (self.vec.y~=0 and (self.vec.y < 0 and not solido(self.x,self.y-kbf) and not solido(self.x+self.w,self.y-kbf)) or (self.vec.y > 0 and not solido(self.x,self.y+kbf+self.h) and not solido(self.x+self.w,self.y+kbf+self.h)) ) then self.y=self.y+self.kby*self.kb end end end for j=1,#bs do if col(self,bs[j]) and bs[j].dano and self.htmr<=0 then parts(self.x+self.w/2,self.y+self.h/2,20,12) self.kb=bs[j].kb self.kbx=bs[j].vec.x self.kby=bs[j].vec.y self.htmr = self.htmp self.vida=self.vida-bs[j].dano sfx(1) if self.htmr > self.htmp/2 then end if not bs[j].atravessa then bs[j].ativo=false end if self.vida <= 0 then if self.spw then for i=0,2,1 do local x = rnd(-10,10) local y = rnd(-10,10) spwEnt(self.x+(self.w/2)+x,self.y+(self.h/2)+y,self.spwi,inimigos) end end sfx(2) self.ativo = false iniNaTela = iniNaTela -1 end end end end function ini:taNaTela() if self.xx==telaAtual.x and self.yy==telaAtual.y then self.naTela=true else self.naTela=false end end function ini:atira() if self.atktmr>0 then self.atktmr=self.atktmr-1 else if self.state=='a' then self.state='m' end end if self.tiroTmr>0 then self.tiroTmr=self.tiroTmr-1 else self.state='a' local target = {x=plr.x+plr.w/2,y=plr.y+plr.h/2} local x,y = self.x+self.w/2-self.blt.w/2, self.y+self.h/2-self.blt.h/2 tiro(x,y,self.blt,inimigos,target,1,self.c) self.atktmr=30 self.tiroTmr=self.tiroTmp end end function ini:move() if self.vec.x<0 then self.f=1 else self.f=0 end if self.htmr <=0 then if (self.vec.x~=0 and (self.vec.x < 0 and not solido(self.x-self.v,self.y) and not solido(self.x-self.v,self.y+self.h)) or (self.vec.x > 0 and not solido(self.x+self.v+self.w,self.y) and not solido(self.x+self.v+self.w,self.y+self.h)) ) then self.x=self.x+self.vec.x*self.v end if (self.vec.y~=0 and (self.vec.y < 0 and not solido(self.x,self.y-self.v) and not solido(self.x+self.w,self.y-self.v)) or (self.vec.y > 0 and not solido(self.x,self.y+self.v+self.h) and not solido(self.x+self.w,self.y+self.v+self.h)) ) then self.y=self.y+self.vec.y*self.v end end end function ini:seek(target) self.a=angEntre(self,target) self.vec=ang2vec(self.a) -- --local vel={x=self.vec.x*self.v,y=self.vec.y*self.v} --local dvel={x=self.vec.x*(self.v),y=self.vec.y*(self.v)} --local ste = {x=dvel.x-vel.x,y=dvel.y-vel.y} -- --if ste.x>0 then -- ste.x=math.min(ste.x,self.v) --elseif ste.x<0 then -- ste.x=math.max(ste.x,-self.v) --end --if ste.y>0 then -- ste.y=math.min(ste.y,self.v) --elseif ste.x<0 then -- ste.y=math.max(ste.y,-self.v) --end -- --if vel.x>0 then -- vel.x=math.min(vel.x+ste.x,0.4) --elseif ste.x<0 then -- vel.x=math.max(vel.x+ste.x,-0.4) --end -- --if vel.y>0 then -- vel.y=math.min(vel.x+ste.x,0.4) --elseif vel.y<0 then -- vel.y=math.max(vel.x+ste.x,-0.4) --end -- self:move() -- local mag =sqrt(self.vec.x*self.vec.x + self.vec.y*self.vec.y) --print(self.v,self.x,self.y-8,4) --local vc={x=0,y=0} --vc = normal(self.vec.x,self.vec.y) end function ini:draw() if self.xx and self.yy and self.xx==telaAtual.x and self.yy==telaAtual.y then if self.htmr>0 then if t%(60*0.3)//(30*0.3)==0 then return end end if self.state == 'p' or self.state == 'a' then sprol(self.img-ceil(self.w/8),self.x,self.y,8,1,self.f,0,ceil(self.w/8),ceil(self.h/8)) else sprol(self.img+t%30//15*ceil(self.w/8),self.x,self.y,8,1,self.f,0,ceil(self.w/8),ceil(self.h/8)) end end end itVida=e:new{ nome='+vida', img=464, f=function() plr.vidaMax=plr.vidaMax+1 plr.vida=plr.vida+1 end } itDas=e:new{ nome='dash', img=465, f=function() plr.isdash=true end } itVel=e:new{ nome='+velocidade', img=466, f=function() plr.v=plr.v+plr.v/2 end } itRan=e:new{ nome='+alcance', img=467, f=function() arm.range=arm.range+arm.range/4 end } itAtk=e:new{ nome='+ataque', img=468, f=function() arm.dmg=arm.dmg+arm.dmg/2 end } itTvl=e:new{ nome='+vel.tiro', img=469, f=function() arm.cd=arm.cd-arm.cd/4 end } chave=e:new{ nome='chave', img=274, f=function() chaves=chaves+1 end } bau=e:new{ x=0, y=0, xx=telaAtual.x, yy=telaAtual.y, naTela=true, h=8, w=8, img=272, aberto=false, item=chave, itTmr=0 } bauVida=bau:new{ item=itVida } bauVel=bau:new{ item=itVel } bauRan=bau:new{ item=itRan } bauAtk=bau:new{ item=itAtk } bauTvl=bau:new{ item=itTvl } bauDas=bau:new{ item=itDas } function bau:update() self:taNaTela() if col(self,plr) and not self.aberto and self.naTela then self.aberto=true if self.item~=nil then self.item.f() end self.itTmr = 60 end end function bau:draw() if self.xx and self.yy and self.xx==telaAtual.x and self.yy==telaAtual.y then local img=self.img if self.aberto then img = self.img+1 end sprol(img,self.x,self.y,8,1,0,0,ceil(self.w/8),ceil(self.h/8)) if self.itTmr > 0 and self.item~=nil then self.itTmr=self.itTmr-1 sprol(self.item.img,self.x,self.y-9,8) end end end function bau:taNaTela() if self.xx==telaAtual.x and self.yy==telaAtual.y then self.naTela=true else self.naTela=false end end porta=bau:new{ img=0, w=16 } function porta:update() self:taNaTela() local prt = {x=self.x-4,y=self.y-4,w=self.w+8,h=self.h+8} if col(prt,plr) and self.aberto==false and self.naTela then if chaves>0 then chaves=chaves-1 self.aberto=true for i=0,29 do for j=0,16 do if(mget(i+30*telaAtual.x,j+17*telaAtual.y))==20 then mset(i+30*telaAtual.x,j+17*telaAtual.y,36) end if(mget(i+30*telaAtual.x,j+17*telaAtual.y))==21 then mset(i+30*telaAtual.x,j+17*telaAtual.y,37) end end end else if self.aberto then plr.msg='c' plr.msgTmr=60 else plr.msg='SEM CHAVE' plr.msgTmr=60 end end end end -----helpers------- ------------------ function ang2vec(a) local v={x,y} v.x=cos(a*tau) v.y=sin(a*tau) return v end function vec2ang(v) local a=atan2(v.y,v.x) if a<0 then a=a+tau end a=a/tau return a end function angEntre(a,b) local ae={x,y} ae.x=b.x-a.x ae.y=b.y-a.y return vec2ang(ae) end function distEntre(ax,ay,bx,by) return sqrt( ((bx-ax)^2)+((by-ay)^2) ) end function objsRemove(objs) local l=#objs for i=l,1,-1 do if not objs[i].ativo then table.remove(objs,i) end end end function col(o,ou) if ou~=nil then if o.x+o.w>=ou.x and o.x<=ou.x+ou.w and o.y+o.h>=ou.y and o.y<=ou.y+ou.h then return true else return false end else return false end end function normal(x,y) local mag =sqrt(x*x + y*y) local v={x=x/mag,y=y/mag} return v end function solido(x,y) return solidos[mget((x//flr(8)+30*telaAtual.x) ,(y//flr(8)+17*telaAtual.y))] end function sign(n) return n>1 and 1 or n<0 and -1 or 0 end function lerp(a,b,t) return (1-t)*a + t*b end function spwEnts() local preto=7 for i=0,30 do for j=0,17 do ---inimigos---- if(mget(i+31*telaAtual.x,j+17*telaAtual.y))==64 then spwEnt(i*8,j*8,ini,inimigos) mset(i+31*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==65 then spwEnt(i*8,j*8,ini2,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==66 then spwEnt(i*8,j*8,ini3,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==67 then spwEnt(i*8,j*8,ini5,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==68 then spwEnt(i*8,j*8,ini6,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==69 then spwEnt(i*8,j*8,ini7,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==70 then spwEnt(i*8,j*8,boss1,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==71 then spwEnt(i*8,j*8,boss2,inimigos) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) iniNaTela=iniNaTela+1 ---itens---- elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==20 then spwEnt(i*8,j*8,porta,itens) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==96 then spwEnt(i*8,j*8,bau,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==97 then spwEnt(i*8,j*8,bauVida,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==98 then spwEnt(i*8,j*8,bauDas,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==99 then spwEnt(i*8,j*8,bauVel,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==100 then spwEnt(i*8,j*8,bauRan,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==101 then spwEnt(i*8,j*8,bauAtk,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) elseif(mget(i+30*telaAtual.x,j+17*telaAtual.y))==102 then spwEnt(i*8,j*8,bauTvl,itens) mset(i+30*telaAtual.x,j+17*telaAtual.y,preto) end -- if(mget(i+30*telaAtual.x,j+17*telaAtual.y))==6 then -- mset(i+30*telaAtual.x,j+17*telaAtual.y,4) -- end end end end function spwPorta() for i=0,29 do for j=0,16 do if(mget(i+30*telaAtual.x,j+17*telaAtual.y))==5 and iniNaTela>0 then mset(i+30*telaAtual.x,j+17*telaAtual.y,4) end end end end function spwEnt(xx,yy,obj,tbl,i) local it=i or nil local ox,oy =(flr(xx/240)),(flr(yy/130)) tbl[#tbl+1]={} if it==nil then tbl[#tbl]=obj:new{x=xx,y=yy,xx=telaAtual.x,yy=telaAtual.y} else tbl[#tbl]=obj:new{x=xx,y=yy,xx=telaAtual.x,yy=telaAtual.y,item=it} end table.insert(tbl,i) end ps={} function parts(x,y,r,c) local j=rnd(5,7) for i=1,j do part(x,y,c,r) end end function part(x,y,c,r) table.insert(ps,{x=x,y=y,d=rnd()*tau,c=c ,ftl=r+rnd(r),s=0.02+0.03*rnd()}) end function drawParts() toDel={} for i,p in ipairs(ps) do circ(p.x,p.y,p.ftl/10,p.c) p.x=p.x+cos(p.d)*p.s*p.ftl p.y=p.y+sin(p.d)*p.s*p.ftl p.ftl=p.ftl-1 p.s=p.s*0.95 if p.ftl<=0 then table.insert(toDel,i) end end for i=#toDel,1,-1 do table.remove(ps,toDel[i]) end end function sprol(i,x,y,t,s,f,r,w,h,br) local b=br or 1 mx,my=mouse() for c=0,15 do poke4(palette_map*2+c,0) end for dx=-b,b do for dy=-b,b do spr(i,x+dx,y+dy,t,s,f,r,w,h) end end for c=0,15 do poke4(palette_map*2+c,c) end spr(i,x,y,t,s,f,r,w,h) end -------------------------- ---------------------------- function game() math.randomseed(t*t*t) map(telaAtual.x*30,telaAtual.y*17,30,17,0,0,-1,1) if iniNaTela == 0 then for i=0,29 do for j=0,16 do if(mget(i+30*telaAtual.x,j+17*telaAtual.y))==4 then mset(i+30*telaAtual.x,j+17*telaAtual.y,7) end end end end arm:update() arm:draw() plr:update() if plr.xx ~= telaAtual.x then telaAtual.x = plr.xx spwEnts() spwPorta() end if plr.yy ~= telaAtual.y then telaAtual.y = plr.yy spwEnts() spwPorta() end --limites(p) for j=1,#itens do itens[j]:update() itens[j]:draw() end plr:draw() objsRemove(inimigos) objsRemove(bs) for j=1,#bs do bs[j]:update() bs[j]:draw() end -- for j=1,#bis do -- bis[j]:update() -- bis[j]:draw() --end for j=1,#inimigos do inimigos[j]:update() inimigos[j]:draw() end drawParts() --updatejoystick(v) --drawjoystick(v) end function menu() local c=12 if t%(60*0.3)//(30*0.3)==0 then c=12 else c=2 end print('PRESS Z KEY \n\nOR A BUTTON\n\nTO START',75,60,c) if btnp(4) or mp then gamestate = 'j' init() end end function gameover() local c=12 if t%(60*0.3)//(30*0.3)==0 then c=12 else c=2 end print(' GAMEOVER\n\nPRESS Z KEY \n\nOR A BUTTON\n\nTOUCH TO START',75,60,c) if btnp(4) or mp then gamestate = 'm' end end init() function TIC() t=t+1 cls() if gamestate=='m' then menu() elseif gamestate=='j' then game() elseif gamestate=='g' then gameover() end end