alter-ego-by-kyuchumimo.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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
  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. --200621 - Some SPR and basic learning
  10. --200622 - Added title music, letters tileset, timming
  11. --200623 - Added mget command for collision proposes and poke() functions for change palette and create fade effect alike NES
  12. --200624 - Added Horizontal and Vertical Alter ego sprite mirroring, SFX and 8x8 movement
  13. --200625 - Added more tilesets, level HELLO WORLD and future levels rearranged based on ZX spectrum version
  14. --200626 - Added Levels 2 to 9 and Remap function for animate tiles
  15. --200627 - Added new formulas for X maps and stairs and blocks collision
  16. --200630 - Added new formulas for Y maps, fall instrucction and sfx, animation and movement speed accurancy
  17. --200701 - Added more level properties, climb movements and arrangement of debug data
  18. --200702 - Added cover art for testing
  19. --200703 - Added a definitive and noiseless cover art
  20. --200804 - Added mset command for switch tiles (e.g. Bridges)
  21. --200807 - Added music more accurated from source, instruments and music loops. Number of patern tables reduced to most minimum (7 saved).
  22. --200808 - Added Sync command to restore tilemap. More variables for control, timing accurancy and small optimizations on code. Game over screen and music. Keyp command
  23. --200820 - Added death proerties, sfx, level 3 music and music loop accurancy with formulas. Music command correction.
  24. --200921 - Added both Pixel and phantom pixel collision, animation and sfx. Improved slide SFX and functional Game Over screen
  25. --200923 - Palette values and address changed to hexadecimal. Code optimization and fixes on collisions and fall conditions (Size from 19618 bytes to 17506 bytes), bridge falling animation (fix later: overlay on frame)
  26. --200924 - Bridge sprite set colorkey for alpha transparency, small fixes. Functional swap abillity for horizontal mirror added (With some unexpected bugs)
  27. --200925 - Some transitions and timming added
  28. --200928 - Vertical mirroring swap abillity added, more transitions and timming, some small changes or fixes.
  29. --201101 - Added 6 levels more. Now you can press either A or B to swap between Alter Ego and Hero
  30. --201105 - Added an unused music, there will be no more music due to limitations in the RAM size of music patterns on TIC-80. Minor additions
  31. --201106 - Cover art updated to a better version. Now you will no longer be able to exchange places with Alter Ego if it is positioned on a block or platform. Added sound effects related to swapping
  32. --201108 - Now each pixel has its own animation set and pixel animation timming accurancy
  33. --201110 - 14 of 16 colors in the color palette updated to Sweetie 16 by GrafxKid palette for more consistency with TIC-80. Debug text thinner. Status are now displayed by tiles instead of sprites. Level clear message added at the end of every level
  34. --201111 - Added pause function, new music respawn method. More additions. Bug fix: Freeze at swapping action bug fixed.
  35. --201112 - Bug fix: Hero was not displayed when he was moving and the game was paused.
  36. --201116 - Some transitions and Jxx command used as a loop for music
  37. --INFO:
  38. --https://tic80.com/play?cart=1420
  39. --https://www.youtube.com/watch?v=O3uOHAvlsN8
  40. --http://www.retrosouls.net/?page_id=614
  41. -- script: lua
  42. --VARIABLES
  43. --climb
  44. c=0
  45. --sprite flip
  46. f=0
  47. --lives
  48. l=5
  49. --LEVEL (DEFAULT=0)
  50. m=0
  51. --pixels (KEEP AWAY FROM 0)
  52. px=0
  53. aepx=0
  54. --swap
  55. s=0
  56. --EVENT TIMER
  57. et=nil
  58. --GLOBAL TIMER
  59. t=0
  60. --bridge animation trigger
  61. btrig=0
  62. --FALL TRIGGER
  63. ftrig=0
  64. --PAUSE TRIGGER
  65. ptrig=0
  66. --SWAP TRIGGER
  67. strig=0
  68. --ALTER EGO mirroring (0=H,1=V)
  69. aeo=0
  70. --HERO animation ticks
  71. anix=0
  72. aniy=0
  73. --HERO X position
  74. animx=0
  75. --HERO Y position
  76. animy=0
  77. --ALTER EGO X position
  78. aex=0
  79. --ALTER EGO Y position
  80. aey=0
  81. --palette RGB value
  82. v=0
  83. cls()
  84. map()
  85. --PALETTE VARIABLES
  86. local basepalette = {
  87. 0x1a1c2c, 0x29366f, 0x3b5dc9, 0x493c2b, 0x5d275d, 0x38b764, 0xb13e53, 0x333c57, 0x41a6f6, 0xef7d57, 0x94b0c2, 0xa7f070, 0xe06f8b, 0x73eff7, 0xffcd75, 0xf4f4f4
  88. }
  89. function pal(v)
  90. for i = 1, #basepalette do
  91. local offset, color = i-1, basepalette[i]
  92. poke(0x3fc0+(offset*3), ((color//65536) * v))
  93. poke(0x3fc1+(offset*3), ((color//256)%256) * v)
  94. poke(0x3fc2+(offset*3), (color%256) * v)
  95. end
  96. end
  97. function fade_out(et)
  98. if t==(et+(2.1*60)) then
  99. 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
  100. return pal(1)
  101. end
  102. if t==(et+(2.2*60)) then return pal(0.75) end
  103. if t==(et+(2.3*60)) then return pal(0.5) end
  104. if t==(et+(2.4*60)) then return pal(0.25) end
  105. if t==(et+(2.5*60)) then return pal(0) end
  106. end
  107. function fade_in(et)
  108. if t==(et+(0*60)+1) then return pal(0) end
  109. if t==(et+(0.1*60)) then return pal(0.25) end
  110. if t==(et+(0.2*60)) then return pal(0.5) end
  111. if t==(et+(0.3*60)) then return pal(0.75) end
  112. if t==(et+(0.4*60)) then return pal(1) end
  113. end
  114. --(shx: Xpos, shy: Ypos, shf: flip, sht: timer) CHECK THIS
  115. function skullh(shx,shy,shf,sht)
  116. --local shx
  117. --local shy
  118. --local sht
  119. --local shf
  120. 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
  121. if shf==0 then shf=1 else shf=0 end
  122. --sht=0
  123. spr(288+t%16//4,(shx*8)+(sht//8),(shy*8),0,1,shf,0,1,2)
  124. else
  125. --sht=sht+1
  126. spr(288+t%16//4,(shx*8)-(sht//8),(shy*8),0,1,shf,0,1,2)
  127. end
  128. if (animx*8+(anix//10))==shx*8 and ((animy*8+(aniy//10))+8)==(shy*8)+8 then
  129. ftrig=0
  130. l=l-1
  131. sfx(56,45,-2,0)
  132. t=0
  133. level(m)
  134. end
  135. --SCREEN SKULL SPR POSITION DEBUG
  136. --print(shx*8,22,24)
  137. --print((shy*8)+8,22,30)
  138. end
  139. --LEVEL PROPERTIES (ANIMX/Y LIMITS(1-28,1-14))
  140. function level(m)
  141. sync(0,0,false)
  142. c=0
  143. f=0
  144. px=nil
  145. aepx=nil
  146. anix=0
  147. aniy=0
  148. et=-255
  149. strig=0
  150. ftrig=0
  151. --HELLO WORLD
  152. if m==2 then
  153. t=0
  154. s=2
  155. px=3
  156. aepx=0
  157. aeo=0
  158. animx=21
  159. animy=3
  160. end
  161. --PROMENADE
  162. if m==3 then
  163. s=2
  164. px=8
  165. aepx=0
  166. aeo=0
  167. animx=5
  168. animy=3
  169. end
  170. --BROKEN BRIDGE
  171. if m==4 then
  172. s=0
  173. px=8
  174. aepx=0
  175. aeo=0
  176. animx=11
  177. animy=8
  178. end
  179. --PHANTOM PIXELS
  180. if m==5 then
  181. s=3
  182. px=2
  183. aepx=4
  184. aeo=0
  185. animx=14
  186. animy=3
  187. end
  188. --ANOTHER PHANTOM
  189. if m==6 then
  190. s=4
  191. px=13
  192. aepx=0
  193. aeo=1
  194. animx=3
  195. animy=10
  196. end
  197. --SKULLS LAIR
  198. if m==7 then
  199. s=2
  200. px=14
  201. aepx=0
  202. aeo=0
  203. animx=17
  204. animy=13
  205. end
  206. --ABRACADABRA
  207. if m==8 then
  208. s=2
  209. px=6
  210. aepx=6
  211. aeo=0
  212. animx=9
  213. animy=10
  214. end
  215. --VERTICAL ILLUTIONS
  216. if m==9 then
  217. s=8
  218. px=10
  219. aepx=0
  220. aeo=1
  221. animx=4
  222. animy=9
  223. end
  224. --MIRRORS
  225. if m==10 then
  226. s=2
  227. px=4
  228. aepx=3
  229. aeo=0
  230. animx=26
  231. animy=11
  232. end
  233. --16 PIXELS
  234. if m==11 then
  235. s=4
  236. px=16
  237. aepx=0
  238. aeo=0
  239. animx=5
  240. animy=9
  241. end
  242. --PERFECT REFLECT
  243. if m==12 then
  244. t=0
  245. s=1
  246. px=16
  247. aepx=0
  248. aeo=0
  249. animx=15
  250. animy=10
  251. end
  252. --ICELANDS
  253. if m==13 then
  254. s=3
  255. px=5
  256. aepx=3
  257. aeo=0
  258. animx=15
  259. animy=9
  260. end
  261. --MIDNIGHT
  262. if m==14 then
  263. s=2
  264. px=5
  265. aepx=0
  266. aeo=0
  267. animx=23
  268. animy=12
  269. end
  270. --ALONE SKULL
  271. if m==15 then
  272. s=3
  273. px=3
  274. aepx=2
  275. aeo=0
  276. animx=15
  277. animy=2
  278. end
  279. --MADE IN HEAVEN
  280. if m==16 then
  281. s=5
  282. px=9
  283. aepx=6
  284. aeo=1
  285. animx=4
  286. animy=4
  287. end
  288. --UNDERWATER
  289. if m==17 then
  290. s=2
  291. px=3
  292. aepx=5
  293. aeo=0
  294. animx=2
  295. animy=9
  296. end
  297. --ZUPAPIXELS
  298. if m==18 then
  299. s=9
  300. px=8
  301. aepx=1
  302. aeo=0
  303. animx=3
  304. animy=2
  305. end
  306. --SKULLOPEDIA
  307. if m==19 then
  308. s=4
  309. px=12
  310. aepx=0
  311. aeo=0
  312. animx=7
  313. animy=12
  314. end
  315. --AFTER THE WAR
  316. if m==20 then
  317. s=3
  318. px=8
  319. aepx=0
  320. aeo=1
  321. animx=3
  322. animy=2
  323. end
  324. --VIRUS KVARTIRUS
  325. if m==21 then
  326. s=6
  327. px=11
  328. aepx=0
  329. aeo=0
  330. animx=24
  331. animy=13
  332. end
  333. --END
  334. if m==22 then
  335. t=0
  336. l=143
  337. s=143
  338. px=-255
  339. aepx=-255
  340. aeo=0
  341. animx=-1
  342. animy=-2
  343. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8),1)
  344. mset(((30*m%240)+(animx*8+(anix//10))//8)-1,(17*(m//8))+((animy*8+(aniy//10))//8)+1,1)
  345. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,1)
  346. mset(((30*m%240)+(animx*8+(anix//10))//8)+1,(17*(m//8))+((animy*8+(aniy//10))//8)+1,1)
  347. end
  348. end
  349. level(m)
  350. function TIC()
  351. --MUSIC (For loop use t%(spd*rows*#patterns used)==0)
  352. --TITLE SCREEN
  353. if m==1 and t==0 then music(0,-1,-1,false) end
  354. --LEVELS 1-10
  355. if m>=2 and m<=11 and t==0 then music(1,-1,-1,false) end
  356. --LEVELS 11-21
  357. if m>=12 and m<=21 and t==0 then music(2,-1,-1,false) end
  358. --LEVELS 21-???
  359. if m>=22 and t==0 then music(3) end
  360. --TIMER
  361. if ptrig==0 then t=t+1 end
  362. --CREDITS
  363. if m==0 then
  364. --if t==(-0.3*60)+1 then return cls(10) end
  365. --if t==(-0.2*60) then return cls() end
  366. --if t==(-0.1*60) then return cls(10) end
  367. --if t<(0*60) then return end
  368. map(0,0,30,17)
  369. print(t,0,0,15,true,1,true)
  370. print(et,0,6,15,true,1,true)
  371. fade_in(0)
  372. if t==(3*60) or keyp(50) then et=t end
  373. if t>(et+(3*60)) and et>=0 then
  374. m=m+1
  375. t=0
  376. et=-255
  377. else
  378. fade_out(et)
  379. return
  380. end
  381. end
  382. --TITLE SCREEN
  383. if m==1 then
  384. l=5
  385. --REMAP
  386. cls()
  387. map(30*m%270,17*((m-1)//8),30,17,0,0,0,1,
  388. function(tile)
  389. if tile>=80 and tile<=111 and et==-255 then
  390. return tile*(t%38//19)
  391. end
  392. if tile>=80 and tile<=111 and et~=-255 then
  393. return tile*(t%10//5)
  394. end
  395. return tile
  396. end)
  397. fade_in(0)
  398. if t<0.4*60 then return end
  399. print("DEBUG: Press X/A and Y/S to switch levels",8,131)
  400. print(et,0,0,15,true,1,true)
  401. if keyp(50) and et<=0 then
  402. music()
  403. sfx(51,43,-1,0,15)
  404. et=t
  405. end
  406. if t>(et+(3*60)) and et>=0 then
  407. m=m+1
  408. level(m)
  409. else
  410. fade_out(et)
  411. return
  412. end
  413. end
  414. --LEVEL DISPLAY
  415. if m>1 then
  416. fade_in(0)
  417. --REMAP
  418. cls()
  419. map(30*m%240,17*(m//8),30,17,0,0,0,1,
  420. function(tile)
  421. if tile>=80 and tile<=111 and anix==0 and aniy==0 and px==0 and aepx==0 then
  422. return tile*(t%38//19)
  423. end
  424. if tile==6 or tile==22 or tile==38 or tile==54 or tile==8 or tile==24 then
  425. return tile+(t%38//19)
  426. else
  427. 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
  428. end
  429. end)
  430. --PIXELS DISPLAY
  431. map(30*m%240,17*(m//8),30,17,0,0,0,1,
  432. function(tile)
  433. if tile==64 or tile==72 then
  434. return tile+(t%20//2.5)
  435. end
  436. if tile==65 or tile==73 then
  437. return tile+(((t+2.5)%20//2.5)-1)
  438. end
  439. if tile==66 or tile==74 then
  440. return tile+(((t+5)%20//2.5)-2)
  441. end
  442. if tile==67 or tile==75 then
  443. return tile+(((t+7.5)%20//2.5)-3)
  444. end
  445. if tile==68 or tile==76 then
  446. return tile+(((t+10)%20//2.5)-4)
  447. end
  448. if tile==69 or tile==77 then
  449. return tile+(((t+12.5)%20//2.5)-5)
  450. end
  451. if tile==70 or tile==78 then
  452. return tile+(((t+15)%20//2.5)-6)
  453. end
  454. if tile==71 or tile==79 then
  455. return tile+(((t+17.5)%20//2.5)-7)
  456. end
  457. end)
  458. --SKULLH LIMITS(1-28,1-14)
  459. --skullh(12,10,0,0)
  460. --if btn(5) then skullh(25,3,0,0) end
  461. --skullh(20,6,0,0)
  462. --LEVEL CLEAR
  463. if px==0 and aepx==0 and anix==0 and aniy==0 then
  464. if et<0 then
  465. sfx(52,36,90,0)
  466. for i=0,29 do
  467. mset((30*m%240)+i,(17*(m//8)),0)
  468. end
  469. mset((30*m%240)+10,(17*(m//8)),91)
  470. mset((30*m%240)+11,(17*(m//8)),84)
  471. mset((30*m%240)+12,(17*(m//8)),101)
  472. mset((30*m%240)+13,(17*(m//8)),84)
  473. mset((30*m%240)+14,(17*(m//8)),91)
  474. mset((30*m%240)+16,(17*(m//8)),82)
  475. mset((30*m%240)+17,(17*(m//8)),91)
  476. mset((30*m%240)+18,(17*(m//8)),84)
  477. mset((30*m%240)+19,(17*(m//8)),80)
  478. mset((30*m%240)+20,(17*(m//8)),97)
  479. et=t
  480. end
  481. if et>0 then
  482. spr(257+(f*3),animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  483. spr(265,aex,aey,0,1,0,0,1,2)
  484. fade_out(et)
  485. end
  486. if t<et+(3*60) then
  487. return end
  488. m=m+1
  489. t=1
  490. level(m)
  491. end
  492. --STATUS DISPLAY
  493. mset((30*m%240)+3,(17*(m//8)),112+l)
  494. mset((30*m%240)+7,(17*(m//8)),112+s)
  495. end
  496. --GAME OVER
  497. if l==0 then
  498. map(210,119,30,17)
  499. sfx(-1,-1,-1,0)
  500. sfx(-1,-1,-1,1)
  501. sfx(-1,-1,-1,2)
  502. sfx(-1,-1,-1,3)
  503. if t==1 then
  504. music(6,-1,-1,false)
  505. end
  506. fade_in(0)
  507. if t<8*60 then
  508. return
  509. end
  510. m=1
  511. level()
  512. t=0
  513. end
  514. --DEATH
  515. 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
  516. if et<0 then
  517. sfx(56,45,-2,0)
  518. sfx(60,45,-2,1)
  519. et=t
  520. end
  521. if et>0 then
  522. spr(331+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  523. spr(329+t%8//4,aex,aey,0,1,0,0,1,2)
  524. fade_out(et)
  525. end
  526. if t<et+(3*60) then
  527. return end
  528. ftrig=0
  529. l=l-1
  530. t=0
  531. level(m)
  532. end
  533. --FALL
  534. 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
  535. if ftrig==0 and l>0 then sfx(57,82,-1,0) end
  536. ftrig=1
  537. animy=animy+1
  538. aniy=-80
  539. spr(263+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  540. end
  541. --NOTHING
  542. if anix==0 and aniy==0 and t>(2*60) then
  543. if ftrig==1 and strig==0 then sfx(58,24,-1,0) end
  544. if strig==0 then
  545. spr(256+c,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  546. else
  547. spr(301+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  548. end
  549. ftrig=0
  550. btrig=0
  551. end
  552. if t<(2*60) then
  553. spr((256+c)+((t%20//10)*15),animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  554. end
  555. if m>1 then
  556. --CONTROLS, COLLISION and SFX
  557. --UP(0),DOWN(1),LEFT(2),RIGHT(3)
  558. if strig==0 and t>(2*60) and ptrig==0 then
  559. 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
  560. ftrig=0
  561. sfx(63,84,-1,3)
  562. animy=animy-1
  563. aniy=80
  564. end
  565. 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
  566. ftrig=0
  567. sfx(63,84,-1,3)
  568. animy=animy+1
  569. aniy=-80
  570. end
  571. 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
  572. ftrig=0
  573. --BRIDGE
  574. 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
  575. sfx(61,0,-1,3)
  576. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,0)
  577. btrig=1
  578. else
  579. sfx(62,0,-1,3)
  580. end
  581. animx=animx-1
  582. anix=80
  583. end
  584. 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
  585. ftrig=0
  586. --BRIDGE
  587. ifmget((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
  588. sfx(61,0,-1,3)
  589. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,0)
  590. btrig=1
  591. else
  592. sfx(62,0,-1,3)
  593. end
  594. animx=animx+1
  595. anix=-80
  596. end
  597. --A/Z(4),B/X(5),X/A(6),Y/S(7)
  598. if (btnp(4) or btnp(5)) and m>=2 then
  599. 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
  600. sfx(53,72,-1,3)
  601. s=s-1
  602. strig=1
  603. else
  604. if s==0 then
  605. sfx(55,31,-1,2)
  606. else
  607. sfx(59,60,-1,3)
  608. end
  609. end
  610. end
  611. if btnp(6) and m<=21 then
  612. m=m+1
  613. level(m)
  614. end
  615. if btnp(7) and m>=3 and m<=21 then
  616. m=m-1
  617. level(m)
  618. end
  619. end
  620. if t>=2*60 then
  621. if keyp(50) then
  622. if ptrig==0 then
  623. sfx(51,43,-1,0,15)
  624. ptrig=1
  625. pal(0.5)
  626. must=peek(0x13ffc)
  627. musf=peek(0x13ffd)
  628. musr=peek(0x13ffe)
  629. musl=peek(0x13fff)
  630. music()
  631. else
  632. sfx(51,43,-1,0,15)
  633. ptrig=0
  634. pal(1)
  635. music(must,musf,musr,musl)
  636. end
  637. end
  638. end
  639. --MOVEMENT PROPERTIES
  640. if strig==1 and anix==0 and aniy==0 then
  641. if aeo==0 then strig=(aex)-(animx*8+(anix//10)) end
  642. if aeo==1 then strig=(aey)-(animy*8+(aniy//10)) end
  643. end
  644. if strig~=1 then
  645. if strig<0 and ptrig==0 then
  646. if aeo==0 then animx=animx-0.5 end
  647. if aeo==1 then animy=animy-0.5 end
  648. strig=strig+4
  649. end
  650. if strig>0 and ptrig==0 then
  651. if aeo==0 then animx=animx+0.5 end
  652. if aeo==1 then animy=animy+0.5 end
  653. strig=strig-4
  654. end
  655. end
  656. if anix>0 then
  657. if btrig==1 then
  658. if m<=11 then spr(48,(animx*8)+8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  659. if m>=12 then spr(49,(animx*8)+8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  660. end
  661. c=0
  662. f=0
  663. if ptrig==0 then anix=anix-8 end
  664. spr(257+t%8//2,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  665. end
  666. if anix<0 then
  667. if btrig==1 then
  668. if m<=11 then spr(48,(animx*8)-8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  669. if m>=12 then spr(49,(animx*8)-8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
  670. end
  671. c=0
  672. f=1
  673. if ptrig==0 then anix=anix+8 end
  674. spr(257+t%8//2,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
  675. end
  676. if aniy>0 then
  677. c=5
  678. if ptrig==0 then aniy=aniy-8 end
  679. spr(261+t%6//3,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  680. end
  681. if aniy<0 then
  682. c=5
  683. if ptrig==0 then aniy=aniy+8 end
  684. 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
  685. spr(263+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  686. else
  687. if ftrig==1 then c=0 end
  688. spr(261+t%14//7,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
  689. end
  690. end
  691. --PIXEL COLLISION
  692. 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
  693. px=px-1
  694. sfx(54,72,-1,0)
  695. mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+1,0)
  696. end
  697. --PHANTOM PIXEL COLLISION
  698. 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
  699. aepx=aepx-1
  700. sfx(54,69,-1,0)
  701. mset((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8),0)
  702. end
  703. --HERO DISPLAY
  704. --ALTER EGO DISPLAY
  705. if aeo==0 then
  706. --120=ZX spectrum Mirrored, 116=NES Mirrored
  707. aex=120-((animx*8+(anix//10))-120)
  708. aey=animy*8+(aniy//10)
  709. end
  710. if aeo==1 then
  711. aex=animx*8+(anix//10)
  712. aey=64-((animy*8+(aniy//10))-64)
  713. end
  714. if t>(2*60) then
  715. if strig==0 then
  716. spr(265+t%8//2,aex,aey,0,1,0,0,1,2)
  717. else
  718. spr(297+t%16//4,aex,aey,0,1,0,0,1,2)
  719. end
  720. else
  721. spr(265+((t%20//10)*6),aex,aey,0,1,0,0,1,2)
  722. end
  723. end
  724. --DEBUG DISPLAY
  725. print("DEBUG",0,0,15,true,1,true)
  726. --TIMER DEBUG
  727. print(t,0,6,15,true,1,true)
  728. --SWAP ACTION INPUT DEBUG
  729. if btn(4)==true or btn(5)==true then
  730. print("true",0,12,15,true,1,true)
  731. else
  732. print("false",0,12,15,true,1,true)
  733. end
  734. --MAP SCREEN DEBUG
  735. print(m,0,18,15,true,1,true)
  736. --SWAP TRIGGER DEBUG
  737. print(strig,22,18,15,true,1,true)
  738. --SCREEN HERO SPR POSITION DEBUG
  739. print((animx*8+(anix//10)),0,24,15,true,1,true)
  740. print((animy*8+(aniy//10))+8,0,30,15,true,1,true)
  741. --SCREEN ALTER EGO SPR POSITION DEBUG
  742. print(aex,22,24,15,true,1,true)
  743. print(aey+8,22,30,15,true,1,true)
  744. --MAP HERO SPR POSITION DEBUG
  745. print((30*m%240)+(animx*8+(anix//10))//8,0,42,15,true,1,true)
  746. print((17*(m//8))+((animy*8+(aniy//10))//8)+1,0,48,15,true,1,true)
  747. --MAP ALTER EGO SPR POSITION DEBUG
  748. print((30*m%240)+aex//8,22,42,15,true,1,true)
  749. print((17*(m//8))+((aey+8)//8),22,48,15,true,1,true)
  750. --MOVEMENT DEBUG
  751. print(anix//10,0,60,15,true,1,true)
  752. print(aniy//10,0,66,15,true,1,true)
  753. --PIXEL AND PHANTOM PIXEL DEBUG
  754. print(px,22,60,15,true,1,true)
  755. print(aepx,22,66,15,true,1,true)
  756. --MGET DEBUG
  757. print(mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10))//8),22,78,15,true,1,true)
  758. 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)
  759. 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)
  760. 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)
  761. 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)
  762. --MUSIC SPEED DEBUG (0-7)
  763. --print(peek(0x13e96),0,102)
  764. --print(peek(0x13ec9),22,102)
  765. --print(peek(0x13efc),0,108)
  766. --print(peek(0x13f2f),22,108)
  767. --print(peek(0x13f62),0,114)
  768. --print(peek(0x13f95),22,114)
  769. --print(peek(0x13fc8),0,120)
  770. --print(peek(0x13ffb),22,120)
  771. --MUSIC POSITION DEBUG
  772. print("track:",44,102,15,true,1,true)
  773. print(peek(0x13ffc),88,102,15,true,1,true)
  774. print("frame:",44,108,15,true,1,true)
  775. print(peek(0x13ffd),88,108,15,true,1,true)
  776. print("row :",44,114,15,true,1,true)
  777. print(peek(0x13ffe),88,114,15,true,1,true)
  778. print("loop :",44,120,15,true,1,true)
  779. print(peek(0x13fff),88,120,15,true,1,true)
  780. --wait: Time event (2 sec)
  781. --if t<2*60 then return end
  782. --stuff to do
  783. --spr command: spr(id+t%nf//f,x,y,z,s,f,r,w,h)
  784. --id=sprite id
  785. --t=timer
  786. --f=frames to wait for switch sprites
  787. --n=number of sprites to switch
  788. --Compare between f and n variables for speed
  789. --x=x position
  790. --y=y position
  791. --z=colorkey id to set alpha
  792. --s=scale
  793. --f=flip(Hflip(1),Vflip(2),HVflip(3))
  794. --r=rotate(90 deg(1),180 deg(2),270 deg(3))
  795. --w=width of composite sprite
  796. --h=height of composite sprite
  797. --end of function TIC()
  798. end