0U(4S4mLu$mD8dqaHuʍ։֝iHVl31 ) then sfx(3,15,7,0,5) return false end this.numMovsLeft=this.numMovsLeft-1 this.setlAP(x,y) this.setAP(nx,ny) local sound_pitch=math.random(16,19) sfx(1,sound_pitch,7,0,5) return true end this.checkValid=function(dir) local x,y=this.aP() local lx,ly=this.lAP() if dir=='up' then return this.updateMovs(x,y,x,y-1,lx,ly) elseif dir=='down' then return this.updateMovs(x,y,x,y+1,lx,ly) elseif dir=='left' then return this.updateMovs(x,y,x-1,y,lx,ly) elseif dir=='right' then return this.updateMovs(x,y,x+1,y,lx,ly) end return false end this.move=function() if not(this.activeD == nil) then local dirMov=moveDice(this.activeD,u,d,l,r) if this.checkValid(dirMov) then bref.bcomp[this.activeD.x..this.activeD.y]=0 this.activeD.move(dirMov) bref.bcomp[this.activeD.x..this.activeD.y]=clr end end end return this end function newBoard(xmod,ymod) local this={} local k={} this.bcomp={} for x=0,B_W-1 do for y=0,B_H-1 do this.bcomp[x*D_S+xmod..y*D_S+ymod]=0 end end this.xmod=xmod this.ymod=ymod this.p1=newPlayer(2,xmod,ymod,0,1,2,3,this) this.p2=newPlayer(4,xmod,ymod+D_S*(B_H-2),0,1,2,3,this) this.currp={} this.currp=this.p1 this.currp.isActive=true this.changeP=function() local remID=this.currp.activeD.x..this.currp.activeD.y this.currp.isActive=false this.currp.activeD.selected=false this.currp.activeD=nil if this.p1==this.currp then this.currp=this.p2 else this.currp=this.p1 end this.currp.isActive=true this.currp.removeDie(remID) end this.draw=function() for x=0,B_W-1 do for y=0,B_H-1 do rectb(x*D_S+xmod,y*D_S+ymod,D_S,D_S,7) end end this.p1.drawDice() this.p2.drawDice() if not(this.currp.activeD == nil) then this.currp.activeD.nextMoves() end this.currp.move() local txt='Moves left: '..this.currp.numMovsLeft print(txt,W-70,H/5,this.currp.clr) --local lx,ly=this.currp.lAP() --local cx,cy=this.currp.aP() --print('cx '..cx..' cy '..cy,W-60,H/2-30,7) --print('nx '..NX..' ny '..NY,W-60,H/2-20,6) --print('lx '..lx..' ly '..ly,W-60,H/2-10,this.currp.clr) end return this end ------------------ GAME FUNC ------------------ board={} BTN_DLY=0 function nextButton() BTN_DLY=BTN_DLY+1 circ(W-30,H/2,10,5) local _,_,lb,_=mouse() if (mouseHits(W-30,H/2,100) or keyp(48)) and board.currp.activeD and board.currp.numMovsLeft==0 then circ(W-30,H/2,10,6) if (lb or keyp(48)) and BTN_DLY>30 then sfx(16,17,10,1,5) BTN_DLY=0 board.changeP() end end spr(36,W-33,H/2-3,0) print('press r to reset',W/2+30,H-10) end initGame=function() board=newBoard(0,0) STATE=play_game end play_game=function() cls() board.draw() nextButton() end main_menu=function() local scl=2 local x=W/3-5*scl-5 local y=H/2-4*scl+math.sin(FC/10)*2-10 local mx,my,lb,_=mouse() cls() local tc=15 if mouseHits(x+8*scl,y+8*scl,50*scl*scl) then pal(15,12) if lb then STATE=initGame end tc=12 else pal() end spr(34,x,y,-1,scl) spr(35,x+8*scl,y,-1,scl) spr(50,x,y+8*scl,-1,scl) spr(51,x+8*scl,y+8*scl,-1,scl) print("XADADO",x+40,y+11,tc,true,2) end STATE=main_menu function TIC() FC=FC+1 STATE() if keyp(18) then STATE=main_menu end end -- AUX functions -- swap c0 and c1 colors, call pal() to reset -- https://github.com/nesbox/TIC-80/issues/523 function pal(c0,c1) if(c0==nil and c1==nil)then for i=0,15 do poke4(0x3FF0*2+i,i)end else poke4(0x3FF0*2+c0,c1)end end function mouseHits(x,y,rad) local mx,my,_=mouse() return math.pow(mx-x,2)+math.pow(my-y,2)