Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.63 KB | None | 0 0
  1. --cruiser kid
  2. --@taeckerwyss 3cjam2017
  3.  
  4. p={}--player
  5. p.x=0
  6. p.y=7--graunded player y is 7
  7. p.z=0--player z is usually 5
  8. p.vx=0--velocity
  9. p.vy=0
  10. p.sprx=0
  11. p.spry=0
  12. p.w=16
  13. p.h=16
  14. p.refire=0
  15. p.scl=1
  16. p.flip=false
  17. jogstate=0
  18. jogcount=0
  19.  
  20. --0=alive
  21. --1=dead
  22. --2=respawn
  23. --3=invincible
  24. pstate=0
  25. pstatecounter=0
  26.  
  27. xdown=false
  28. zdown=false
  29.  
  30. bp={}--bullets:player
  31. be={}--bullets:enemy
  32. en={}--enemies
  33. smk={}--smoke
  34. xpl={}--explosions
  35. pts={}--lil numbers that appear when u get points
  36.  
  37. todraw={}--elements to z sort and draw
  38.  
  39. fnum=0--frame counter
  40.  
  41. --states: menu, level, game, gameover
  42. gamestate="menu"
  43. lives=0
  44. lifeplus=0
  45.  
  46. lvlnum=0
  47. lvlround=0
  48. spawnc=0
  49. spwnpool={}
  50.  
  51. menutween=0
  52. menutime=0--frames this menu has been open
  53. title={}--title text
  54. gmovr={}--gameover text
  55.  
  56. mrlog=""
  57.  
  58. score=0
  59. scrmulti=1
  60. multi=0.5
  61.  
  62.  
  63. cartdata("_cruiser_kid_")
  64. hiscore=0
  65. hiscoretxt="0"
  66. newhi=false
  67.  
  68. function _init()
  69. --dset(0,0) --clear highscore
  70. gethiscore()
  71. palt(7,true)
  72. palt(0,false)
  73. addtitle()
  74. addgmovr()
  75. entermenu()
  76. music(0,0,3)
  77.  
  78. end
  79.  
  80. function _update60()
  81. fnum+=1
  82.  
  83. if gamestate=="menu" then
  84. domenu()
  85. elseif gamestate=="gameover" then
  86. dogameover()
  87. else
  88. playerupdate()
  89. if gamestate=="level" then
  90. if p.y<=7 then
  91. p.vx=0
  92. end
  93. dolevel()
  94. else
  95. spawnloop()
  96. --update objects
  97. playermotor()
  98. foreach(en,doen)
  99. foreach(bp,dobp)
  100. foreach(be,dobe)
  101. --collisions
  102. foreach(bp,colenbp)
  103. if pstate==0 then --no col with player if dead or invincible
  104. foreach(en,colenp)
  105. foreach(be,colbep)
  106. end
  107. end
  108. playerlateupdate()
  109. if lifeplus>0 then
  110. lifeplus-=1
  111. end
  112. end
  113. --fx
  114. foreach(xpl,doxpl)
  115. foreach(smk,dosmk)
  116. foreach(pts,dopts)
  117.  
  118. xdown=btn(5)
  119. zdown=btn(4)
  120. end
  121.  
  122. function _draw()
  123. cls()
  124. todraw={}
  125. camera(0,max(-10,-p.y*0.2))
  126. spr(64,0,-10,16,4)--sky
  127. drawflr()
  128. if gamestate=="menu" then
  129. foreach(title,drawtitle)
  130. zsort(todraw)
  131. foreach(todraw,drawtodraw)
  132. drawmenu()
  133. elseif gamestate=="gameover" then
  134. zsort(todraw)
  135. foreach(todraw,drawtodraw)
  136. drawgameover()
  137. elseif gamestate=="game" then
  138. drawgame()
  139. drawhud()
  140. else --gamestate=="level"
  141. drawgame()
  142. drawlevel()
  143. drawhud()
  144. end
  145. end
  146.  
  147. function drawgame()--shared between gamestate "game" and "level"
  148. foreach(en,drawen)
  149. foreach(bp,drawbp)
  150. foreach(be,drawbe)
  151. drawplayer()
  152. foreach(smk,drawsmk)
  153. foreach(xpl,drawxpl)
  154. zsort(todraw)
  155. foreach(todraw,drawtodraw)
  156. foreach(pts,drawpts)
  157. camera(0,0)
  158. print(mrlog,0,0,7)
  159. end
  160.  
  161. function multiup()
  162. multiset( min(multi+0.05,3.99) )
  163. end
  164. function multidown()
  165. multiset( max(multi-0.03*multi,0.5) )
  166. end
  167.  
  168. function multibonus(amt)
  169. multiset( min(multi+amt,3.99) )
  170. end
  171.  
  172. function multiset(n)
  173. multi=n
  174. scrmulti=ceil(multi)
  175. end
  176.  
  177. function spawnloop()--called every frame. handle new enemy spawning
  178. if lvlround<=0 then
  179. if #en==0 then
  180. addlife()
  181. enterlevel()
  182. spawnc=60
  183. end
  184. else
  185. if #en==0 then
  186. spawnc=0
  187. else
  188. spawnc-=1
  189. end
  190. if spawnc<=0 then
  191. makemob()
  192. lvlround-=1
  193. spawnc=340
  194. end
  195. end
  196. end
  197.  
  198. function nextlevel()
  199. lvlnum+=1
  200. lvlround=6+2*lvlnum
  201. spwnpool={}
  202. local tbl={}
  203. if lvlnum<=1 then
  204. spwnpool[1]={0,12} --cat
  205. spwnpool[2]={1,12} --shrimp
  206. spwnpool[3]={11,1}--cat+shrimp
  207. spwnpool[4]={2}--bat
  208. spwnpool[5]={3}--tank
  209. spwnpool[6]={11,2}--cat+bat
  210. elseif lvlnum==2 then
  211. spwnpool[1]={0,2}--cat+bat
  212. spwnpool[2]={12,2}--shrimp+bat
  213. spwnpool[3]={3}--tank
  214. spwnpool[4]={5}--men
  215. spwnpool[5]={13}--men
  216. spwnpool[6]={8}--gnomes
  217. elseif lvlnum==3 then
  218. spwnpool[1]={3}--tank
  219. spwnpool[2]={4}--apc
  220. spwnpool[3]={7,12}--men+shrimp
  221. spwnpool[4]={5}--men
  222. spwnpool[5]={13,2}--men+bats
  223. spwnpool[6]={14}--robots
  224. elseif lvlnum==4 then
  225. spwnpool[1]={14}--robots
  226. spwnpool[2]={6}--robots
  227. spwnpool[3]={1,10}--gnomes+shrimp
  228. spwnpool[4]={8}--gnomes
  229. spwnpool[5]={6,11}--robots+cats
  230. spwnpool[6]={16}--planes
  231. elseif lvlnum==5 then
  232. spwnpool[1]={4}--apc
  233. spwnpool[2]={0,4}--apc+cats
  234. spwnpool[3]={12,2}--shrimp+bats
  235. spwnpool[4]={11,2}--cats+bats
  236. spwnpool[5]={5}--men
  237. spwnpool[6]={3}--tank
  238. elseif lvlnum==6 then
  239. spwnpool[1]={7,2}--men+bats
  240. spwnpool[2]={14}--robots
  241. spwnpool[3]={5,6}--robots+men
  242. spwnpool[4]={10,2}--gnomes+bats
  243. spwnpool[5]={15}--2x tank
  244. elseif lvlnum==7 then
  245. spwnpool[1]={7,16}--men+planes
  246. spwnpool[2]={14}--robots
  247. spwnpool[3]={5,6}--robots+men
  248. spwnpool[4]={10,16}--gnomes+planes
  249. spwnpool[5]={15}--2x tank
  250. elseif lvlnum==8 then
  251. spwnpool[1]={8,2,1}--gnomes+bats+shrimp
  252. spwnpool[2]={14,8}--gnomes+robots
  253. spwnpool[3]={10,6}--gnomes+men
  254. spwnpool[4]={2,16}--planes+bats
  255. spwnpool[5]={9}--turtle
  256. elseif lvlnum==9 then
  257. spwnpool[1]={6,0,11}--robots+2x cats
  258. spwnpool[2]={2,2,2}--3x bats
  259. spwnpool[3]={13,13}--2x men
  260. spwnpool[4]={4}--apc
  261. spwnpool[5]={9}--turtle
  262. elseif lvlnum==10 then
  263. spwnpool[1]={6}--robots
  264. spwnpool[2]={4}--apc
  265. spwnpool[3]={9}--turtle
  266. spwnpool[4]={3}--tank
  267. spwnpool[5]={5,13}--men
  268. spwnpool[6]={16,13}--planes+men
  269. elseif lvlnum==11 then
  270. spwnpool[1]={8,3}--gnomes+tank
  271. spwnpool[2]={10,4}--gnomes+apc
  272. spwnpool[3]={12,1,12}--shrimp
  273. spwnpool[4]={15,0}--2x tanks
  274. spwnpool[5]={6,14}--robots
  275. else
  276. spwnpool[1]={0,11,2,3}
  277. spwnpool[2]={12,4}
  278. spwnpool[3]={9,1}
  279. spwnpool[3]={9}
  280. spwnpool[4]={15}
  281. spwnpool[5]={8,8,8}
  282. spwnpool[6]={7,6}
  283. spwnpool[7]={14,14}
  284. spwnpool[8]={3,10}
  285. spwnpool[9]={10,4}
  286. spwnpool[10]={16,0}
  287. spwnpool[11]={16,6}
  288. end
  289. end
  290.  
  291. function makemob()
  292. r=flr(rnd(#spwnpool))+1
  293. spawn(spwnpool[r])
  294. end
  295.  
  296. function spawn(t)--t is a table of enemy types
  297. local k
  298. for i=1,#t do
  299. k=t[i]
  300. if k==0 then spwnrow( 0, 3+rnd(3), 100+rnd(20)) --0 row of cats
  301. spwnrow( 0, 3+rnd(3), 140+rnd(30))
  302. elseif k==1 then spwnchain( 1, 6+rnd(4), 25, 20) --1 troop of shrimp
  303. elseif k==2 then spwnchain( 2, 4+rnd(4), 80, 15) --2 squad of bats
  304. elseif k==3 then adden(rnd(110)-55, 120, 3) --3 one tank
  305. elseif k==4 then spwnantichain( 4, 3+rnd(2), 40, 60) --4 platoon of apcs
  306. elseif k==5 then spwnrow( 5, 2+rnd(3), 110+rnd(20)) --5 squad of men
  307. spwnrow( 5, 2+rnd(3), 150+rnd(20))
  308. elseif k==6 then spwnrow( 6, 2+rnd(2), 110+rnd(20)) --6 squad of robots
  309. spwnrow( 6, 2+rnd(2), 150+rnd(20))
  310. elseif k==7 then spwnantichain( 5, 4+rnd(4), 30, 20) --7 platoon of men
  311. elseif k==8 then spwnantichain( 7, 4+rnd(3), 20, 15) --8 platoon of gnomes
  312. elseif k==9 then adden(rnd(110)-55, 105, 8) --9 one turtle
  313. elseif k==10 then spwnrow(7, 2+rnd(3), 110+rnd(20)) --10 squad of gnomes
  314. spwnrow(7, 2+rnd(3), 150+rnd(20))
  315. elseif k==11 then spwnantichain( 0, 5+rnd(4), 40, 15) --11 platoon of cats
  316. elseif k==12 then spwnantichain( 1, 6+rnd(4), 50, 15) --12 scattering of shrimp
  317. elseif k==13 then spwnchain( 5, 5+rnd(3), 5, 15) --13 chain of men
  318. elseif k==14 then spwnchain( 6, 4+rnd(3), 10, 15) --14 chain on robots
  319. elseif k==15 then spwnrow(3, 2, 120) --15 pair of tanks
  320. elseif k==16 then spwnchain( 9, 3+rnd(3), 40, 25) --16 squad of planes
  321. end
  322. end
  323. end
  324.  
  325. function spwnrow(t,n,z)
  326. n=flr(n)
  327. local a=120/(n-1)
  328. for i=0,n-1 do
  329. adden(a*i-60,z+rnd(2),t)
  330. end
  331. end
  332.  
  333. function spwnchain(t,n,xrng,zrng)
  334. n=flr(n)
  335. local x=rnd(100)-50
  336. local z=105
  337. for i=1,n do
  338. adden(x,z,t)
  339. x=max(min(x+rnd(2*xrng)-xrng, 55),-55)
  340. z+=zrng+rnd(zrng*0.2)
  341. end
  342. end
  343.  
  344. function spwnantichain(t,n,xmin,zrng)
  345. n=flr(n)
  346. local x=rnd(100)-50
  347. local z=105
  348. local xmin2=2*xmin
  349. for i=1,n do
  350. adden(x,z,t)
  351.  
  352. local w=110+x-(x+xmin2)
  353. local rndo=rnd(w)-55
  354. if rndo>x-xmin then
  355. rndo+=xmin2
  356. end
  357. x=rndo
  358. z+=zrng
  359. end
  360. end
  361.  
  362.  
  363. function adden(x,z,t)
  364. local e={}
  365. e.x=x
  366. e.z=z
  367. e.t=t
  368. --defaults
  369. e.y=0
  370. e.vx,e.vy,e.vz=0,0,0.25
  371. e.w,e.h=16,16--width/height in px on spritesheet
  372. e.scl=1.5--scale
  373. e.sprx,e.spry = 64,16--sprite coordinates
  374. e.points,e.bonus = 100,0.05
  375. e.shadow,e.flip = false,false
  376. e.counter=0
  377. e.hp=1
  378. e.nudge=2
  379. e.parts={}
  380. if t==0 then--cat
  381. e.vz=0.4
  382. e.scl=1
  383. e.hp=6
  384. e.agetowiggle=rnd(30)
  385. e.parts.flip=e.flip
  386. local butt={}
  387. butt.sprx,butt.spry=0,16
  388. butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl
  389. butt.xo,butt.yo,butt.zo=0,0,1.8
  390. add(e.parts,butt)
  391. elseif t==1 then --shrimp
  392. e.vz=0.25
  393. e.sprx,e.spry=64,64
  394. e.w=8
  395. e.hp=2
  396. e.scl=1
  397. e.offset=rnd(1)
  398. e.offset2=flr(rnd(20))
  399. elseif t==2 then --bat
  400. e.bonus = 0.2
  401. e.vz=0.25
  402. e.y=30
  403. e.sprx=80
  404. e.h=8
  405. e.shadow = true
  406. e.points = 200
  407. e.counter=rnd(3)
  408. elseif t==3 then --tank
  409. e.bonus = 0.6
  410. e.sprx=48
  411. e.hp=18
  412. e.points=1000
  413. e.range=35+rnd(20)
  414. e.state=0
  415. e.scl=4
  416. e.offset=rnd(1)
  417. e.nudge=0
  418. local butt={}
  419. butt.sprx,butt.spry=32,16
  420. butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl
  421. butt.xo,butt.yo,butt.zo=0,0,3
  422. add(e.parts,butt)
  423. elseif t==4 then --apc
  424. e.bonus = 0.75
  425. e.sprx=112
  426. e.hp=10
  427. e.vz=0.45
  428. e.points=800
  429. e.scl=3
  430. e.counter=rnd(1)
  431. e.offset=rnd(1)
  432. e.nudge=0.1
  433. local butt={}
  434. butt.sprx,butt.spry=16,16
  435. butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl
  436. butt.xo,butt.yo,butt.zo=0,0,2.5
  437. add(e.parts,butt)
  438. elseif t==5 then -- man
  439. e.bonus = 0.1
  440. e.hp=3
  441. e.flipcounter=rnd(1)
  442. e.w=8
  443. e.sprx=96
  444. e.points = 300
  445. e.vz=0.25+rnd(0.05)
  446. elseif t==6 then -- robot
  447. e.bonus = 0.15
  448. e.hp=6
  449. e.flipcounter=rnd(1)
  450. e.w=8
  451. e.sprx=104
  452. e.points = 400
  453. e.scl=2.1
  454. e.vz=0.15+rnd(0.05)
  455. e.shootang=-0.12
  456. elseif t==7 then -- gnome
  457. e.bonus = 0.3
  458. e.hp=8
  459. e.flipcounter=rnd(1)
  460. e.points = 300
  461. e.sprx,e.spry=32,64
  462. e.points = 400
  463. e.vz=0.1
  464. e.shootang=-0.12
  465. e.scl=2.2
  466. e.floory=e.h*e.scl*0.5
  467. e.airborn=false
  468. elseif t==8 then -- turtle
  469. e.bonus = 0.8
  470. e.w,e.h=32,32
  471. e.sprx,e.spry = 0,64
  472. e.points = 2000
  473. e.hp=30
  474. e.nudge=0
  475. e.state=0
  476. e.vz=0.25
  477. e.scl=3
  478. e.range=30+rnd(20)
  479. local butt={}
  480. butt.sprx,butt.spry=48,80
  481. butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl*2
  482. butt.xo,butt.yo,butt.zo=0,0,6.5
  483. add(e.parts,butt)
  484. elseif t==9 then --plane
  485. e.bonus = 0.3
  486. e.vz=0.3
  487. e.y=30
  488. e.hp=4
  489. e.sprx,e.spry=80,64
  490. e.w=32
  491. e.shadow = true
  492. e.points = 300
  493. e.counter=rnd(3)
  494. e.scl=1.5
  495. e.offset=rnd(1)
  496. end
  497. e.y+=e.h*e.scl*0.5
  498. e.age=0
  499. e.hurt=0
  500. add(en,e)
  501. end
  502.  
  503. function doen(i)
  504. if i.hurt>0 then
  505. i.hurt-=1
  506. end
  507. if i.z<100 then
  508. i.age+=1
  509. --cat
  510. if i.t==0 then
  511. if i.age>i.agetowiggle then
  512. i.agetowiggle+=5+rnd(20)
  513. i.flip=not i.flip
  514. i.parts[1].flip=i.flip
  515. end
  516. --shrimp
  517. elseif i.t==1 then
  518. i.counter+=1
  519. if p.x-i.x>30 then
  520. i.vx=0.15
  521. elseif p.x<-30 then
  522. i.vx=-0.15
  523. else
  524. i.vx=0
  525. end
  526. i.vx+=sin(0.01*i.age+i.offset)
  527. if (i.age+i.offset2)%20 ==0 then
  528. i.flip=not i.flip
  529. end
  530. --bat
  531. elseif i.t==2 then
  532. if fnum%28==0 then
  533. if i.spry==24 then
  534. i.spry=16
  535. else
  536. i.spry=24
  537. if i.z<70 then
  538. i.counter+=1
  539. if i.counter>=4 then
  540. eshoot(i.x,i.y,i.z, 0,-0.25,0.4, 8)
  541. i.counter=0
  542. end
  543. end
  544. end
  545. end
  546. -- tank
  547. elseif i.t==3 then
  548. if i.state==0 then
  549. if i.z<70 then
  550. i.state=1+flr(rnd(2))
  551. i.nudge=1
  552. end
  553. else
  554. i.counter+=1
  555. if i.x>64 then i.x=64 end
  556. if i.x<-64 then i.x=-64 end
  557. i.vx=sin(0.002*fnum+i.offset)*0.4+sin(0.009*i.age)*0.6
  558. if i.z>i.range then
  559. i.vz=0.25
  560. elseif i.vz>0 then
  561. i.vz*=0.9
  562. end
  563. if i.state==1 then
  564. if i.counter==100 or i.counter==160 then
  565. shootspread( i.x,7,i.z, 0.5, 8, 4+flr(rnd(3)), 0.03)
  566. elseif i.counter>300 then
  567. i.counter,i.state=0,2
  568. end
  569. else--i.state==2
  570. if i.counter%20==1 then
  571. shootat( i.x,i.y+20,i.z, p.x,7,p.z, 0.5, 8)
  572. elseif i.counter>=80 then
  573. i.counter,i.state=0,1
  574. end
  575. end
  576. end
  577. -- apc
  578. elseif i.t==4 then
  579. i.vx=sin(0.015*i.age+i.offset)*0.5
  580. if i.z<70 and i.z>20 then
  581. i.counter+=0.017
  582. if i.counter>=1 then
  583. i.counter=0
  584. shootbeamat( i.x,i.y+20,i.z, p.x,7,p.z, 0.55, 0.04, 3, 8)
  585. end
  586. end
  587. -- man
  588. elseif i.t==5 then
  589. i.vx=min(1,max(-1, i.vx+rnd(0.02)-0.01))
  590. if i.z<90 then
  591. i.flipcounter+=0.12
  592. if i.flipcounter>=1 then
  593. i.flip= not i.flip
  594. i.flipcounter=0
  595. end
  596. if i.z<60 then
  597. if i.z>20 then
  598. i.counter+=1
  599. if i.counter>=80 then
  600. shootat( i.x,i.y,i.z, p.x,p.y,p.z, 0.5, 12)
  601. i.counter=0
  602. end
  603. end
  604. end
  605. end
  606. -- robot
  607. elseif i.t==6 then
  608. if i.z<90 then
  609. i.vz=sin(i.age*0.01)*0.1+0.15
  610. i.flipcounter+=0.1
  611. if i.flipcounter>=1 then
  612. i.flip= not i.flip
  613. i.flipcounter=0
  614. end
  615. if i.z<60 then
  616. i.vx=min(1,max(-1, i.vx+rnd(0.04)-0.02))
  617. i.counter+=1
  618. if i.counter>=60 and i.counter<78 then
  619. if i.counter%4==0 then
  620. shootyangle(i.x,i.y,i.z, i.shootang , 0.5, 6)
  621. i.shootang+=0.06
  622. end
  623. end
  624. end
  625. end
  626. -- gnome
  627. elseif i.t==7 then
  628. if abs(i.x)>60 then
  629. i.x=min(60,max(-60,i.x))
  630. i.vx*=-1
  631. end
  632. if i.airborn then
  633. if i.y>i.floory then
  634. i.vy-=0.2
  635. else--landed
  636. sfx(21,3)
  637. i.vx=rnd(1)-0.5
  638. i.vy=0
  639. i.vz=0.05
  640. i.y=i.floory
  641. i.airborn=false
  642. end
  643. else
  644. i.flipcounter+=0.15
  645. if i.flipcounter>=1 then
  646. i.flip=not i.flip
  647. i.flipcounter=0
  648. end
  649. i.counter+=1
  650. if i.counter == 90 and i.z<70 then
  651. shootspread( i.x,i.y,i.z, 0.7, 10, 4, 0.005)
  652. elseif i.counter >= 95 then
  653. sfx(22,3)
  654. local angle=rnd(0.46)-0.23
  655. i.vx=sin(angle)
  656. i.vy=3
  657. i.vz=cos(angle)*0.7
  658. i.airborn=true
  659. i.counter=0
  660. i.flip=not i.flip
  661. end
  662. end
  663. --turtle
  664. elseif i.t==8 then
  665. if i.state==0 then
  666. if i.z<70 then
  667. i.state=1
  668. i.nudge=0.5
  669. end
  670. else
  671. i.counter+=1
  672. i.vx=sin(i.age*0.001)*0.3
  673. if i.z>i.range then
  674. i.vz=0.2
  675. elseif i.vz != 0 then
  676. i.vz=0
  677. end
  678. if i.state==1 or i.state==3 then
  679. if i.counter>140 then
  680. i.counter=0
  681. i.state+=1
  682. end
  683. elseif i.state==2 then
  684. if i.counter%40==20 then
  685. shootbeamat( i.x,i.y+20,i.z, p.x,p.y,p.z, 0.56, 0.04, 4, 14)
  686. elseif i.counter>120 then
  687. i.counter,i.state=0,3
  688. end
  689. else--i.state==4
  690. if i.counter%12==1 then
  691. shootyangle(i.x,12,i.z, sin(i.counter*.005)*.2, 0.45, 8)
  692. elseif i.counter>=200 then
  693. i.counter,i.state=0,1
  694. end
  695. end
  696. end
  697.  
  698. elseif i.t==9 then
  699. i.vy=sin(0.008*i.age+i.offset)*0.3
  700. if i.counter<1 and i.z<50 then
  701. i.counter=1
  702. shootbeamat( i.x,i.y+8,i.z, p.x,7,p.z, 0.4, 0.04, 5, 8)
  703. end
  704.  
  705. end
  706. end
  707. i.x+=i.vx
  708. i.y+=i.vy
  709. i.z-=i.vz
  710. if i.z<=0 then
  711. del(en,i)
  712. end
  713. end
  714.  
  715. function damage(nme,amt)
  716. multiup()
  717. nme.hp-=amt
  718. nme.z+=nme.nudge
  719. if nme.hp<=0 then
  720.  
  721. killen(nme)
  722. return
  723. end
  724. sfx(9+flr(rnd(4)),2)
  725. nme.hurt=3
  726. end
  727.  
  728. function killen(i)
  729. getpoints(i.points,i.x,i.y,i.z)
  730. multibonus(i.bonus)
  731. if i.bonus<0.3 then
  732. sfx(15,3)
  733. else
  734. sfx(16,3)
  735. end
  736. addxpl(i.x, i.y, i.z, 40, false)
  737. del(en,i)
  738. end
  739.  
  740. function drawen(i)
  741. local flashing=i.hurt>0
  742. drawsspr(i,i.shadow,flashing)
  743. if #i.parts>=1 then
  744. for k=1,#i.parts do
  745. i.parts[k].x=i.x+i.parts[k].xo
  746. i.parts[k].y=i.y+i.parts[k].yo
  747. i.parts[k].z=i.z+i.parts[k].zo
  748. drawsspr(i.parts[k],false,flashing)
  749. end
  750. end
  751. end
  752.  
  753. function shootat(x,y,z, tx,ty,tz, spd, scl)
  754. eshoot(x,y,z, ((tx-x)/(tz-z))*-spd, ((ty-y)/(tz-z))*-spd, spd, scl)
  755. end
  756.  
  757. function shootyangle(x,y,z, ang, spd, scl)
  758. eshoot(x,y,z, sin(ang)*spd*3,0,cos(ang)*spd, scl)
  759. end
  760.  
  761. function shootxangle(x,y,z, vx, ang, spd, scl)
  762. eshoot(x,y,z, vx, sin(ang)*spd*2,cos(ang)*spd, scl)
  763. end
  764.  
  765. function shootbeamat(x,y,z, tx,ty,tz, minspd, spdstep, n, scl)
  766. for i=0,n-1 do
  767. shootat( x,y,z, tx,ty,tz, minspd+spdstep*i, scl)
  768. end
  769. end
  770.  
  771. function shootspread(x,y,z, spd, scl, num, step)--step is step in angles (.125 is a 45 degree angle)
  772. local cursr=(num-1)*step*-0.5
  773. for i=1,num do
  774. eshoot(x,y,z, sin(cursr)*spd*3,0,cos(cursr)*spd, scl)
  775. cursr+=step
  776. end
  777. end
  778.  
  779. function eshoot(x,y,z, vx,vy,vz, scl)
  780. sfx(8,3)
  781. local bullet={}
  782. bullet.x=x
  783. bullet.y=y
  784. bullet.z=z
  785. bullet.vx=vx
  786. bullet.vy=vy
  787. bullet.vz=vz
  788. bullet.scl=1
  789. bullet.w=scl
  790. bullet.h=scl
  791. bullet.age=0
  792. add(be,bullet)
  793. end
  794.  
  795. function dobe(i)
  796. i.age+=1
  797. i.x+=i.vx
  798. i.y+=i.vy
  799. i.z-=i.vz
  800. if i.z<0.1 or i.z>90 then
  801. del(be,i)
  802. end
  803. if i.y<0 then
  804. del(be,i)
  805. addsmk(i.x,0,i.z,i.w*0.1)
  806. end
  807. end
  808.  
  809. function drawbe(i)
  810. local size=i.w*0.5
  811. if i.age<8 then
  812. size*=i.age*0.4
  813. end
  814. drawcirc(i.x, i.y, i.z, size, color(i.age*0.5%3), true)
  815. drawcirc(i.x, 0, i.z, i.w*0.3, 3, true)
  816. end
  817.  
  818.  
  819. --visualstuff
  820.  
  821. function addsmkpuff(x,y,z,n,r)
  822. for i=0,n do
  823. local angle=rnd(1)
  824. local power=rnd(rnd(1))
  825. local smksize=rnd(1-power)
  826. power=power*r
  827. addsmk(x+sin(angle)*power, y+rnd(r-power), z+cos(angle)*power*0.15, smksize)
  828. end
  829. end
  830.  
  831. function addsmkrnd(x,y,z,r,scl)
  832. addsmk(x+rnd(r)+rnd(r)-r, y+rnd(r)+rnd(r)-r, z, rnd(scl))
  833. end
  834.  
  835. function addsmk(x,y,z,size)
  836. local smoke={}
  837. smoke.x=x
  838. smoke.y=y
  839. smoke.z=z
  840. smoke.age=1
  841. smoke.size=size
  842. smoke.grow=0.5+rnd(0.7)
  843. smoke.life=10+rnd(35)
  844. add(smk,smoke)
  845. end
  846.  
  847. function dosmk(i)
  848. i.z-=0.15
  849. i.age+=1
  850. if i.age>i.life or i.z<1 then
  851. del(smk,i)
  852. end
  853. end
  854.  
  855. function drawsmk(i)
  856. drawcirc( i.x, i.y, i.z, sqrt(i.age)*i.grow+i.size, 3, false)
  857. end
  858.  
  859. function addxpl(x,y,z,scl,player)
  860. local xp={}
  861. xp.x=x
  862. xp.y=y
  863. xp.z=z
  864. xp.scl=scl
  865. xp.age=10
  866. if player then
  867. xp.age=0
  868. xp.offset=rnd(1)
  869. end
  870. add(xpl,xp)
  871. end
  872.  
  873. function doxpl(i)
  874. i.age+=1
  875. if i.age>35 then
  876. del(xpl,i)
  877. end
  878. end
  879.  
  880. function drawxpl(i)
  881. if i.age<10 then
  882. local colo=color(i.age%3)
  883. local anglo=0.07*(i.x+sqrt(i.age))+i.offset
  884. drawcross( i.x, i.y, i.z-0.1, 8*(10-i.age), anglo, 8)
  885. drawcirc( i.x, i.y, i.z, 0.2*i.scl*(10-i.age), colo, false)
  886. elseif i.age<16 then
  887. drawcirc( i.x, i.y, i.z, i.scl, color(0.5*i.age%3), true)
  888. else
  889. drawcirc( i.x, i.y, i.z, i.scl*i.age*0.04, 8, false)
  890. end
  891. end
  892.  
  893. function getpoints(amt, x, y, z)
  894. local points=amt*scrmulti
  895. score+=ceil(points*.01)
  896. addpts(points,x,y,z)
  897. end
  898.  
  899. function addpts(amt,x,y,z)
  900. local point={}
  901. local t=tostring(amt)
  902. point.c=#t
  903. for i=1,point.c do
  904. point[i]= sub(t,i,i+1)
  905. end
  906. local ok=ztoscalar(z)
  907. point.x=xcoord(x,ok)
  908. point.y=ycoord(y,ok)
  909. point.age=50+amt*0.05
  910. add(pts, point)
  911. end
  912.  
  913. function dopts(i)
  914. i.age-=1
  915. if i.age<=0 then
  916. del(pts, i)
  917. end
  918. end
  919. -- player
  920. function drawpts(i)
  921. cursorx=i.x-i.c*2
  922. cursory=i.y-5
  923. for j=1,i.c do
  924. cursorx += 4
  925. print (i[j], cursorx, cursory+5*sin(0.02*(j*2+i.age)), color((i.age*0.1)%3))
  926. end
  927. end
  928.  
  929. function playerupdate()--occurs in game or level screen
  930. if pstate==1 then return end
  931. if p.z<5 then
  932. p.z=min(5,p.z+0.1)
  933. end
  934. if p.y<=7 then
  935. pjog()
  936. else --airborn
  937. if pairborn() then
  938. sfx(13,3)
  939. p.vy=0
  940. p.y=7
  941. p.vx=min(1.2,max(-1.2,p.vx))
  942. addsmkpuff(p.x,0,p.z,4,16)
  943. elseif fnum%5==0 then
  944. addsmkrnd(p.x,p.y,p.z,4,1)
  945. end
  946. end
  947. end
  948.  
  949. function playerlateupdate()
  950. if pstate==1 then return end
  951. applypvx()
  952. end
  953.  
  954. function playermotor()--occurs only in game, not in level screen
  955. if pstate==1 then
  956. if pstatecount() then
  957. pspawn()
  958. end
  959. return end
  960. if pstate==2 then
  961. if pstatecount() then
  962. pstate=0
  963. end
  964. end
  965.  
  966. if p.y<=7 then
  967. --directional control
  968. if btn(0) then
  969. p.vx=max(-1.2,p.vx-0.4)
  970. elseif btn(1) then
  971. p.vx=min(1.2,p.vx+0.4)
  972. else
  973. if p.vx>0 then
  974. p.vx=max(0,p.vx-0.4)
  975. elseif p.vx<0 then
  976. p.vx=min(0,p.vx+0.4)
  977. end
  978. end
  979. --jump
  980. if xpressed() then
  981. sfx(6,3)
  982. addsmkpuff(p.x, 0,5,6,25)
  983. p.vy=4.5
  984. if btn(0) then
  985. p.vx=-1.8
  986. elseif btn(1) then
  987. p.vx=1.8
  988. else
  989. p.vx=0
  990. end
  991. p.y+=p.vy*2
  992. jogstate=0
  993. jogcount=0
  994. if (p.vx>0.1) then
  995. p.sprx=64
  996. elseif (p.vx<-0.1) then
  997. p.sprx=48
  998. else
  999. p.sprx=0
  1000. end
  1001. end
  1002. end
  1003. --shoot
  1004. if p.refire>0 then
  1005. p.refire-=1
  1006. elseif btn(4) then
  1007. pshoot()
  1008. p.refire=6
  1009. end
  1010. end
  1011.  
  1012. function pjog()--jog
  1013. if jogstate==1 then
  1014. jogcount+=0.05
  1015. p.sprx=16
  1016. elseif jogstate==3 then
  1017. jogcount+=0.05
  1018. p.sprx=32
  1019. else
  1020. jogcount+=0.2
  1021. p.sprx=0
  1022. end
  1023. if jogcount>1 then
  1024. jogcount=0
  1025. if jogstate==0 then
  1026. addsmk(p.x-4,4,p.z,1)
  1027. sfx(14,2)
  1028. elseif jogstate==2 then
  1029. addsmk(p.x+4,4,p.z,1)
  1030. sfx(14,2)
  1031. end
  1032. jogstate=(jogstate+1)%4
  1033. end
  1034. end
  1035.  
  1036. function pairborn()
  1037. p.vy-=0.3
  1038. p.y+=p.vy
  1039. if p.y<=7 then--land
  1040. return true
  1041. end
  1042. return false
  1043. end
  1044.  
  1045. function pstatecount()
  1046. pstatecounter-=1
  1047. return pstatecounter<=0
  1048. end
  1049.  
  1050. function playerkill()
  1051. sfx(19,1)
  1052. addxpl(p.x, p.y, p.z, 40, true)
  1053. pstatecounter=60
  1054. pstate=1
  1055. p.y=7
  1056. end
  1057.  
  1058. function pspawn()
  1059. multiset(0.5)
  1060. lives-=1
  1061. if lives<0 then
  1062. entergameover()
  1063. else
  1064. preset()
  1065. end
  1066. end
  1067.  
  1068. function preset()
  1069. jogstate=0
  1070. jogcount=0
  1071. pstatecounter=180
  1072. pstate=2
  1073. p.x=0
  1074. p.y=7
  1075. p.z=0.1
  1076. end
  1077.  
  1078. function applypvx()
  1079. p.x+=p.vx
  1080. if p.x<-60 then
  1081. p.x=-60
  1082. p.vx=0
  1083. elseif p.x>60 then
  1084. p.x=60
  1085. p.vx=0
  1086. end
  1087. end
  1088.  
  1089. function drawplayer()
  1090. if pstate==1 or ( pstate>=2 and flr(fnum*0.5)%2==0 )then --flash when invincible
  1091. return
  1092. end
  1093. local pycache=p.y
  1094. if p.y==7 then
  1095. if jogstate==1 or jogstate==3 then
  1096. p.y-=8*sin(jogcount*0.5)
  1097. end
  1098. end
  1099. drawsspr(p,false, false)
  1100. p.y=pycache
  1101. end
  1102.  
  1103. function pshoot()
  1104. sfx(7,2)
  1105. local shot={}
  1106. shot.x=p.x
  1107. shot.y=p.y
  1108. shot.z=5
  1109. shot.w=12
  1110. shot.h=12
  1111. shot.scl=1
  1112. add(bp,shot)
  1113. end
  1114.  
  1115. function dobp(i)
  1116. i.z+=1
  1117. if i.z>70 then
  1118. multidown()
  1119. del(bp,i)
  1120. end
  1121. end
  1122.  
  1123. function drawbp(i)
  1124. drawcirc(i.x, i.y, i.z, i.w*0.4, 8, false)
  1125. end
  1126.  
  1127. -- collisions
  1128.  
  1129. function colenbp(i)
  1130. for j=1,#en do
  1131. if checkcol(en[j],i) then
  1132. damage(en[j],1)
  1133. del(bp,i)
  1134. return
  1135. --hitfx
  1136. end
  1137. end
  1138. end
  1139.  
  1140. function colenp(i)
  1141. if checkcol(i,p) then
  1142. playerkill()
  1143. end
  1144. end
  1145.  
  1146. function colbep(i)
  1147. if checkcol(i,p) then
  1148. playerkill()
  1149. addsmk(i.x,0,i.z,i.w*0.1)
  1150. del(be,i)
  1151. end
  1152. end
  1153.  
  1154. --scenery
  1155.  
  1156. function drawflr()
  1157. local y
  1158. for z=fnum*-0.25%14, 100, 14 do
  1159. y=ycoord(0,ztoscalar(z))+1
  1160. line(0, y, 140, y, 3)
  1161. end
  1162.  
  1163. end
  1164.  
  1165. --gamestate/menu
  1166.  
  1167. function newgame()
  1168. multiset(0.5)
  1169. smk={}
  1170. xpl={}
  1171. pts={}
  1172. score=0
  1173. lives = 4
  1174. lvlnum=0
  1175. lvlround=0
  1176. preset()
  1177. enterlevel()
  1178. newhi=false
  1179. end
  1180.  
  1181. function tweenui()
  1182. menutween+=1
  1183. if menutween>=30 then
  1184. return true
  1185. end
  1186. return false
  1187. end
  1188.  
  1189. function domenu()
  1190. menutime+=1
  1191. if menutween!=0 then
  1192. if tweenui() then
  1193. newgame()
  1194. end
  1195. else
  1196. if xpressed() or zpressed() then
  1197. menutween=1--close menu
  1198. sfx(18,3)
  1199. end
  1200. end
  1201. dotitle()
  1202. end
  1203.  
  1204. function dolevel()
  1205. menutime+=1
  1206. if menutween!=0 then
  1207. if tweenui() then
  1208. entergame()
  1209. end
  1210. else
  1211. if menutime>300 or (xpressed() or zpressed()) then
  1212. menutween=1--close menu
  1213. sfx(18,3)
  1214. end
  1215. end
  1216. end
  1217.  
  1218. function dogameover()
  1219. menutime+=1
  1220. if menutween!=0 then
  1221. if tweenui() then
  1222. entermenu()
  1223. end
  1224. else
  1225. if xpressed() or zpressed() then
  1226. menutween=1--close menu
  1227. sfx(18,3)
  1228. end
  1229. end
  1230. foreach(gmovr,dogmovr)
  1231. end
  1232.  
  1233. function drawmenu()
  1234. local t=menutween*3
  1235. local hstxt="hi:"..hiscoretxt
  1236. namebar("\148\139\131\144\145\151\150\129\144\151\142\135\135\129\144\142\143\143\143\129\144", -1-abs(menutween),3,0,false,true)
  1237. namebar(" - 3cjam 2017 - @taeckerwyss", 120+abs(menutween),3,0,true)
  1238. rectfill(2+t,3, 2+t+4*#hstxt,5, 0)
  1239. print(hstxt,2+t,2,8)
  1240. print("\139/\145 - move",40-t*3,74,8)
  1241. print(" x - jump",40-t*3,90,8)
  1242. print(" z - shoot",40-t*3,82,8)
  1243. if menutween!=0 or flr(fnum*0.07)%4>0 then
  1244. printcenter("press start",0,110-menutween*4,8)
  1245. end
  1246. if newhi and menutween==0 and flr(fnum*0.05)%3>0 then
  1247. print("new!",#hstxt*4-4,5,color(0.5*fnum%3))
  1248. end
  1249. end
  1250.  
  1251. function drawlevel()
  1252. local t=menutween*3
  1253. line(0,62+t, 128,62+t, 8)
  1254. printcenter("zone "..lvlnum,0,64+t,8)
  1255. line(0,71+t, 128,71+t, 8)
  1256. printcenter("love is "..max(0,1001-lvlnum).."00 miles away",t,72+t,8)
  1257. print("cruiser kid \144\144\144",16-t,57+t,8)
  1258. end
  1259. function drawgameover()
  1260. namebar("game over - well played - try again? - ", 7-abs(menutween),3,0,false)
  1261. namebar("[hint] - your multi drains if you miss shots - ", 112+abs(menutween),3,0,true)
  1262. printcenter("hiscore",0,82+menutween*4,8)
  1263. printcenter(hiscoretxt,0,90+menutween*4,8)
  1264. foreach(gmovr,drawgmovrcirc)
  1265. foreach(gmovr,drawgmovr)
  1266. if newhi and menutween==0 and flr(fnum*0.07)%4>0 then
  1267. print("new!",80,79,color(0.5*fnum%3))
  1268. end
  1269. end
  1270.  
  1271. function entermenu()
  1272. sfx(17,2)
  1273. menutween=-30
  1274. gamestate="menu"
  1275. menutime=0
  1276. end
  1277.  
  1278. function enterlevel()
  1279. sfx(17,2)
  1280. p.refire=3
  1281. bp={}
  1282. be={}
  1283. en={}
  1284. nextlevel()
  1285. menutween=-30
  1286. gamestate="level"
  1287. menutime=0
  1288. end
  1289.  
  1290. function entergameover()
  1291. sfx(20,3)
  1292. if score>hiscore then
  1293. sethiscore(score)
  1294. newhi=true
  1295. else
  1296. newhi=false
  1297. end
  1298. startgmovr()
  1299. menutween=-30
  1300. gamestate="gameover"
  1301. menutime=0
  1302. end
  1303. function entergame()
  1304. gamestate="game"
  1305. end
  1306.  
  1307. function gethiscore()
  1308. hiscore=dget(0)
  1309. hiscoretxt="$ "..hiscore.."00"
  1310. end
  1311. function sethiscore(i)
  1312. hiscore=i
  1313. hiscoretxt="$ "..hiscore.."00"
  1314. dset(0,hiscore)
  1315. end
  1316.  
  1317. function addlife()
  1318. lives+=1
  1319. sfx(23,1)
  1320. lifeplus=60
  1321. end
  1322.  
  1323. function drawlifeplus()
  1324. if lifeplus<=0 then return end
  1325. print("+1", 23, 100+lifeplus*0.25, color(1+fnum*0.25%2))
  1326. end
  1327.  
  1328. function drawhud()
  1329. rectfill(0,108,128,128,0)
  1330.  
  1331. local scrstring="$ "..score.."00"
  1332. print(scrstring,124-#scrstring*4,112,8)
  1333. scrstring="hi:"..hiscoretxt
  1334. print(scrstring,124-#scrstring*4,121,3)
  1335.  
  1336. line(34,109, 34,128, 3)
  1337. line(66,109, 66,128, 3)
  1338.  
  1339. line(40,126, 60,126, 3)
  1340. pset(40,125,3)
  1341. pset(45,125,3)
  1342. pset(50,125,3)
  1343. pset(55,125,3)
  1344. pset(60,125,3)
  1345.  
  1346. line(40,126, 40+multi*5,126, 8)
  1347. line(40,125, 40+multi*5,125, 8)
  1348. local multicolor=3
  1349. if scrmulti>1 then
  1350. multicolor=8
  1351. end
  1352.  
  1353. print("multi", 41,110,3)
  1354. print("x"..scrmulti, 47,116,multicolor)
  1355.  
  1356. local colr=3
  1357. if lives==0 and flr(fnum*0.04)%2==0 then
  1358. colr=8
  1359. end
  1360. print("\134", 8, 109, colr)
  1361. print("\137x"..lives, 8, 112, colr)
  1362.  
  1363. print("zone-"..lvlnum,3,121,3)
  1364. drawlifeplus()
  1365. end
  1366.  
  1367. function addtitle()
  1368. local ts={224,225,226,227,228,229,225,230,227,231}
  1369. for i=1,10 do
  1370. local letr={}
  1371. letr.x=-110+20*i
  1372. if (i>7) letr.x+=16
  1373. letr.y=60
  1374. letr.z=100
  1375. letr.cntrz=20+abs(letr.x*0.12)
  1376. letr.cntry=60
  1377. letr.sp=ts[i]
  1378. add(title,letr)
  1379. end
  1380. end
  1381.  
  1382. function dotitle()
  1383. local anglo
  1384. for i=1,10 do
  1385. anglo=menutime*0.02-i*0.1
  1386. title[i].z=(title[i].cntrz-abs(menutween)*3)+sin(anglo)*2
  1387. title[i].y=(title[i].cntry+abs(menutween)*4) +cos(anglo)*5
  1388. title[i].x+=cos(menutime*0.0039+i*0.01)*0.25
  1389. end
  1390. end
  1391.  
  1392. function drawtitle(i)
  1393.  
  1394. for k=1,5 do
  1395. drawspr(i.sp,i.x,i.y,i.z+k*6,1,2,true,true)
  1396. end
  1397. drawspr(i.sp,i.x,i.y,i.z,1,2,true,false)
  1398. end
  1399.  
  1400. function addgmovr()
  1401. local xgutter=36
  1402. local gap =(128-xgutter*2)/3
  1403. local letterz={64,72,80,88,96,104,88,112}
  1404. for i=0,7 do
  1405. letter={}
  1406. letter.x=xgutter+gap*(i%4)
  1407. letter.y=45+gap*flr(i/4)
  1408. letter.age=0-i*10
  1409. letter.sprx=letterz[i+1]
  1410. letter.spry=96
  1411. add(gmovr,letter)
  1412. end
  1413. end
  1414.  
  1415. function startgmovr()
  1416. for i=1,#gmovr do
  1417. gmovr[i].age=0-(i-1)*10
  1418. end
  1419. end
  1420.  
  1421. function dogmovr(i)
  1422. i.age+=1
  1423. if i.age==35 then
  1424. sfx(21,1)
  1425. end
  1426. end
  1427.  
  1428. function drawgmovrcirc(i)
  1429. if i.age>=35 and i.age<50 then
  1430. if i.age>37 then
  1431. mcirc(i.x,i.y ,3*sqrt(i.age-30) ,color(rnd(3)) )
  1432. else
  1433. mcircfill(i.x,i.y ,16 ,8 )
  1434. end
  1435. end
  1436. end
  1437.  
  1438. function drawgmovr(i)
  1439. if (i.age<0) return
  1440. local scale
  1441. if i.age<35 then
  1442. scale=1+(35-i.age)*0.1
  1443. else
  1444. scale=1
  1445. end
  1446. if menutween>0 then
  1447. scale*=(30-menutween)*0.033
  1448. end
  1449. local myx=i.x-scale*4
  1450. local myy=i.y-scale*4
  1451. local myw=scale*8
  1452. sspr( i.sprx, i.spry, 8, 8, myx, myy, myw, myw)
  1453. end
  1454.  
  1455. function namebar (t, yloc,c1,c2,reverse,double)
  1456. rectfill(0, yloc+1, 128, yloc+3, c2)
  1457. local length=#t*4
  1458. if double then length*=2 end
  1459. local ok=fnum
  1460. if reverse then ok*=-1 end
  1461. ok=ok*0.5%length
  1462. print(t, ok, yloc, c1)
  1463. print(t,ok-length, yloc, c1)
  1464. end
  1465.  
  1466. function printcenter(txt,xoffset,y,col)
  1467. print(txt,xoffset+64-2*#txt,y,col)
  1468. end
  1469.  
  1470. -- draw in 3d
  1471.  
  1472. function drawcirc(x, y, z, r, c, fill)
  1473. if (z<0) return
  1474. local ok=ztoscalar(z)
  1475. local cue={xcoord(x,ok), ycoord(y,ok), getscale(r,ok), c}
  1476. cue.z=z
  1477. cue.type=1
  1478. if fill then
  1479. cue.type=2
  1480. end
  1481. add(todraw,cue)
  1482. end
  1483.  
  1484. --cue scaled sprite
  1485. function drawsspr(i,shadow, flash)--i must have parameters: sprx, spry, x, y, z, w, h, scl
  1486. if (i.z<0) return
  1487. local ok=ztoscalar(i.z)
  1488. local scaleo=getscale(i.scl,ok)
  1489. local scalw=ceil(scaleo*i.w)
  1490. local scalh=ceil(scaleo*i.h)
  1491. local xcrd=xcoord(i.x,ok)
  1492. local ycrd=ycoord(i.y,ok)
  1493. local cue={i.sprx, i.spry, i.w, i.h, xcrd-0.5*scalw, ycrd-0.5*scalh, scalw, scalh, i.flip, flash}
  1494. cue.type=0
  1495. cue.z=i.z
  1496. add(todraw,cue)
  1497. if shadow and i.z<80 then
  1498. local shadowy=ycoord(0,ok)
  1499. mcircfill(xcrd,shadowy,scalw*0.2,3)
  1500. end
  1501. end
  1502.  
  1503. --cue unscaled sprite (don't use for colliders)
  1504. function drawspr(sp,x,y,z,w,h,shadow, flash)--w and h are in sprites
  1505. if (z<0) return
  1506. local ok=ztoscalar(z)
  1507. local xcrd=xcoord(x,ok)
  1508. local ycrd=ycoord(y,ok)
  1509. local cue={sp, xcrd-w*4, ycrd-h*4, w, h, flash}
  1510. cue.type=4
  1511. cue.z=z
  1512. add(todraw,cue)
  1513. if shadow and z<80 then
  1514. local shadowy=ycoord(0,ok)
  1515. mcircfill(xcrd,shadowy,w*3,3)
  1516. end
  1517. end
  1518.  
  1519. function drawcross(x,y,z,r,ang,c)
  1520. if (z<0) return
  1521. local ok=ztoscalar(z)
  1522. local ctrx=xcoord(x,ok)
  1523. local ctry=ycoord(y,ok)
  1524. cue={ctrx,ctry,r,ang,c}
  1525. cue.z=z
  1526. cue.type=3
  1527. add(todraw,cue)
  1528. end
  1529.  
  1530. function dcross(x,y,r,a,c)
  1531. pset(x,y,11)
  1532. local cosa=cos(a)
  1533. local sina=sin(a)
  1534. line( x-cosa*r, y-sina*r, x+cosa*r, y+sina*r, c)
  1535. line( x-sina*r, y+cosa*r, x+sina*r, y-cosa*r, c)
  1536. end
  1537.  
  1538. function drawtodraw(i)
  1539. if i.type==0 then
  1540. if i[10] then pal(3,0) pal(8,3) end
  1541. sspr(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9])
  1542. if i[10] then pal(3,3) pal(8,8) end
  1543. elseif i.type==1 then
  1544. mcirc(i[1],i[2],i[3],i[4])
  1545. elseif i.type==2 then
  1546. mcircfill(i[1],i[2],i[3],i[4])
  1547. elseif i.type==3 then
  1548. dcross(i[1],i[2],i[3],i[4],i[5])
  1549. elseif i.type==4 then
  1550. if(i[6]) then pal(8,3) end
  1551. spr(i[1], i[2], i[3], i[4], i[5])
  1552. if(i[6]) then pal(8,8) end
  1553. end
  1554.  
  1555. end
  1556.  
  1557. function zsort(data)
  1558. local n=#data
  1559. if (n<2)return
  1560. for i=flr(n/2)+1,1,-1 do
  1561. local parent,value,m=i,data[i],i+i
  1562. local key=-value.z
  1563.  
  1564. while m<=n do
  1565. --find the max child
  1566. if ((m<n) and (-data[m+1].z > -data[m].z)) m+=1
  1567. local mval=data[m]
  1568. if (key > -mval.z) break
  1569. data[parent] = mval
  1570. parent=m
  1571. m+=m
  1572. end
  1573. data[parent] = value
  1574. end
  1575. --read out values
  1576. for i=n, 2, -1 do
  1577. --swap root w last
  1578. local value = data[i]
  1579. data[i], data[1] = data[1], value
  1580. --restore the heap
  1581. local parent,term,m= 1,i-1,2
  1582. local key=-value.z
  1583.  
  1584. while m <= term do
  1585. local mval=data[m]
  1586. local mkey=-mval.z
  1587. if m<term and -data[m+1].z>mkey then
  1588. m+=1
  1589. mval=data[m]
  1590. mkey=-mval.z
  1591. end
  1592. if(key>mkey) break
  1593. data[parent]=mval
  1594. parent=m
  1595. m+=m
  1596. end
  1597. data[parent]=value
  1598. end
  1599. end
  1600.  
  1601. --------helpers--------------------------------
  1602.  
  1603. function checkcol(a,b)--a and b are tables with x,y,z,w,h,scl values
  1604. local w=(a.w*a.scl+b.w*b.scl)*0.5
  1605. local h=(a.h*a.scl+b.h*b.scl)*0.5
  1606. if abs(a.x-b.x)<w and abs(a.y-b.y)<h and abs(a.z-b.z)<1 then
  1607. return true
  1608. end
  1609. return false
  1610. end
  1611.  
  1612. function xcoord(x,z)
  1613. return lerp(x*1.886,0,z)+64
  1614. end
  1615.  
  1616. function ycoord(y,z)
  1617. return lerp((96-y)*1.886,20,z)
  1618. end
  1619.  
  1620. function getscale(r,z)
  1621. return max(0,(1-z)*r*1.886)
  1622. end
  1623.  
  1624. function ztoscalar(z)
  1625. return sqrt(sqrt(z*0.01))
  1626. end
  1627.  
  1628. function color(i)
  1629. if i<1 then return 0 end
  1630. if i<2 then return 3 end
  1631. return 8
  1632. end
  1633.  
  1634. function lerp(la,lb,li)
  1635. return la+li*(lb-la)
  1636. end
  1637.  
  1638. function ceil(num)
  1639. return flr(num+0x0.ffff)
  1640. end
  1641.  
  1642. function round(num)
  1643. return flr(num+0.5)
  1644. end
  1645.  
  1646. function tostring(n)
  1647. return ""..n
  1648. end
  1649.  
  1650. function xpressed()
  1651. if btn(5) and xdown==false then
  1652. return true
  1653. end
  1654. return false
  1655. end
  1656.  
  1657. function zpressed()
  1658. if btn(4) and zdown==false then
  1659. return true
  1660. end
  1661. return false
  1662. end
  1663.  
  1664. --minskycricle by@musurca, @felice, and @ultrabrite
  1665. function mcirc(x,y,r,c)
  1666. x,y=x+0.5,y+0.5
  1667. local j,k,rat=r,0,1/r
  1668. poke(0x5f25,c) --set color
  1669. for i=1,0.785*r do
  1670. k-=rat*j
  1671. j+=rat*k
  1672. pset(x+j,y+k)
  1673. pset(x+j,y-k)
  1674. pset(x-j,y+k)
  1675. pset(x-j,y-k)
  1676. pset(x+k,y+j)
  1677. pset(x+k,y-j)
  1678. pset(x-k,y+j)
  1679. pset(x-k,y-j)
  1680. end
  1681. pset(x,y-r)
  1682. pset(x,y+r)
  1683. pset(x-r,y)
  1684. pset(x+r,y)
  1685. end
  1686.  
  1687. function mcircfill(x,y,r,c)
  1688. x,y=x+0.5,y+0.5
  1689. local j,k,rat=r,0,1/r
  1690. poke(0x5f25,c) --set color
  1691. for i=1,r*0.786 do
  1692. k-=rat*j
  1693. j+=rat*k
  1694. rectfill(x+k,y+k,x+j,y-k)
  1695. rectfill(x-k,y+k,x-j,y-k)
  1696. rectfill(x-k,y-j,x-k,y+j)
  1697. rectfill(x+k,y-j,x+k,y+j)
  1698.  
  1699.  
  1700. --rectfill(x+j,y+k,x+j,y-k)
  1701. --rectfill(x-j,y+k,x-j,y-k)
  1702. --rectfill(x-k,y-j,x-k,y+j)
  1703. --rectfill(x+k,y-j,x+k,y+j)
  1704. end
  1705. rectfill(x,y-flr(r),x,y+flr(r))--flooring these values reduces ugly 3-vertical-pixel "circles", but causes uneven edges
  1706. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement