0mڑY޶$H$3#2mʶ$$mm @2TvͫgE#2Tv2TvX4Ce ޼y5#2C mmmnfnnfhhDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDwwpwwwwwwwwwwwwwwwwpwwpwwwwwwwwwwwwwwwww0030333<3<3333`ff `mnfnf@@DHDHDHDHDDDDDDDDDDDDDDDDDDDDppp@DD@DDDD@@@@pppDD@LLLLLLLL@DD wwwwww ppwwwwww ̜  ̙񙙙̙̑񙙙̑ ̜ ̙ ̙ 񙙙̑ ɜ ̜̙̙̙̙̜ ̜̜̜̜̙̙̙̙̜̜ ̙̙̙̙̜̜ ̙̙̜̜̙̜̜̜̑  ̙̟ ̜̙̐ ̙̐  ̙wpw ww U PXXXU P p ( (  (" (*  (  (( **("("("("*"("*"                   PUPU_U_UPUUU  Uxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwfff  if ɜ ̜wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwfff`fffffffffffffffffffffffnfffffnfnffffffffffffffff wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww<<~ff`v08n`f f<~<8~<~<`6~>06`f~ff 0<< <<ff v~ffff<>~~>fvff>~<f<~ff`f~`>fffffff<<><>ff`vff|f<~fffffffff<|<lff~6f~>cswk>kk>sw>cp<0<<<>ffAffAffIff6fffpwwwwppwwwppwwwpwppppppppwppppppwwwwppppn0`n0 `f0 ff0ff0ff0f<0~<6`f6`f6ff 6ff ~ff 0ff 0<< f|f`ffffffff<<0wpwpppppppppwpwwwxxxxwwxxxw~@A !01 ! !@A0101@A@A !01-@A=,,,,<<<<./././././ !01  "),./ /P/p////////////////////// 1m111136;>?????????????????????{ % )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DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD̄DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDHDHDHDHDHDHDHDHDHDHDHDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDHDHDHDHDHDHDHDHDHDHDHDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD)-- title: sheep attack -- author: bisko3000 -- desc: demo -- version: 0.2.8.2 -- script: lua -- input: gamepad -- some code yoinked from trelemar's basic platformer engine require "math" require "string" function sign(n) if n==0 then return 0 else return n/math.abs(n) end end function round(n) return math.floor(n+0.5) end function xor(b1,b2) return (b1 or b2) and not (b1 and b2) end function set1bpp() poke4(0x3ffc*2,8) end function set2bpp() poke4(0x3ffc*2,4) end function set4bpp() poke4(0x3ffc*2,2) end function swapColor(index,color) poke4(0x3ff0*2+index,color) end function editColor(index,red,green,blue) poke(0x3fc0+index*3,red) poke(0x3fc1+index*3,green) poke(0x3fc2+index*3,blue) end function resetPalette() editColor(0,0x00,0x00,0x00) editColor(1,0x00,0x6d,0xda) editColor(2,0x91,0x59,0xde) editColor(3,0xb6,0x24,0x00) editColor(4,0x91,0x48,0x00) editColor(5,0xda,0xda,0x00) editColor(6,0x24,0x91,0x00) editColor(7,0xff,0xff,0xff) editColor(8,0x33,0x23,0x32) editColor(9,0x6d,0xb6,0xff) editColor(10,0xca,0xb6,0xee) editColor(11,0xf2,0x24,0x24) editColor(12,0xff,0x91,0x00) editColor(13,0xff,0xff,0x6d) editColor(14,0x6d,0xda,0x00) editColor(15,0xb6,0xb6,0xb6) for i=0,15 do swapColor(i,i) end end function remap(tile,x,y) if fget(tile,7) then return tile+math.floor((t/30)%2)*2,0,0 else return tile,0,0 end end function coll(e1,e2) e2=e2 or p if e1==water then return e2.y+e2.h>water.y else return ( (e1.x<(e2.x+e2.w)) and ((e1.x+e1.w)>e2.x) and (e1.y<(e2.y+e2.h)) and ((e1.y+e1.h)>e2.y) ) end end function mapFlag(x,y,f) return fget(mget(x//8,y//8),f) end function touchingGround(flag,e) flag=flag or 1 e=e or p for i=0,e.w-1,(e.w-1)/((e.w//8)) do if debug then pix((e.x+math.ceil(i))-cam.x,(e.y+e.h)-cam.y,1) end if mapFlag(e.x+math.ceil(i)+e.xVel,e.y+e.h+e.yVel,flag) then return true end end return false end function touchingWall(flag,e) flag=flag or 0 e=e or p for i=0,e.w-1,e.w-1 do for j=0,e.h-e.yVel-1,(e.h-e.yVel-1)/((e.h//8)) do if debug then pix((e.x+i)-cam.x,(e.y+math.ceil(j))-cam.y,2) end if e.xVel>0 then -- if moving right, use ceiling if mapFlag(e.x+i+math.ceil(e.xVel),e.y+math.floor(j)+e.yVel,flag) then return true end elseif e.xVel<0 then -- if moving left, use floor if mapFlag(e.x+i+math.floor(e.xVel),e.y+math.floor(j)+e.yVel,flag) then return true end end end end return false end function touchingCeiling(flag,e) flag=flag or 0 e=e or p for i=0,e.w,(e.w-1)/((e.w//8)) do if debug then pix((e.x+math.ceil(i))-cam.x,e.y-cam.y,3) end if mapFlag(e.x+math.ceil(i)+e.xVel,e.y+e.yVel,flag) then return true end end return false end function touching(flag) return touchingGround(flag) or touchingWall(flag) or touchingCeiling(flag) end function distance(e1,e2) e2=e2 or p dist=math.sqrt(((e1.x+e1.w/2)-(e2.x+e2.w/2))^2+(((e1.y+e1.h/2)-(e2.y+e2.h/2))^2)) if debug then line(e1.x+e1.w/2-cam.x,e1.y+e1.h/2-cam.y,e2.x+e2.w/2-cam.x,e2.y+e2.h/2-cam.y,13) print(math.floor(dist),e1.x-cam.x,e1.y-8-cam.y,5,false,1,true) end return dist end function wrapCoords(e) if p.x<0 then p.x=p.x+1920 cam.x=cam.x+1920 jay.x=jay.x+1920 elseif p.x>1920 then p.x=p.x-1920 cam.x=cam.x-1920 jay.x=jay.x-1920 end if p.y<0 then p.y=p.y+1088 cam.y=cam.y+1088 jay.y=jay.y+1088 elseif p.y>1088 then p.y=p.y-1088 cam.y=cam.y-1088 jay.y=jay.y-1088 end end function fontPrint(str,x,y,color,big) big=big or false set1bpp() if big then for i=1,string.len(str) do local j=string.byte(str,i) swapColor(1,0) spr(1920+(j-48),x+(i-1)*8+1,y+1,0,1,0,0,1,2) swapColor(1,color) spr(1920+(j-48),x+(i-1)*8,y,0,1,0,0,1,2) end else swapColor(1,0) font(str,x+1,y+1,0,8,8,true,1,true) swapColor(1,color) font(str,x,y,0,8,8,true,1,true) end swapColor(1,1) set4bpp() -- 4bpp mode end function drawSprite(e) if coll(e,cam) then if not debug then if e==p and p.char~=0 then e.frame=e.frame+p.char*64 end spr(e.frame,math.floor(e.x)-math.floor(cam.x),math.floor(e.y)-math.floor(cam.y),0,1,e.flip,0,e.w//8,e.h//8) --if in water, draw goggles if e==p and coll(water) then spr(314+p.char*64,math.floor(e.x)-math.floor(cam.x),math.floor(e.y)-math.floor(cam.y)+5-p.char,0,1,e.flip,0,2,1) end elseif not hitpoint then rectb(e.x-cam.x,e.y-cam.y,e.w,e.h,7) end end end function drawHUD() if debug then print("PX "..p.x.."\nPY "..p.y.."\nPXV "..p.xVel.."\nPYV "..p.yVel.."\nCX "..cam.x.."\nCY "..cam.y.."\nINV "..p.inv.."\n"..t,0,0,7,false,1,true) else fontPrint("[",4,4,13) --time icon fontPrint(string.format("%01d:%02d",math.floor(time()/1000/60),math.floor(time()/1000%60)),20,4,7) fontPrint("\\",4,12,12) --money icon end if p.view then fontPrint("l",228,4,11) --view icon end spr(p.frame,4,116,-1,1,0,0,2,2) fontPrint("_",20,124,7) --x sign fontPrint(tostring(p.hp),28,116,7,true) end function jayLogic() if jay.flight then jay.frame=442+math.floor((t/7.5)%2) if (distance(jay)>16) then jay.x=jay.x+((p.x+p.w/2-jay.x-jay.w/2)/20) jay.y=jay.y+((p.y+p.h/2-jay.y-jay.h/2)/20) else jay.flight=false jay.yVel=0 jay.csent=math.random(5) end if jay.x+jay.w/2=0 then jay.y=math.floor(jay.y+jay.yVel) jay.yVel=0 while touchingGround(1,jay) do jay.y=jay.y-1 end jay.y=jay.y+1 else jay.yVel=jay.yVel+0.25 jay.y=jay.y+jay.yVel end if distance(jay)>32 then jay.flight=true end end if jay.y+jay.h>water.y+2 then jay.flight=true jay.y=water.y-6 end end jay={ x=0,y=0, -- coords xVel=0,yVel=0, w=8,h=8, -- width & height flip=0, -- sprite flip flight=true } -- Define variables. p={ x=56,y=0, -- coords xVel=0,yVel=0, w=16,h=32, -- width & height xVelCap=1,yVelCap=4, -- speed caps anim={ -- various animations idle=256,jump=260,skid=262,hurt=264,crouch=266 }, frame=256, -- currently displayed frame run={ period=0, t=60, }, flip=0, -- flip sprite hp=20, char=0, -- seletcted character inv=0, -- invencibility counter crouch=false, -- is crouching? view=false, -- is in view mode? (move camera) lock=false -- lock the controls } function p.anim.run() p.run.period=math.ceil(10/math.floor(math.abs(p.xVel))) if p.run.t+1==p.run.period then p.run.t=0 else p.run.t=p.run.t+1 end return 256+math.floor((p.run.t/p.run.period)%2)*2 end cam={ x=p.x-120,y=p.y-68, w=240,h=136, box={w=16,h=32}, } water={ y=136 } debug=false t=0 function TIC() cls(0) -- check if sprint if btn(5) and not p.crouch and not p.lock then p.xVelCap=3 else p.xVelCap=1.5 end -- left-right controller checks (x axis) if (btn(2) and btn(3) or (not (btn(2) or btn(3)))) or (p.crouch and touchingGround()) or btn(7) or p.lock then p.xVel=p.xVel-sign(p.xVel)*0.125 p.frame=p.anim.idle elseif btn(2) and not (p.crouch and touchingGround()) then if p.xVel>-p.xVelCap then p.xVel=p.xVel-0.125 p.flip=1 else p.xVel=-p.xVelCap end if -(p.flip*2-1)==sign(p.xVel) then p.frame=p.anim.run() else p.frame=p.anim.skid end elseif btn(3) and not (p.crouch and touchingGround()) then if p.xVel=0 then p.y=math.floor(p.y+p.yVel) p.yVel=0 p.hurt=false while touchingGround() do p.y=p.y-1 end p.y=p.y+1 elseif p.yVelcam.x+(240/2+cam.box.w) then cam.x=cam.x+((p.x+p.w)-(cam.x+(240/2+cam.box.w))) else cam.x=math.floor(cam.x) end if p.ycam.y+(136/2+cam.box.h) then cam.y=cam.y+((p.y+p.h)-(cam.y+(136/2+cam.box.h))) else cam.y=math.floor(cam.y) end -- wrap coords around if exceeded wrapCoords() jayLogic() -- draw everything map(cam.x//8,cam.y//8,31,18,-(cam.x%8),-(cam.y%8),0,1,remap) if (p.inv%2==0 or p.frame==p.anim.hurt) then drawSprite(p) end drawSprite(jay) drawHUD() -- invencibility counter if p.inv>0 then p.inv=p.inv-1 end -- frame counter if t+1==720 then t=0 else t=t+1 end -- debug toggle if keyp(4) then debug=not debug end -- hitpoint toggle if keyp(8) then hitpoint=not hitpoint end -- char toggle if keyp(3) then if p.char==0 then p.char=1 else p.char=0 end end end function BDR(scanline) resetPalette() if scanline>=4+water.y-math.floor(cam.y)+round(math.sin(t/180*math.pi*2)*2) then -- murkify for i=0,15 do editColor(i,(peek(0x3fc0+i*3)+65)/2,(peek(0x3fc1+i*3)+120)/2,(peek(0x3fc2+i*3)+100)/2) end end end