0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ös²÷ôôô”°ÂVl†3w or en_x-camx+32<0 then wltimer=wltimer+1 else wltimer=0 end if wltimer>50 and en_x-camx>w then wltimer=0 fightstate=3 end if wltimer>50 and en_x-camx+40<0 then wltimer=0 fightstate=4 end end --lose if fightstate==3 then camx=fightx-500 opponents[fightopp].x=opponents[fightopp].x+300 fightstate=5 end --win if fightstate==4 then camx=fightx+300 opponents[fightopp].x=opponents[fightopp].x-500 fightstate=5 end if fightstate==5 then fightstate=0 state="race" end end function drawbg() cls(11) for i,val in ipairs(grass) do spr(199+val.sp,0-camx%256+(i-1)*32,h-32,0,1,val.flip,0,4,4) spr(199+val.sp,0-camx%256+(i+7)*32,h-32,0,1,val.flip,0,4,4) end if #flowers<8 then table.insert(flowers,{x=camx+math.random(w,w+200),flip=math.random(0,1),t=flowertypes[math.random(1,#flowertypes)]}) end for i,val in ipairs(flowers) do spr(val.t.sp,val.x-math.floor(camx),h-val.t.h*8,0,1,val.flip,0,val.t.w,val.t.h) if val.x-camx<0-val.t.w*8 then table.remove(flowers,i) end end end function drawui() rect(0,h-6-4,51,10,8) rect(1,h-6-3,speed*50/2.7,8,9) print("speed",9,h-6-2,12) end function drawfightscreen() local ht=40 local sprite=opponents[fightopp].sp cls(0) rect(0,h/2-ht/2,w,ht,14) rect(0+2,h/2-ht/2+2,w-4,ht-4,13) spr(5,w/2-100,h/2,0,1,0,0,4,2) spr(1,w/2-100,h/2-8,0,1,0,0,4,2) spr(sprite+4,w/2+100-4*8,h/2,0,1,1,0,4,2) spr(sprite,w/2+100-4*8,h/2-8,0,1,1,0,4,2) print("VS",w/2-4*6,h/2-4*2,2,false,4) end function drawplayer() if introstate<2 then drawthings(5,x,y+7,4,2,0,0,0,0,0,0,angle) drawthings(1,x,y,4,2,0,10+math.sin(introflap/50)*10,0,10+math.sin(introflap/50)*20,0,math.sin(introflap/50)*3,angle) return end drawthings(5,x,y+7,4,2,0,0,0,0,0,0,angle) drawthings(1,x,y,4,2,0,10+math.sin(flapplayer/50)*10,0,10+math.sin(flapplayer/50)*20,0,math.sin(flapplayer/50)*3,angle) end function drawenemy() drawthings(en_sprite+4,en_x-camx,en_y+7,4,2,0,0,0,0,0,0,en_angle) drawthings(en_sprite,en_x-camx,en_y,4,2,0,10+math.sin(en_flap/50)*10,0,10+math.sin(en_flap/50)*20,0,math.sin(en_flap/50)*3,en_angle) end function drawraindrops() local sprite=128 local wt=2 local ht=4 for i,val in ipairs(drops) do spr(sprite,val.x,val.y,0,1,0,0,wt,ht) val.y=val.y+2 if val.y>h then table.remove(drops,i) end end end function drawwarnings() for i,val in ipairs(warnings) do spr(86,val.x,val.y,0,1,0,val.rot,2,2) val.t=val.t-1 if val.t<0 then table.remove(warnings,i) end end end function add_drop(p,pi) table.insert(drops,{x=patterns[p][pi],y=-20-4*8-32-pi*32}) table.insert(drops,{x=patterns[p][pi],y=-20-4*8-1*32-pi*32}) table.insert(drops,{x=patterns[p][pi],y=-20-4*8-2*32-pi*32}) table.insert(drops,{x=patterns[p][pi],y=-20-4*8-3*32-pi*32}) table.insert(warnings,{x=patterns[p][pi],y=10,t=30,rot=0}) end function rain() if rainstate==0 then pattype=math.random(1,#patterns) rainstate=1 end if rainstate==1 then for i=#patterns[pattype],0,-1 do add_drop(pattype,i) end wait=400 rainstate=2 end if rainstate==2 then if wait<0 then rainstate=0 else wait=wait-1 end end end function add_traffic() local ry=math.random(0,h-30) table.insert(traffic,{x=w+50,y=ry,spd=math.random()*2,sp=traffictypes[math.random(1,#traffictypes)]}) table.insert(warnings,{x=w-20,y=ry,t=30,rot=1}) end function drawtraffic() for i,val in ipairs(traffic) do local flp=flap+val.spd%50 drawthings2(val.sp+2,val.x,val.y+7,2,2,0,0,0,0,0,0,0) drawthings2(val.sp,val.x,val.y,2,2,0,10+math.sin(flp/50)*10,0,10+math.sin(flp/50)*20,0,math.sin(flp/50)*3,0) end end function movetraffic() for i,val in ipairs(traffic) do val.x=val.x-val.spd-speed if collision(x+10,y+12,20,10,val.x+10,val.y+12,20,10) then acc.x=-0.1 slow=10 sfx(0,12*3+5,20,3) end end end function maketraffic(delay) if trafficstate==0 then add_traffic() trafficstate=1 end if trafficstate==1 then wait=delay trafficstate=2 end if trafficstate==2 then if wait<0 then trafficstate=0 else wait=wait-1 end end end function moveplayer() speed=(x/(w/2))+1 if slow>0 then speed=speed/2 slow=slow-1 end local spdx=0.09*(2.7-speed) local spdy=0.05+0.05*(2.7/speed) --butterfly ctrl if not(state=="intro") then if btn(0) then acc.y=acc.y-spdy end if btn(1) then acc.y=acc.y+spdy end if btn(2) then acc.x=acc.x-spdx-0.05 end if btn(3) then acc.x=acc.x+spdx end end --limits if x<0 then x=0 end if x>w-30 then x=w-30 end if y< -10 then y= -10 end if y>h-30 then y=h-30 end --speed up if any presses if acc.x+acc.y==0 then motion=0 else motion=1 end --body collision if state=="fight" and collision(x+10,y+10,20,16,en_x-camx+10,en_y+10,20,16) then acc.x=-(en_x-camx-x)*0.05 acc.y=-(en_y-y)*0.05 sfx(0,12*3+5,20,3) end --head collision if state=="fight" and collision(x+26,y+12,5,8,en_x-camx,en_y+12,8,8) then slow=100 sfx(8,12+5,20,3) end for i,val in ipairs(drops) do if val.x==nil then goto skip end if collision(x+10,y+10,20,16,val.x,val.y,16,16) then slow=100 sfx(8,12+3,20,3) end ::skip:: end if slow>0 then acc.x=acc.x-0.1 end angle=vel.x/5+(speed-2)/4+math.sin(t/50)*0.02 vel={x=vel.x+acc.x,y=vel.y+acc.y} x=x+vel.x;y=y+vel.y acc={x=0,y=0} vel={x=vel.x*0.9,y=vel.y*0.9} end function ai() if aistate==-1 then en_x,en_y=w+camx-50 ,h/2 x ,y =0+50 ,h/2 aistate=0 end if en_x-camx-x>0 then leader=1 else leader=0 end if aistate==0 then fstates={1,2,4,1,2,4} bstates={3,3} if leader==1 then aistate=fstates[math.random(1,#fstates)] else aistate=bstates[math.random(1,#bstates)] end wait=200 end aipressup=0 aipressdown=0 aipressleft=0 aipressright=0 if aistate==1 then --follow lead=leader --up if y-en_y<-10 then aipressup=1 end --down if y-en_y>10 then aipressdown=1 end --left if en_x-camx-x>80 then aipressleft=1 end --right if en_x-camx-x<50 then aipressright=1 end if wait<0 or not(lead==leader) then aistate=0 else wait=wait-1 end end if aistate==2 then --attack lead=leader --up if y-en_y<-5 then aipressup=1 end --down if y-en_y>5 then aipressdown=1 end --left if y-en_y<5 and y-en_y>-5 then aipressleft=1 end --right if en_x-camx-x<5 then aipressright=1 end if wait<0 or not(lead==leader) then aistate=0 else wait=wait-1 end end if aistate==3 then --avoid lead=leader --up if y-en_y>=0 and y-en_y<20 then aipressup=1 end --down if y-en_y<0 and y-en_y>-20 then aipressdown=1 end --lightright if y-en_y<20 and y-en_y>-20 then aipressright=0.9 end --right if y-en_y>20 or y-en_y<-20 then aipressright=1.2 end if wait<0 or not(lead==leader) then aistate=0 else wait=wait-1 end end if aistate==4 then lead=leader --up if y-en_y>-10 then aipressup=1 end --down if y-en_y<10 then aipressdown=1 end --left if y-en_y<3 and y-en_y>-3 and en_x-camx-x>-10 then aipressleft=1 end --right if en_x-camx-x<50 then aipressright=1 end if wait<0 or not(lead==leader) then aistate=0 else wait=wait-1 end end --print(aistate,0,0) --print(leader,30,0) --print(en_x-camx-x,0,12) --print(y-en_y,0,24) end function dist(i,j) if i>j then return math.abs(i-j) else return math.abs(j-i) end end function moveenemy() --print(en_x,100,100) --print(camx,100,120) en_speed=0.25 if en_slow>0 then en_speed=en_speed/2 en_slow=en_slow-1 end local spdx=en_speed local spdy=0.1 --butterfly ctrl --aipressright=1 --aipressleft=0 if aipressup==1 then en_acc.y=en_acc.y-spdy end if aipressdown==1 then en_acc.y=en_acc.y+spdy end if aipressleft==1 then en_acc.x=en_acc.x-spdx end if aipressright>0 then en_acc.x=en_acc.x+spdx*aipressright else en_acc.x=en_acc.x+spdx/2 end --limits --if en_x<0 then en_x=0 end --if en_x>w-30 then en_x=w-30 end if en_y< -10 then en_y= -10 end if en_y>h-35 then en_y=h-35 end --speed up if any presses if en_acc.x+en_acc.y==0 then en_motion=0 else en_motion=1 end --body collision if collision(x+10,y+10,20,16,en_x-camx+10,en_y+10,20,16) then en_acc.x=(en_x-camx-x)*0.07 en_acc.y=(en_y-y)*0.07 sfx(0,12*3+5,20,3) end --print(en_x-camx-x,0,120,6) --head collision if collision(x,y+12,8,8,en_x-camx+26,en_y+12,5,8) then en_slow=100 sfx(1,12*3+5,20,3) end if slow>0 then en_acc.x=en_acc.x+0.1 end if en_slow>0 then en_acc.x=en_acc.x-0.15 end en_angle=en_vel.x/5+(en_speed-2)/4+math.sin(t/50)*0.02 en_vel={x=en_vel.x+en_acc.x,y=en_vel.y+en_acc.y} en_x=en_x+en_vel.x;en_y=en_y+en_vel.y en_acc={x=0,y=0} en_vel={x=en_vel.x*0.9,y=en_vel.y*0.9} end function moveopponents() local introboost=1 if introstate==0 then return end if introstate==1 then introboost=6 end for i,val in ipairs(opponents) do val.x=val.x+val.vel.x val.vel={x=val.vel.x+val.spd*introboost,y=val.vel.y+val.spd} val.vel={x=val.vel.x*0.9,y=val.vel.y*0.9} end end function drawbody() spr(5,x,y,0,1,0,0,4,3) end function drawthings(sprite,px,py,wt,ht,x_shift1,y_shift1,x_shift2,y_shift2,x_shift3,y_shift3,ang) local width=wt*8 local height=ht*8 local p1={x=x_shift1, y=y_shift1 } local p2={x=x_shift2+width,y=y_shift2 } local p3={x=x_shift3, y=y_shift3+height} local p4={x=width, y=height } if not(ang==0) then p1=rotate(p1,ang) p2=rotate(p2,ang) p3=rotate(p3,ang) p4=rotate(p4,ang) end p1=trans(p1,{x=px,y=py}) p2=trans(p2,{x=px,y=py}) p3=trans(p3,{x=px,y=py}) p4=trans(p4,{x=px,y=py}) local u1={x=(sprite%16)*8,y=math.floor(sprite/16)*8} local u2={x=u1.x+width,y=u1.y} local u3={x=u1.x,y=u1.y+height} local u4={x=u1.x+width,y=u1.y+height} --line(p1.x,p1.y,p2.x,p2.y,0) --line(p2.x,p2.y,p4.x,p4.y,0) --line(p4.x,p4.y,p3.x,p3.y,0) --line(p3.x,p3.y,p1.x,p1.y,0) -- line(u1.x,u1.y,u2.x,u2.y,0) -- line(u2.x,u2.y,u4.x,u4.y,0) -- line(u4.x,u4.y,u3.x,u3.y,0) -- line(u3.x,u3.y,u1.x,u1.y,0) textri(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y, u1.x,u1.y,u2.x,u2.y,u3.x,u3.y,false,0) textri(p2.x,p2.y,p4.x,p4.y,p3.x,p3.y, u2.x,u2.y,u4.x,u4.y,u3.x,u3.y,false,0) end function drawthings2(sprite,px,py,wt,ht,x_shift1,y_shift1,x_shift2,y_shift2,x_shift3,y_shift3,ang) local width=wt*8 local height=ht*8 local p1={x=x_shift1, y=y_shift1 } local p2={x=x_shift2+width,y=y_shift2 } local p3={x=x_shift3, y=y_shift3+height} local p4={x=width, y=height } p2,p1=p1,p2 p3,p4=p4,p3 if not(ang==0) then p1=rotate(p1,angle) p2=rotate(p2,angle) p3=rotate(p3,angle) p4=rotate(p4,angle) end p1=trans(p1,{x=px,y=py}) p2=trans(p2,{x=px,y=py}) p3=trans(p3,{x=px,y=py}) p4=trans(p4,{x=px,y=py}) local u1={x=(sprite%16)*8,y=math.floor(sprite/16)*8} local u2={x=u1.x+width,y=u1.y} local u3={x=u1.x,y=u1.y+height} local u4={x=u1.x+width,y=u1.y+height} textri(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y, u1.x,u1.y,u2.x,u2.y,u3.x,u3.y,false,0) textri(p2.x,p2.y,p4.x,p4.y,p3.x,p3.y, u2.x,u2.y,u4.x,u4.y,u3.x,u3.y,false,0) end function trans(pos,origin) pos.x=pos.x+origin.x pos.y=pos.y+origin.y return pos end function rotate(pos,ang) local rx,ry=pos.x,pos.y local cos=math.cos(ang) local sin=math.sin(ang) local x=rx*cos-ry*sin local y=ry*cos+rx*sin return {x=x,y=y} end function collision(x1,y1,w1,h1,x2,y2,w2,h2) if x1x2 and y1y2 then return true end return false end function changestate() if state=="fight" then return end fightwait=fightwait-1 if not(state=="intro") and fightwait<0 then for i,val in ipairs(opponents) do if dist(val.x,camx)<2 then fightopp=i state="fight" en_slow=10 slow=10 end end end if camx>rainsection and camxtrafficsection and camxfinish then for i,val in ipairs(opponents) do if val.x-camx>x then place=place+1 end end state="finish" end end function drawintro() map(0+camx,0) for i,val in ipairs(grass) do spr(199+val.sp,0-camx%256+(i-1)*32,h-32,0,1,val.flip,0,4,4) spr(199+val.sp,0-camx%256+(i+7)*32,h-32,0,1,val.flip,0,4,4) end for i,val in ipairs(opponents) do drawthings(val.sp+4,val.x-camx,val.y+7,4,2,0,0,0,0,0,0,en_angle) drawthings(val.sp,val.x-camx,val.y,4,2,0,10+math.sin(introflap/50)*10,0,10+math.sin(introflap/50)*20,0,math.sin(introflap/50)*3,en_angle) end drawthings(131,-10-camx*2,h-32,4,4,0,0,x-(10)-camx,y-(h-50)+camx,0,0,0) end function intro() if introstate==0 then speed=0 x=0 y=h-48 if introtimer<0 then introstate=1 else introtimer=introtimer-1 end end if introstate==1 then speed=0.00001 for i,val in ipairs(opponents) do val.y=val.y-val.spd end --introstate=2 end if introstate==2 then state="race" end end function drawqte() print("Press UP/RIGHT fast!!!",58,h/2-20) circ( w/2,h/2,10,15) circb(w/2,h/2,11,14) circ( w/2,h/2,qte_rad+1,5) circb(w/2,h/2,qte_rad,6) end function qte() if btnp(0,0,50) then qte_rad=qte_rad+0.5 acc.y=acc.y-0.1 end if btnp(1,0,50) then qte_rad=qte_rad+0.5 acc.y=acc.y+0.01 end if btnp(2,0,50) then qte_rad=qte_rad+0.5 acc.x=acc.x-0.01 end if btnp(3,0,50) then qte_rad=qte_rad+0.5 acc.x=acc.x+0.1 end qte_rad=qte_rad*0.995 if qte_rad>10 then introstate=2 end end function dofinish() map(0,17) rect(0,4,w,18,12) print("You finished "..place.."!!!!",w/2-9*6*2,8,3,true,2) local index=1 for i=1,4 do local px=220-i*48 local py=20+i*5-math.sin(t/50)*5 if place==i then x=px y=py angle=-0.3 drawplayer() else local sprite=opponents[index].sp drawthings(sprite+4,px,py+7,4,2,0,0,0,0,0,0,-0.3) drawthings(sprite,px,py,4,2,0,10+math.sin(introflap/50)*10,0,10+math.sin(introflap/50)*20,0,math.sin(introflap/50)*3,-0.3) index=index+1 end end end