alter-ego-by-kyuchumimo.lua 24 KB

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