0    Y  }W p8d%qy  e;]AsVl3<W
?  DDDDDDDD2TvͫgE#2Tv2TvͼwVD4""                                   D DL@D̈@DLDDDDDDDDDDDDDDDD       D   D   D  D  D  D    D DL@D̈@DLDDDDDDD DD DDD     D   D   D                       ̪̬ʌʌ̪       
  ʬ    ̈  ̈
 ʬ
    "  "" """ "" , ("("""    "   "  ,    ̈  ̈ ,   03 033 3330330<0Ì83Ì8333    3   3  <    ̈  ̈ <                  ̈  ̈      ̪̪̪       
    ̪  ̪  
 ʬ
                                                                 DDDD@DDD@DDD DDD  D            D  D   D                      DDDD@DDD@DDD DDD  D                D   D                      
 
                 
 
 
 
 
                 """"""""" "                   "" "" "                    333333333030                  33 33 30                                                          ʪ̪
 
                 
 
 
 
 
                                                                                                                                                                                       ̪̬ʌʌ̪       
  ʬ    ̈  ̈
 ʬ
    "  "" """ "" , ("("""    "   "  ,    ̈  ̈ ,   03 033 3330330<0Ì83Ì8333    3   3  <    ̈  ̈ <                  ̈  ̈      ̙̙̙       	    ̙  ̙  	 ɜ	                                                                                                                                                                                                 

                  
 
 

                    """"""""""                    "" "" "                     3333333333 0 0                33 33 3  0                                                          ə̙		                  	 	 		                                                      D DDD@J@LDDDDDDDDDDDDDO       J   L   DUUDffD DD                 UUUUffff               @      UUMDffMD MD DMD@D  DDD DDDDDDDDDDDDOD                                                                                                                                                                                                                                                                                                                                                                D@@DDD0DDD3D            OD D  D   4   0  03                                           DM  D   D   C  0            DODDDDDD@D0  03                                                                                                                                                                                                                                                                                                                                                                            		    	    		    	                        	    		    	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               @DDD@DDD@DDD@DDD@DDD@DDD@DDD@DDD@DD@DD@DD@DD@DD@DD@DD@DDD DD DD DD DD DD DD DD DDDD DDD DDD DDD DDD DDD DDD DDD        D  DD  DD DDD DDDDDDDD               @   D  @D @DDDDD  @D @DD@DD@DD@DD@DD@DD@DDDDDDDDDDDDDDDDDDD@DD@DDDDDDDDD  DDD DDDDDDDDDDDDDDDDDDDDDDC                                                                                                                                                                                                DD DDDDDDDDDDDDDDDD@DDD DDD  DD@DDDDDDDDDD4DDD4DDDCDD3D3 4  @DD@DD@DD  DD  @D   D   @    D DDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDD DDD DDC DD D4 DC  C       DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DD@DD@DD@DD@DD@DD@DD@DDDDDDDDDDD4DDD4DD4DD4DD4DDDDD4D3D D                                                                                                                                                                                                                                                        DD  DD  DD  DD  DD  DD  DD  DDDDDDDDDDDDDDDDDDDD DDD DDDDDDDDDD   DD DDD DDDDDDDDDDDDDD4        @D  @D  DD@DDD@DDDDDDD               @   D   D  @D @D  @D DDDDDDDDDDDDDDDDDDDDDDDDDD    D  DD DDD DD D                                                                                                                                                                                                                                                                                                           DD  DD  DD  DD  DD  DD  DD  DDDDDDDDDDDDCDDDC DDC DDC DDC DDD DDC 4C@D  D   D  @D  @D  DD @DDDD@DD DDD@DDDDDDDDDDDDDDDDDDDDDD @DD @D4@D4 DDC @D4 D4 DDD DDDDDDDDDDDDDDDDDDDDDDDD@DDD @DD       4  D3 DD3D4C DC  D@                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 pwwwwwwwwwwwwww """""!"!"""!"!""!"" DD @DDDD DD  DD @DD DD                                     
	03332#332#33#"333#33#"3233# ""\                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        pppppp  ppp   pp  ppp                                                                                                                                                                                                        pp                 pppppp  ppp  ppp pppp                                                                                                                                                                                                 pp   ppppp  pp           pppppppp paaaaapp`````                                                                                                                                                                                               p pp   ppppp pppp    ``  ppp``ppaap paaaaapp`````                                                                                                                                                                                     pp  pp pppp pp p ppppp ppppp a`````pp````paaaaaa`````p```                                                                                                                                                                                     ppp pp paaaaaaaaaaaaapaapaapaa`````````aaa```a`b`a```                                                                                                                                                                                    aaaa aaapaccccccaccccccacccaaaa```````bbaaab`a`````a`````                                                                                                                                                                                    aaaaccccca`````ba`rr```c```caaa```````bbaaab`ab`b`a`````                                                                                                                                                                                    accab``rra`rr``ba`rr`b`r`b``aaa`````````aaab`ab`b`a```                                                                                                                                                                                    ``ba```rra`rr``ra````b`r`b``aaa`````````aaa```a`````a```                                                                                                                                                                                    ``b ```` ````ra`````````   ````````   `` `` ````                                                                                                                                                                                    ``` ```` ````` `````````   ````````   `` `` ````                                                                                                                                                                                    qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq   qqqqqqqqqqqqqqq	E 
                       %I*"48;<13:=>ACG\^bei]^ac{|    
			 d                
                           a    a    a    a    a    a    a    a                                                                d 	     d d d d    d d d	 d	     d d d                   d d   d d   d d    d                                                                                                                                                       $ $ $ $ $ $ $ $ $ D D D D Df  @                                                0                                                 '0                                         "   "" """       "  ""  "" """ """                                                                                "        "      " "   "  "  "                                                                                   "     "   "      "   "   "  "  "                                                                                   """   " """"     "" "   "  " """"                                                                                 "     "  "         "   "  "" "                                                                                   "       "      "    "  " " "                                                                                   "   "" """       ""  ""  "" " """"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               DDDD DDDD @DDD           DDDDDDD                                                                                       DDDD DDDD @DDD@        @ DDDDDDDD                                                                                     DDDD DDDD @DDD@D      @D DDDDDDDDD                                                                                     DDDD DDDD @DDD@D     DD DDDDDDDDD                                                                                    DDDD DDDD @DDD@DD    @DD DDDD DDDD                                                                                    DDDD DDDD @DDD@DD   DDD DDDD DDDD                                                                                    DDDD DDDD @DDD@DDD DDDD DDDDDDDDD                                                                                    DDDD DDDD @DDD@DDDD@DDDD DDDDDDDD4                                                                               @DD  DDDD DDDD @DDD@DDDDDDDDD DDDDDDDDC                                                                                @DDDDDDDD DDDDDDDDD@DDDDDDDDD DDDDDD4C                                                                                @DDDDDDDC DDDDDDDD4@DDDDDDDDD DDDDCDD                                                                                  @DDDDDDD @DDDDDDD4 @DDDDDDDDD DDDDC                                                                                    @DDDDDD4  DDDDDDDC @DDDDDDDDD DDDDC                                                                                     DDDDD4C   @DDDDD4 @DDDDDDDDD DDDDC                                                                                     @DDD4C     DDDD4  @DDDDDDDDD DDDDC                                                                                      @DDC       DDD   @DDDDDDDDD DDDDD                                                                                          @DDDDDD             D                                                                                                 @DDDDDDDD   @      @DDDD                                                                                                @DDDDDDDD  D    @DDDDDD                                                                                               @DDDDDDDDD  D    DDDDDD                                                                                              @DDD@DDDD @DD   @DDDČHD                                                                                               @DDD@DDDD DDD  @DDDDD                                                                                               @DDDDDDDDD DDD  DDDDDD                                                                                                @DDDDDDDDC@DDDD  DDDDD                                                                                                 @DDDDDDD4@DDD DDDDD                                                                                                 @DDDDDD3D DD @D DDDDDD                                                                                                 @DDD4DD @DDDDC DDDDDDD                                                                                                @DDD4   @DDDDDC @DDDDDDD                                                                                               @DDD4   DDDDDD4 DDDDDD4C                                                                                              @DDD4   DDDDDDDC @DDDDD3                                                                                              @DDD4  @DDDDDDDC  DDDD4                                                                                               @DDDD  DDDDDDDDD  DDD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               	  	        	 	   	 	 		  		                                                	  	 	   	           	   	 			         	    	                                                 			  	 	  	 	         	    	     	 	       	    	                                                 		 	   	            	  	     	 	   	  	                                                 				  		   	        	  	 	    	 	     	 	    	                                                 	  		  	 	   	        	 	 	 		 	      	 	    	                                                  	 	 	     	   	    		 	      	                                                                                                                                                                                                          		    	 		                                                                                  	       		        	  	                                                                                    	       	          	 	                                                                                     	       	     	 	                                                                                   	        	 	      	 	   	                                                                                 	        			       	 	  	                                                                                          			 		 -- title:  Jump Pac
-- author: Lostcadesoft by BGelais
-- desc:   a pacman twist with trampoline
-- script: lua

score=0
lives=3
score=0
high=0
pac={x=130,y=16,xd=0,yd=2,flp=0}
tik=0
g=0.02
power=0
points={}
math.seed=time()
level=math.random(19)

function TIC()
	go(Title)
end

function Title()
	if score>pmem(0) then pmem(0,score) end
	wait(360,Attract)
	cls()
	high()
	text("@2023 LOSTCADESOFT",6,11,9)
	text("BY BGELAIS",12,12,9)
	spr(176,math.min(-100+tik,80),32,0,1,0,0,10,5)
	spr(1+2*math.floor(tik/10%2),-50+tik,58,0,1,0,0,2,2)
 Pstart()
end

function Attract()
	wait(360,Title)
	cls()
	map()
	high()
	text("PAC JUMP AND EAT!",7,3,12)
	text("...100",14,6,12)
	text("...200",14,8,12)
	text("...300",14,10,12)
	text("...400",14,12,12)
	f=32*math.floor(tik/10%2)
	spr(5+f,96,44,0,1,1,0,2,2)
	spr(7+f,96,60,0,1,1,0,2,2)
	spr(9+f,96,76,0,1,1,0,2,2)
	spr(11+f,96,92,0,1,1,0,2,2)
	spr(64,0,122,0,1,0,0,5,2)
	f=2*math.floor(tik/10%2)
	spr(1+f,16,64+math.sin(tik/16)*50,0,1,0,0,2,2)
	Pstart()
end

function Start()
	score=0 lives=3
	level=math.random(29)
	if tik==0 then sfx(0) end
	wait(120,game_init)
	cls()
	hud()
	text("PLAYER START",9,8,12)
end

function Game()
	tik=tik+1
	if power>0 then power=power-1 end
	if #pills==0 then go(Levelup) end
	cls()
 map(level,0,30,15)
 hud()
	ghosts_up()
	pills_up()
	player()
	points_up()
end

function Levelup()
 if tik==0 then music(1) end
	wait(300,game_init)
	level=math.random(19)
	cls()
	hud()
	text("PAC EAT MORE!",8,8,12)
	spr(1+2*math.floor(tik/10%2),-16+tik,92,0,1,0,0,2,2)
	spr(5+32*math.floor(tik/10%2),0+tik,92,0,1,0,0,8,2)
end

function dead()
	tik=tik+1
	if tik==1 then 
	lives=lives-1 
	music(-1) sfx(2) end
	
	if lives>0 then wait(300,game_init) end
 
 if lives<=0 then wait(300,Over) end
	pac.y=pac.y+1
	cls()
	hud()
	if lives>0 then text("GET READY!",10,9,8+tik/8%7) end
	spr(3,pac.x-8,pac.y-8,0,1,pac.flp,(tik/10)%4,2,2)

end

function Over()
	wait(240,Title)
	cls()
	hud()
	if tik==90 and score>pmem(0) then sfx(0) end
	if tik>90 and score>pmem(0) then 
 	text("NEW HIGH SCORE!",8,12,8+tik/10%8)
	end
	text("GAME OVER",11,8,2)
end

function game_init()
	pills={}
	pac={x=130,y=16,xd=0,yd=2,flp=0}
	power=0
	for i=1,30 do
		pill={}
		pill.x=i*8
		pill.y=math.random(3,14)*8
		pill.s=33
		if i%8==0 then pill.s=35 end
		table.insert(pills,pill)		
	end
	ghosts_init()
	music(0)
	go(Game)
end

function pills_up()
		for id,o in pairs(pills) do
		o.x=o.x-1
		if o.x<-16 then o.x=260 end
		if col(o,pac) and o.s==33 then
			score=score+10
			sfx(0)
			table.remove(pills,id) end
		if col(o,pac) and o.s==35 and power==0 then
			score=score+50
			power=300
	  sfx(1)
			table.remove(pills,id)
		end
		spr(o.s+tik/8%2,o.x-4,o.y-4,0,1,0,0,1,1)
	end
end

function ghosts_up()
	for id,o in pairs(ghosts) do
		o.x=o.x+o.xd 
		o.y=o.y+o.yd
		o.t=o.t-1
		
		if col(o,pac) and power>0 then
			point(o.x-5,o.y-5,id*100)
			sfx(3)
			table.remove(ghosts,id)
		elseif col(o,pac) and power<=0 then
			go(dead)
		end
		
		if o.t<=0 then 
			o.t=math.random(120)
			o.xd=math.random(-1,1)
			o.yd=math.random(-1,1)
		end
		if o.x<-16 then o.x=276 end
		if o.x>276 then o.x=-16 end
		o.y=math.min(math.max(o.y,22),80)
		if o.xd>=0 then flp=0 else flp=1 end
		 o.f=math.floor(tik/10)%2*32
		if power>0 then
			spr(13+o.f,o.x-5,o.y-6,0,1,flp,0,2,2)
		else
			spr(o.s+o.f,o.x-5,o.y-6,0,1,flp,0,2,2)		
	 end 
	end
end

function ghosts_init()
	ghosts={}
	power=0
	for i=5,11,2 do
		ghost={
			s=i,
			y=math.random(3,14)*8,
			x=32*8,
			xd=math.random(-1,1),
			yd=math.random(-1,1),
			t=math.random(120),						
		}
		table.insert(ghosts,ghost)
	end
end

function player()
	if btn(2) then 
		pac.xd=pac.xd-1
		pac.flp=1
	elseif btn(3) then
		pac.xd=pac.xd+1
		pac.flp=0
	end
 pac.yd=pac.yd+g
	pac.x=pac.x+pac.xd
	pac.y=pac.y+pac.yd	
	pac.xd=pac.xd-pac.xd/4
	pac.x=math.min(math.max(pac.x,4),236)
	
	if pac.y>121 then pac.yd=-2 end
	
	spr(1+2*math.floor(tik/8%2),pac.x-8,pac.y-8,0,1,pac.flp,0,2,2)
	spr(64,pac.x-20,120,0,1,pac.x/8%2,0,5,2)
end

function Pstart()
	if time()%1000<=500 then
	text("a TO START",10,16,12)
	end
	if btnp(4) then go(Start) end
end

function text(str,x,y,c)
	poke4 (0x3ff0*2+12,c)
	poke4 (0x3ff0*2+13,c+1)
	font(str,x*8,(y*8),-1,8,8,true,1)
	poke4 (0x3ff0*2+12,12)
	poke4 (0x3ff0*2+13,13)
end

function hud()
	text("SCORE",0,0,2)
	text(string.sub("000000"..tonumber(score),-6),0,1,12)
	high()
	if lives>0 then
		text(string.sub("ccc",-lives),24,0,0)
	end
end

function high()
		text("HIGH SCORE",10,0,2)
	text(string.sub("000000"..tonumber(pmem(0)),-6),12,1,12)

end

function point(_x,_y,_p)
	table.insert(points,{
	x=_x,y=_y,p=_p,t=120})
end

function points_up()
	for id,o in pairs(points) do
		o.y=o.y-1
		if o.y<=16 then 
			score=score+o.p
			if #ghosts==0 then ghosts_init() end
			table.remove(points,id)
		end
		print(o.p,o.x,o.y,12,false,1,true)
	end
end

function go(f)
	tik=0
	TIC=f
end

function wait(s,f)
	tik=tik+1
	if tik>s then tik=0 end
	if tik==s then tik=0 TIC=f end
end

function col(a,b)
	if math.abs(a.x-b.x)<8
	and math.abs(a.y-b.y)<8
	then return true end
end
