alter-ego-by-kyuchumimo.lua 25 KB

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