alter-ego-by-kyuchumimo.lua 25 KB

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