alter-ego-by-kyuchumimo.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. -- title: Alter Ego (WIP)
  2. -- author: ORIGINAL ZX SPECTRUM GAME BY DENIS GRACHEV
  3. -- NES CONVERSION BY SHIRU
  4. -- NES MUSIC BY RICHARD "KULOR" ARMIJO
  5. -- TIC-80 CONVERSION BY KYUCHUMIMO AND PIXELBATH
  6. -- desc: My first TIC-80 program
  7. --WARNING: Saved on TIC-80 0.80.xxxx beta. Music doesn't work on previous versions.
  8. --CHANGELOG:
  9. --201120 - pixelbath joined the project. Code optimization: 26473 to 21757 bytes. Changelog moved to tic80.com/play?cart=1420
  10. --INFO:
  11. --https://tic80.com/play?cart=1420
  12. --https://www.youtube.com/watch?v=O3uOHAvlsN8
  13. --http://www.retrosouls.net/?page_id=614
  14. -- script: lua
  15. --VARIABLES
  16. --climb
  17. c=0
  18. --sprite flip
  19. f=0
  20. --lives
  21. l=5
  22. --LEVEL (DEFAULT=0)
  23. m=0
  24. --pixels (KEEP AWAY FROM 0)
  25. px=0
  26. aepx=0
  27. --swap
  28. s=0
  29. --EVENT TIMER
  30. et=nil
  31. --GLOBAL TIMER
  32. t=0
  33. --bridge animation trigger
  34. btrig=0
  35. --FALL TRIGGER
  36. ftrig=0
  37. --PAUSE TRIGGER
  38. ptrig=0
  39. --SWAP TRIGGER
  40. strig=0
  41. --ALTER EGO mirroring (0=H,1=V)
  42. aeo=0
  43. --HERO animation ticks
  44. anix=0
  45. aniy=0
  46. --HERO X position
  47. animx=0
  48. --HERO Y position
  49. animy=0
  50. --ALTER EGO X position
  51. aex=0
  52. --ALTER EGO Y position
  53. aey=0
  54. --palette RGB value
  55. v=0
  56. options = {
  57. music = true,
  58. debug = true,
  59. }
  60. cls()
  61. map()
  62. --PALETTE STUFF
  63. local basepalette = {
  64. 0x1a1c2c, 0x29366f, 0x3b5dc9, 0x493c2b, 0x5d275d, 0x38b764, 0xb13e53, 0x333c57, 0x41a6f6, 0xef7d57, 0x94b0c2, 0xa7f070, 0xe06f8b, 0x73eff7, 0xffcd75, 0xf4f4f4
  65. }
  66. function pal(v)
  67. for i = 1, #basepalette do
  68. local offset, color = i-1, basepalette[i]
  69. poke(0x3fc0+(offset*3), ((color//65536) * v))
  70. poke(0x3fc1+(offset*3), ((color//256)%256) * v)
  71. poke(0x3fc2+(offset*3), (color%256) * v)
  72. end
  73. end
  74. function fade_out(et)
  75. if t==(et+(2.1*60)) then
  76. if mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8)==6 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==151 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==152 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==153 then music() end
  77. return pal(1)
  78. end
  79. if t==(et+(2.2*60)) then return pal(0.75) end
  80. if t==(et+(2.3*60)) then return pal(0.5) end
  81. if t==(et+(2.4*60)) then return pal(0.25) end
  82. if t==(et+(2.5*60)) then return pal(0) end
  83. end
  84. function fade_in(et)
  85. if t==(et+(0*60)+1) then return pal(0) end
  86. if t==(et+(0.1*60)) then return pal(0.25) end
  87. if t==(et+(0.2*60)) then return pal(0.5) end
  88. if t==(et+(0.3*60)) then return pal(0.75) end
  89. if t==(et+(0.4*60)) then return pal(1) end
  90. end
  91. -- PARTICLE/VFX STUFF
  92. waterlevel = 120 -- y coordinate of the water
  93. particletype='rain' -- snow|rain|stars
  94. particles = {}
  95. local starcolors = { 1, 2, 13, 15}
  96. function particleinit(numparticles)
  97. if particletype == 'stars' then
  98. for i = 0, numparticles do
  99. table.insert(particles, {
  100. x = math.random() * 240,
  101. y = math.random() * waterlevel,
  102. twinkle = math.random() > 0.49, -- randomly pick true/false
  103. color = starcolors[math.random(#starcolors)],
  104. t = 0,
  105. })
  106. end
  107. end
  108. if particletype == 'rain' or particletype == 'snow' then
  109. for i = 0, numparticles do
  110. color = 2
  111. if particletype == 'snow' then color=15 end
  112. table.insert(particles, {
  113. x = math.random() * 240,
  114. y = math.random() * waterlevel,
  115. lastx = 0,
  116. lasty = -3,
  117. color = 2,
  118. t = 0,
  119. vel = (math.random() * 3) + 1,
  120. })
  121. end
  122. end
  123. end
  124. function particleupdate()
  125. if particletype == 'stars' then
  126. for i = 1,#particles do
  127. local p = particles[i]
  128. if not p.twinkle then goto continueTwinkle end
  129. ::continueTwinkle::
  130. if t % 15 == 0 and math.random() > 0.1 then
  131. p.color = starcolors[math.random(#starcolors)]
  132. end
  133. end
  134. end
  135. if particletype == 'rain' then
  136. for i = 1,#particles do
  137. local p = particles[i]
  138. if p.lasty and p.lasty > 136 then
  139. p.y = 0
  140. p.lasty = 0
  141. p.x = math.random() * 240
  142. end
  143. p.lasty = p.y
  144. p.lastx = p.x
  145. p.y = p.y + p.vel
  146. end
  147. end
  148. end
  149. function particledraw()
  150. if (particletype == 'rain') then
  151. for i = 1,#particles do
  152. local p = particles[i]
  153. line(p.x, p.y, p.lastx, p.lasty, color)
  154. end
  155. return
  156. end
  157. for i = 1,#particles do
  158. local p = particles[i]
  159. pix(p.x, p.y, p.color)
  160. end
  161. end
  162. particleinit(150)
  163. --(shx: Xpos, shy: Ypos, shf: flip, sht: timer) CHECK THIS
  164. function skullh(shx,shy,shf,sht)
  165. --local shx
  166. --local shy
  167. --local sht
  168. --local shf
  169. if mget((30*m%240)+((shx-8)//8),(17*(m//8))+((shy+8)//8))==0 or mget((30*m%240)+((shx+8)//8),(17*(m//8))+((shy+8)//8))==0 then
  170. if shf==0 then shf=1 else shf=0 end
  171. --sht=0
  172. spr(288+t%16//4,(shx*8)+(sht//8),(shy*8),0,1,shf,0,1,2)
  173. else
  174. --sht=sht+1
  175. spr(288+t%16//4,(shx*8)-(sht//8),(shy*8),0,1,shf,0,1,2)
  176. end
  177. if (animx*8+(anix//10))==shx*8 and ((animy*8+(aniy//10))+8)==(shy*8)+8 then
  178. ftrig=0
  179. l=l-1
  180. sfx(56,45,-2,0)
  181. t=0
  182. level(m)
  183. end
  184. --SCREEN SKULL SPR POSITION DEBUG
  185. --print(shx*8,22,24)
  186. --print((shy*8)+8,22,30)
  187. end
  188. --LEVEL PROPERTIES (ANIMX/Y LIMITS(1-28,1-14))
  189. function level(m)
  190. c=0
  191. f=0
  192. px=nil
  193. aepx=nil
  194. anix=0
  195. aniy=0
  196. et=-255
  197. strig=0
  198. ftrig=0
  199. --HELLO WORLD
  200. if m==2 then
  201. t=0
  202. s=2
  203. px=3
  204. aepx=0
  205. aeo=0
  206. animx=21
  207. animy=3
  208. end
  209. --PROMENADE
  210. if m==3 then
  211. s=2
  212. px=8
  213. aepx=0
  214. aeo=0
  215. animx=5
  216. animy=3
  217. end
  218. --BROKEN BRIDGE
  219. if m==4 then
  220. s=0
  221. px=8
  222. aepx=0
  223. aeo=0
  224. animx=11
  225. animy=8
  226. end
  227. --PHANTOM PIXELS
  228. if m==5 then
  229. s=3
  230. px=2
  231. aepx=4
  232. aeo=0
  233. animx=14
  234. animy=3
  235. end
  236. --ANOTHER PHANTOM
  237. if m==6 then
  238. s=4
  239. px=13
  240. aepx=0
  241. aeo=1
  242. animx=3
  243. animy=10
  244. end
  245. --SKULLS LAIR
  246. if m==7 then
  247. s=2
  248. px=14
  249. aepx=0
  250. aeo=0
  251. animx=17
  252. animy=13
  253. end
  254. --ABRACADABRA
  255. if m==8 then
  256. s=2
  257. px=6
  258. aepx=6
  259. aeo=0
  260. animx=9
  261. animy=10
  262. end
  263. --VERTICAL ILLUTIONS
  264. if m==9 then
  265. s=8
  266. px=10
  267. aepx=0
  268. aeo=1
  269. animx=4
  270. animy=9
  271. end
  272. --MIRRORS
  273. if m==10 then
  274. s=2
  275. px=4
  276. aepx=3
  277. aeo=0
  278. animx=26
  279. animy=11
  280. end
  281. --16 PIXELS
  282. if m==11 then
  283. s=4
  284. px=16
  285. aepx=0
  286. aeo=0
  287. animx=5
  288. animy=9
  289. end
  290. --PERFECT REFLECT
  291. if m==12 then
  292. t=0
  293. s=1
  294. px=16
  295. aepx=0
  296. aeo=0
  297. animx=15
  298. animy=10
  299. end
  300. --ICELANDS
  301. if m==13 then
  302. s=3
  303. px=5
  304. aepx=3
  305. aeo=0
  306. animx=15
  307. animy=9
  308. end
  309. --MIDNIGHT
  310. if m==14 then
  311. s=2
  312. px=5
  313. aepx=0
  314. aeo=0
  315. animx=23
  316. animy=12
  317. end
  318. --ALONE SKULL
  319. if m==15 then
  320. s=3
  321. px=3
  322. aepx=2
  323. aeo=0
  324. animx=15
  325. animy=2
  326. end
  327. --MADE IN HEAVEN
  328. if m==16 then
  329. s=5
  330. px=9
  331. aepx=6
  332. aeo=1
  333. animx=4
  334. animy=4
  335. end
  336. --UNDERWATER
  337. if m==17 then
  338. s=2
  339. px=3
  340. aepx=5
  341. aeo=0
  342. animx=2
  343. animy=9
  344. end
  345. --ZUPAPIXELS
  346. if m==18 then
  347. s=9
  348. px=8
  349. aepx=1
  350. aeo=0
  351. animx=3
  352. animy=2
  353. end
  354. --SKULLOPEDIA
  355. if m==19 then
  356. s=4
  357. px=12
  358. aepx=0
  359. aeo=0
  360. animx=7
  361. animy=12
  362. end
  363. --AFTER THE WAR
  364. if m==20 then
  365. s=3
  366. px=8
  367. aepx=0
  368. aeo=1
  369. animx=3
  370. animy=2
  371. end
  372. --VIRUS KVARTIRUS
  373. if m==21 then
  374. s=6
  375. px=11
  376. aepx=0
  377. aeo=0
  378. animx=24
  379. animy=13
  380. end
  381. --END
  382. if m==22 then
  383. t=0
  384. l=143
  385. s=143
  386. px=-255
  387. aepx=-255
  388. aeo=0
  389. animx=-1
  390. animy=-2
  391. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8),1)
  392. mset(((30*m%240)+(animx*8+(anix//10))//8)-1,(17*(m//8))+((animy*8+(aniy//10))//8)+1,1)
  393. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,1)
  394. mset(((30*m%240)+(animx*8+(anix//10))//8)+1,(17*(m//8))+((animy*8+(aniy//10))//8)+1,1)
  395. end
  396. end
  397. level(m)
  398. function TIC()
  399. --MUSIC (For loop use t%(spd*rows*#patterns used)==0)
  400. if options.music then
  401. --TITLE SCREEN
  402. if m==1 and t==0 then music(0,-1,-1,false) end
  403. --LEVELS 1-10
  404. if m>=2 and m<=11 and t==0 then music(1,-1,-1,false) end
  405. --LEVELS 11-21
  406. if m>=12 and m<=21 and t==0 then music(2,-1,-1,false) end
  407. --LEVELS 21-???
  408. if m>=22 and t==0 then music(3) end
  409. end
  410. --TIMER
  411. if ptrig==0 then t=t+1 end
  412. --CREDITS
  413. if m==0 then
  414. map(0,0,30,17)
  415. if options.debug then
  416. print(t,0,0,15,true,1,true)
  417. print(et,0,6,15,true,1,true)
  418. end
  419. fade_in(0)
  420. if t==(3*60) or keyp(50) then
  421. et=t
  422. t=180
  423. end
  424. if t>(et+(3*60)) and et>=0 then
  425. m=m+1
  426. t=0
  427. et=-255
  428. else
  429. fade_out(et)
  430. return
  431. end
  432. end
  433. --TITLE SCREEN
  434. if m==1 then
  435. l=5
  436. --REMAP
  437. cls()
  438. particleupdate()
  439. particledraw()
  440. map(30*m%270,17*((m-1)//8),30,17,0,0,0,1)
  441. fade_in(0)
  442. if t<0.4*60 then return end
  443. if options.debug then
  444. print("DEBUG: Press X/A and Y/S to switch levels",8,131)
  445. print(et,0,0,15,true,1,true)
  446. end
  447. if keyp(50) and et<=0 then
  448. music()
  449. sfx(51,43,-1,0,15)
  450. et=t
  451. end
  452. if t>(et+(3*60)) and et>=0 then
  453. m=m+1
  454. level(m)
  455. else
  456. fade_out(et)
  457. return
  458. end
  459. end
  460. --LEVEL DISPLAY
  461. if m>1 then
  462. fade_in(0)
  463. --REMAP
  464. cls()
  465. particleupdate()
  466. particledraw()
  467. map(30*m%240,17*(m//8),30,17,0,0,0,1,
  468. function(tile)
  469. if tile>=80 and tile<=111 and anix==0 and aniy==0 and px==0 and aepx==0 then
  470. return tile*(t%38//19)
  471. end
  472. if tile==6 or tile==22 or tile==38 or tile==54 or tile==8 or tile==24 then
  473. return tile+(t%38//19)
  474. else
  475. if tile~=6 and tile~=22 and tile~=38 and tile~=54 and tile~=8 and tile~=24 and not (tile>=64 and tile<=79) then return tile end
  476. end
  477. end
  478. )
  479. --PIXELS DISPLAY
  480. map(30*m%240,17*(m//8),30,17,0,0,0,1,
  481. function(tile)
  482. if tile==64 or tile==72 then
  483. print(t%20//2.5, 2, 120)
  484. return tile+(t%20//2.5)
  485. end
  486. if tile==65 or tile==73 then
  487. return tile+(((t+2.5)%20//2.5)-1)
  488. end
  489. if tile==66 or tile==74 then
  490. return tile+(((t+5)%20//2.5)-2)
  491. end
  492. if tile==67 or tile==75 then
  493. return tile+(((t+7.5)%20//2.5)-3)
  494. end
  495. if tile==68 or tile==76 then
  496. return tile+(((t+10)%20//2.5)-4)
  497. end
  498. if tile==69 or tile==77 then
  499. return tile+(((t+12.5)%20//2.5)-5)
  500. end
  501. if tile==70 or tile==78 then
  502. return tile+(((t+15)%20//2.5)-6)
  503. end
  504. if tile==71 or tile==79 then
  505. return tile+(((t+17.5)%20//2.5)-7)
  506. end
  507. end
  508. )
  509. --SKULLH LIMITS(1-28,1-14)
  510. --skullh(12,10,0,0)
  511. --if btn(5) then skullh(25,3,0,0) end
  512. --skullh(20,6,0,0)
  513. --LEVEL CLEAR
  514. if px==0 and aepx==0 and anix==0 and aniy==0 then
  515. if et<0 then
  516. sfx(52,36,90,0)
  517. for i=0,29 do
  518. mset((30*m%240)+i,(17*(m//8)),0)
  519. end
  520. mset((30*m%240)+10,(17*(m//8)),91)
  521. mset((30*m%240)+11,(17*(m//8)),84)
  522. mset((30*m%240)+12,(17*(m//8)),101)
  523. mset((30*m%240)+13,(17*(m//8)),84)
  524. mset((30*m%240)+14,(17*(m//8)),91)
  525. mset((30*m%240)+16,(17*(m//8)),82)
  526. mset((30*m%240)+17,(17*(m//8)),91)
  527. mset((30*m%240)+18,(17*(m//8)),84)
  528. mset((30*m%240)+19,(17*(m//8)),80)
  529. mset((30*m%240)+20,(17*(m//8)),97)
  530. et=t
  531. end
  532. if et>0 then
  533. spr(257+(f*3),animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  534. spr(265,aex,aey,0,1,0,0,1,2)
  535. fade_out(et)
  536. end
  537. if t<et+(3*60) then
  538. return end
  539. m=m+1
  540. t=1
  541. level(m)
  542. end
  543. --STATUS DISPLAY
  544. mset((30*m%240)+3,(17*(m//8)),112+l)
  545. mset((30*m%240)+7,(17*(m//8)),112+s)
  546. end
  547. --GAME OVER
  548. if l==0 then
  549. map(210,119,30,17)
  550. sfx(-1,-1,-1,0)
  551. sfx(-1,-1,-1,1)
  552. sfx(-1,-1,-1,2)
  553. sfx(-1,-1,-1,3)
  554. if t==1 then
  555. music(6,-1,-1,false)
  556. end
  557. fade_in(0)
  558. if t<8*60 then
  559. return
  560. end
  561. m=1
  562. level()
  563. t=0
  564. end
  565. --DEATH
  566. if mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8)==6 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==151 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==152 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==153 then
  567. if et<0 then
  568. sfx(56,45,-2,0)
  569. sfx(60,45,-2,1)
  570. et=t
  571. end
  572. if et>0 then
  573. spr(331+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  574. spr(329+t%8//4,aex,aey,0,1,0,0,1,2)
  575. fade_out(et)
  576. end
  577. if t<et+(3*60) then
  578. return end
  579. ftrig=0
  580. l=l-1
  581. t=0
  582. level(m)
  583. end
  584. --FALL
  585. if not ((mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==1 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==2 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==17 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==18 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==10 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==11 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==26 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==27 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==5 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==37 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==48 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==49 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==16 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==32 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==5 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==37) and anix==0 and aniy==0 and strig==0 then
  586. if ftrig==0 and l>0 then sfx(57,82,-1,0) end
  587. ftrig=1
  588. animy=animy+1
  589. aniy=-80
  590. spr(263+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  591. end
  592. --NOTHING
  593. if anix==0 and aniy==0 and t>(2*60) then
  594. if ftrig==1 and strig==0 then sfx(58,24,-1,0) end
  595. if strig==0 then
  596. spr(256+c,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  597. else
  598. spr(301+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  599. end
  600. ftrig=0
  601. btrig=0
  602. end
  603. if t<(2*60) then
  604. spr((256+c)+((t%20//10)*15),animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  605. end
  606. if m>1 then
  607. --CONTROLS, COLLISION and SFX
  608. --UP(0),DOWN(1),LEFT(2),RIGHT(3)
  609. if strig==0 and t>(2*60) and ptrig==0 then
  610. if btn(0) and (mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10))//8)==5 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10))//8)==37) and anix==0 and aniy==0 then
  611. ftrig=0
  612. sfx(63,84,-1,3)
  613. animy=animy-1
  614. aniy=80
  615. end
  616. if btn(1) and (mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==0 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==5 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==37) and anix==0 and aniy==0 then
  617. ftrig=0
  618. sfx(63,84,-1,3)
  619. animy=animy+1
  620. aniy=-80
  621. end
  622. if btn(2) and anix==0 and aniy==0 and not ((mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==1 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==2 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==17 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==18 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==10 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==11 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==26 or (mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==27) then
  623. ftrig=0
  624. --BRIDGE
  625. if mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==48 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==49 then
  626. sfx(61,0,-1,3)
  627. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,0)
  628. btrig=1
  629. else
  630. sfx(62,0,-1,3)
  631. end
  632. animx=animx-1
  633. anix=80
  634. end
  635. if btn(3) and anix==0 and aniy==0 and not ((mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==1 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==2 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==17 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==18 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==10 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==11 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==26 or (mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8))==27) then
  636. ftrig=0
  637. --BRIDGE
  638. if mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==48 or mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8)==49 then
  639. sfx(61,0,-1,3)
  640. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,0)
  641. btrig=1
  642. else
  643. sfx(62,0,-1,3)
  644. end
  645. animx=animx+1
  646. anix=-80
  647. end
  648. --A/Z(4),B/X(5),X/A(6),Y/S(7)
  649. if (btnp(4) or btnp(5)) and m>=2 then
  650. if s>0 and not (mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==1 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==2 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==16 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==17 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==18 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==10 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==11 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==26 or mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))==27) then
  651. sfx(53,72,-1,3)
  652. s=s-1
  653. strig=1
  654. else
  655. if s==0 then
  656. sfx(55,31,-1,2)
  657. else
  658. sfx(59,60,-1,3)
  659. end
  660. end
  661. end
  662. if btnp(6) and m<=21 then
  663. m=m+1
  664. level(m)
  665. end
  666. if btnp(7) and m>=3 and m<=21 then
  667. m=m-1
  668. level(m)
  669. end
  670. end
  671. if t>=2*60 then
  672. if keyp(50) then
  673. if ptrig==0 then
  674. sfx(51,43,-1,0,15)
  675. ptrig=1
  676. pal(0.5)
  677. must=peek(0x13ffc)
  678. musf=peek(0x13ffd)
  679. musr=peek(0x13ffe)
  680. musl=peek(0x13fff)
  681. music()
  682. else
  683. sfx(51,43,-1,0,15)
  684. ptrig=0
  685. pal(1)
  686. music(must,musf,musr,musl)
  687. end
  688. end
  689. end
  690. --MOVEMENT PROPERTIES
  691. if strig==1 and anix==0 and aniy==0 then
  692. if aeo==0 then strig=(aex)-(animx*8+(anix//10)) end
  693. if aeo==1 then strig=(aey)-(animy*8+(aniy//10)) end
  694. end
  695. if strig~=1 then
  696. if strig<0 and ptrig==0 then
  697. if aeo==0 then animx=animx-0.5 end
  698. if aeo==1 then animy=animy-0.5 end
  699. strig=strig+4
  700. end
  701. if strig>0 and ptrig==0 then
  702. if aeo==0 then animx=animx+0.5 end
  703. if aeo==1 then animy=animy+0.5 end
  704. strig=strig-4
  705. end
  706. end
  707. if anix>0 then
  708. if btrig==1 then
  709. if m<=11 then spr(48,(animx*8)+8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  710. if m>=12 then spr(49,(animx*8)+8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  711. end
  712. c=0
  713. f=0
  714. if ptrig==0 then anix=anix-8 end
  715. spr(257+t%8//2,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  716. end
  717. if anix<0 then
  718. if btrig==1 then
  719. if m<=11 then spr(48,(animx*8)-8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  720. if m>=12 then spr(49,(animx*8)-8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  721. end
  722. c=0
  723. f=1
  724. if ptrig==0 then anix=anix+8 end
  725. spr(257+t%8//2,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  726. end
  727. if aniy>0 then
  728. c=5
  729. if ptrig==0 then aniy=aniy-8 end
  730. spr(261+t%6//3,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  731. end
  732. if aniy<0 then
  733. c=5
  734. if ptrig==0 then aniy=aniy+8 end
  735. if not ((mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==1 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==2 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==17 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==18 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==10 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==11 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==26 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==27 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==5 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==37 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==48 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==49 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==16 or (mget((30*m%240)+(animx*8+(anix/10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8))==32) then
  736. spr(263+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  737. else
  738. if ftrig==1 then c=0 end
  739. spr(261+t%14//7,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  740. end
  741. end
  742. --PIXEL COLLISION
  743. if mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8)>=64 and mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8)<=71 and strig==0 then
  744. px=px-1
  745. sfx(54,72,-1,0)
  746. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+1,0)
  747. end
  748. --PHANTOM PIXEL COLLISION
  749. if mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))>=72 and mget((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8))<=79 and strig==0 then
  750. aepx=aepx-1
  751. sfx(54,69,-1,0)
  752. mset((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8),0)
  753. end
  754. --HERO DISPLAY
  755. --ALTER EGO DISPLAY
  756. if aeo==0 then
  757. --120=ZX spectrum Mirrored, 116=NES Mirrored
  758. aex=120-((animx*8+(anix//10))-120)
  759. aey=animy*8+(aniy//10)
  760. end
  761. if aeo==1 then
  762. aex=animx*8+(anix//10)
  763. aey=64-((animy*8+(aniy//10))-64)
  764. end
  765. if t>(2*60) then
  766. if strig==0 then
  767. spr(265+t%8//2,aex,aey,0,1,0,0,1,2)
  768. else
  769. spr(297+t%16//4,aex,aey,0,1,0,0,1,2)
  770. end
  771. else
  772. spr(265+((t%20//10)*6),aex,aey,0,1,0,0,1,2)
  773. end
  774. end
  775. if options.debug then
  776. print("DEBUG",0,0,15,true,1,true)
  777. --TIMER DEBUG
  778. print(t,0,6,15,true,1,true)
  779. --SWAP ACTION INPUT DEBUG
  780. if btn(4)==true or btn(5)==true then
  781. print("true",0,12,15,true,1,true)
  782. else
  783. print("false",0,12,15,true,1,true)
  784. end
  785. --MAP SCREEN DEBUG
  786. print(m,0,18,15,true,1,true)
  787. --SWAP TRIGGER DEBUG
  788. print(strig,22,18,15,true,1,true)
  789. --SCREEN HERO SPR POSITION DEBUG
  790. print((animx*8+(anix//10)),0,24,15,true,1,true)
  791. print((animy*8+(aniy//10))+8,0,30,15,true,1,true)
  792. --SCREEN ALTER EGO SPR POSITION DEBUG
  793. print(aex,22,24,15,true,1,true)
  794. print(aey+8,22,30,15,true,1,true)
  795. --MAP HERO SPR POSITION DEBUG
  796. print((30*m%240)+(animx*8+(anix//10))//8,0,42,15,true,1,true)
  797. print((17*(m//8))+((animy*8+(aniy//10))//8)+1,0,48,15,true,1,true)
  798. --MAP ALTER EGO SPR POSITION DEBUG
  799. print((30*m%240)+aex//8,22,42,15,true,1,true)
  800. print((17*(m//8))+((aey+8)//8),22,48,15,true,1,true)
  801. --MOVEMENT DEBUG
  802. print(anix//10,0,60,15,true,1,true)
  803. print(aniy//10,0,66,15,true,1,true)
  804. --PIXEL AND PHANTOM PIXEL DEBUG
  805. print(px,22,60,15,true,1,true)
  806. print(aepx,22,66,15,true,1,true)
  807. --MGET DEBUG
  808. print(mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10))//8),22,78,15,true,1,true)
  809. print(mget((30*m%240)+(animx*8+(anix//10)-8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8),0,84,15,true,1,true)
  810. print(mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8),22,84,15,true,1,true)
  811. print(mget((30*m%240)+(animx*8+(anix//10)+8)//8,(17*(m//8))+(animy*8+(aniy//10)+8)//8),44,84,15,true,1,true)
  812. print(mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10)+16)//8),22,90,15,true,1,true)
  813. --MUSIC SPEED DEBUG (0-7)
  814. --print(peek(0x13e96),0,102)
  815. --print(peek(0x13ec9),22,102)
  816. --print(peek(0x13efc),0,108)
  817. --print(peek(0x13f2f),22,108)
  818. --print(peek(0x13f62),0,114)
  819. --print(peek(0x13f95),22,114)
  820. --print(peek(0x13fc8),0,120)
  821. --print(peek(0x13ffb),22,120)
  822. --MUSIC POSITION DEBUG
  823. print("track:",44,102,15,true,1,true)
  824. print(peek(0x13ffc),88,102,15,true,1,true)
  825. print("frame:",44,108,15,true,1,true)
  826. print(peek(0x13ffd),88,108,15,true,1,true)
  827. print("row :",44,114,15,true,1,true)
  828. print(peek(0x13ffe),88,114,15,true,1,true)
  829. print("loop :",44,120,15,true,1,true)
  830. print(peek(0x13fff),88,120,15,true,1,true)
  831. --wait: Time event (2 sec)
  832. --if t<2*60 then return end
  833. --stuff to do
  834. --spr command: spr(id+t%nf//f,x,y,z,s,f,r,w,h)
  835. --id=sprite id
  836. --t=timer
  837. --f=frames to wait for switch sprites
  838. --n=number of sprites to switch
  839. --Compare between f and n variables for speed
  840. --x=x position
  841. --y=y position
  842. --z=colorkey id to set alpha
  843. --s=scale
  844. --f=flip(Hflip(1),Vflip(2),HVflip(3))
  845. --r=rotate(90 deg(1),180 deg(2),270 deg(3))
  846. --w=width of composite sprite
  847. --h=height of composite sprite
  848. end --if options.debug
  849. --end of function TIC()
  850. end