alter-ego-by-kyuchumimo.lua 25 KB

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