Browse Source

moving remaining alter ego code to examples

pixelbath 3 years ago
parent
commit
491f84d4eb
2 changed files with 69 additions and 800 deletions
  1. 0 800
      alter-ego-by-kyuchumimo.lua
  2. 69 0
      palettefade.lua

+ 0 - 800
alter-ego-by-kyuchumimo.lua

@@ -1,800 +0,0 @@
--- title:   Alter Ego (WIP)
--- author: ORIGINAL ZX SPECTRUM GAME BY DENIS GRACHEV
---          NES CONVERSION BY SHIRU
---          NES MUSIC BY RICHARD "KULOR" ARMIJO
---          TIC-80 CONVERSION BY KYUCHUMIMO AND PIXELBATH
--- desc:    My first TIC-80 program
-
---WARNING: Saved on TIC-80 0.80.xxxx beta. Music doesn't work on previous versions.
-
---CHANGELOG:
---201120 - pixelbath joined the project. Code optimization: 26473 to 21757 bytes. Changelog moved to tic80.com/play?cart=1420
---INFO:
---https://tic80.com/play?cart=1420
---https://www.youtube.com/watch?v=O3uOHAvlsN8
---http://www.retrosouls.net/?page_id=614
-
--- script:  lua
-
---VARIABLES
---climb
-c=0
---sprite flip
-f=0
---lives
-l=5
---LEVEL (DEFAULT=0)
-m=0
---pixels (KEEP AWAY FROM 0)
-px=0
-aepx=0
---swap
-s=0
---EVENT TIMER
-et=nil
---GLOBAL TIMER
-t=0
---bridge animation trigger
-btrig=0
---FALL TRIGGER
-ftrig=0
---PAUSE TRIGGER
-ptrig=0
---SWAP TRIGGER
-strig=0
---ALTER EGO mirroring (0=H,1=V)
-aeo=0
-
---HERO animation ticks
-anix=0
-aniy=0
---HERO X position
-animx=0
---HERO Y position
-animy=0
---ALTER EGO X position
-aex=0
---ALTER EGO Y position
-aey=0
---palette RGB value
-v=0
-
-options = {
-	music = true,
-	debug = true,
-}
-
-leveldata = {
-	{ name='title' },
-	{ name='hello world',      s=2, px=3, aepx=0, aeo=0, animx=21, animy=3 },
-	{ name='promenade',        s=2, px=8, aepx=0, aeo=0, animx=5, animy=3 },
-	{ name='broken bridge',    s=0, px=8, aepx=0, aeo=0, animx=11, animy=3 },
-	{ name='phantom pixels',   s=3, px=2, aepx=4, aeo=0, animx=14, animy=3 },
-	{ name='another phantom',  s=4, px=13, aepx=0, aeo=1, animx=3, animy=10 },
-	{ name='skulls lair',      s=2, px=14, aepx=0, aeo=0, animx=17, animy=13 },
-	{ name='abracadabra',      s=2, px=6, aepx=6, aeo=0, animx=9, animy=10 },
-	{ name='vertical illusions', s=8, px=10, aepx=0, aeo=1, animx=4, animy=9 },
-	{ name='mirrors',          s=2, px=4, aepx=3, aeo=0, animx=26, animy=11 },
-	{ name='16 pixels',        s=4, px=16, aepx=0, aeo=0, animx=5, animy=9 },
-	{ name='perfect reflect',  s=1, px=16, aepx=0, aeo=0, animx=15, animy=10 },
-	{ name='icelands',         s=3, px=5, aepx=3, aeo=0, animx=15, animy=9 },
-	{ name='midnight',         s=2, px=5, aepx=0, aeo=0, animx=23, animy=12 },
-	{ name='alone skull',      s=3, px=3, aepx=2, aeo=0, animx=15, animy=2 },
-	{ name='made in heaven',   s=5, px=9, aepx=6, aeo=1, animx=4, animy=4 },
-	{ name='underwater',       s=2, px=3, aepx=5, aeo=0, animx=2, animy=9 },
-	{ name='zupapixels',       s=9, px=8, aepx=1, aeo=0, animx=3, animy=2 },
-	{ name='skullopedia',      s=4, px=12, aepx=0, aeo=0, animx=7, animy=12 },
-	{ name='after the war',    s=3, px=8, aepx=0, aeo=1, animx=3, animy=2 },
-	{ name='vuris knvartirus', s=6, px=11, aepx=0, aeo=0, animx=24, animy=13 },
-	{ name='the end',          s=143, px=-255, aepx=-255, aeo=0, animx=-1, animy=-2 },
-}
-
-cls()
-map()
-
---PALETTE STUFF
-local basepalette = {
-	0x1a1c2c, 0x29366f, 0x3b5dc9, 0x1a1c2c, 0x5d275d, 0x38b764, 0xb13e53, 0x333c57, 0x41a6f6, 0xef7d57, 0x94b0c2, 0xa7f070, 0xe06f8b, 0x73eff7, 0xffcd75, 0xf4f4f4
-}
-function pal(v)
-	for i = 1, #basepalette do
-		local offset, color = i-1, basepalette[i]
-		poke(0x3fc0+(offset*3), ((color//65536) * v))
-		poke(0x3fc1+(offset*3), ((color//256)%256) * v)
-		poke(0x3fc2+(offset*3), (color%256) * v)
-	end
-end
-
-function fade_out(et)
-	if t==(et+(2.1*60)) then
-		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
-		return pal(1)
-	end
-	if t==(et+(2.2*60)) then return pal(0.75) end
-	if t==(et+(2.3*60)) then return pal(0.5) end
-	if t==(et+(2.4*60)) then return pal(0.25) end
-	if t==(et+(2.5*60)) then return pal(0) end
-end
-
-function fade_in(et)
-	if t==(et+(0*60)+1) then return pal(0) end
-	if t==(et+(0.1*60)) then return pal(0.25) end
-	if t==(et+(0.2*60)) then return pal(0.5) end
-	if t==(et+(0.3*60)) then return pal(0.75) end
-	if t==(et+(0.4*60)) then return pal(1) end
-end
-
--- PARTICLE/VFX STUFF
-particles = {}
-particletype = 'stars'
-local starcolors = { 1, 2, 13, 15}
--- numparticles = number of particles to show
--- particletype = rain|snow|stars
-function particleinit(numparticles, type)
-	-- initialize
-	particles = {}
-	particletype = type
-	for i = 0, numparticles do
-		table.insert(particles, {
-			x = math.random() * 240,
-			y = math.random() * 136,
-			lastx = 0,
-			lasty = 0,
-			color = 2,
-			t = 0,
-			vel = 0,
-		})
-	end
-	if particletype == 'stars' then
-		for i = 1, #particles do
-			particles[i].twinkle = math.random() > 0.49 -- randomly pick true/false
-			particles[i].color = starcolors[math.random(#starcolors)]
-		end
-	end
-	if particletype == 'rain' then
-		for i = 1, #particles do
-			particles[i].vel = math.random(3) + 1
-			if particles[i].vel > 2.5 then
-				particles[i].color = 8
-			end
-		end
-	end
-	if particletype == 'snow' then
-		for i = 1, #particles do
-			particles[i].color = 15
-			particles[i].vel = math.random() + 0.2
-		end
-	end
-end
-
-function particleupdate()
-	if particletype == 'stars' then
-		for i = 1,#particles do
-			local p = particles[i]
-			if not p.twinkle then goto continueTwinkle end
-			::continueTwinkle::
-			if t % 15 == 0 and math.random() > 0.1 then
-				p.color = starcolors[math.random(#starcolors)]
-			end
-		end
-	end
-	if particletype == 'rain' then
-		for i = 1,#particles do
-			local p = particles[i]
-			if p.lasty and p.lasty > 136 then
-				p.y = 0
-				p.lasty = 0
-				p.x = math.random() * 240
-			end
-			p.lasty = p.y
-			p.lastx = p.x
-			p.x = p.x - p.vel / 5
-			p.y = p.y + p.vel * 1.5
-		end
-	end
-	if particletype == 'snow' then
-		for i = 1,#particles do
-			local p = particles[i]
-			if p.y and p.y > 136 then
-				p.y = 0
-				p.lasty = 0
-				p.x = math.random() * 240
-			end
-			p.x = p.x - (math.random() - 0.4)
-			p.y = p.y + p.vel
-		end
-	end
-end
-
-function particledraw()
-	if (particletype == 'rain') then
-		for i = 1,#particles do
-			local p = particles[i]
-			line(p.x, p.y, p.lastx, p.lasty, p.color)
-		end
-		return
-	end
-	for i = 1,#particles do
-		local p = particles[i]
-		pix(p.x, p.y, p.color)
-	end
-end
-
--- init here for title screen
-particleinit(150, 'stars')
-
---(shx: Xpos, shy: Ypos, shf: flip, sht: timer) CHECK THIS
-function skullh(shx,shy,shf,sht)
-	--local shx
-	--local shy
-	--local sht
-	--local shf
-	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
-		if shf==0 then shf=1 else shf=0 end
-		--sht=0
-		spr(288+t%16//4,(shx*8)+(sht//8),(shy*8),0,1,shf,0,1,2)
-	else
-		--sht=sht+1
-		spr(288+t%16//4,(shx*8)-(sht//8),(shy*8),0,1,shf,0,1,2)
-	end
-	
-	if (animx*8+(anix//10))==shx*8 and ((animy*8+(aniy//10))+8)==(shy*8)+8 then
-		ftrig=0
-		l=l-1
-		sfx(56,45,-2,0)
-		t=0
-		level(m)	
-	end
- 
---SCREEN SKULL SPR POSITION DEBUG
-	--print(shx*8,22,24)
-	--print((shy*8)+8,22,30)
-
-end
-
---LEVEL PROPERTIES (ANIMX/Y LIMITS(1-28,1-14))
-function level(m)
-	-- reset level data
-	sync (0,0, false)
-
-	c=0
-	f=0
-	px=nil
-	aepx=nil
-	anix=0
-	aniy=0
-	et=-255
-	strig=0
-	ftrig=0
-	t=0
-
-	-- switch particles
-	if m==1 then particleinit(150, 'stars') end
-	if m>=2 and m<12 then particleinit(120, 'rain') end
-	if m>=12 then particleinit(180, 'snow') end
-	if m==22 then particleinit(150, 'stars') end
-
-	if m > 0 then
-		local data = leveldata[m]
-		s = data.s
-		px = data.px
-		aepx = data.aepx
-		aeo = data.aeo
-		animx = data.animx
-		animy = data.animy
-	end
-
-	--END
-	if m==22 then
-		l=143
-		s=143
-		mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8),1)
-		mset(((30*m%240)+(animx*8+(anix//10))//8)-1,(17*(m//8))+((animy*8+(aniy//10))//8)+1,1)
-		mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,1)
-		mset(((30*m%240)+(animx*8+(anix//10))//8)+1,(17*(m//8))+((animy*8+(aniy//10))//8)+1,1)	
-	end
-end
-
-level(m)
-
-function TIC()
-
-	--MUSIC (For loop use t%(spd*rows*#patterns used)==0)
-	if options.music then
-		--TITLE SCREEN
-		if m==1 and t==0 then music(0,-1,-1,false) end
-		--LEVELS 1-10
-		if m>=2 and m<=11 and t==0 then	music(1,-1,-1,false) end
-		--LEVELS 11-21
-		if m>=12 and m<=21 and t==0 then music(2,-1,-1,false) end
-		--LEVELS 21-???
-		if m>=22 and t==0 then music(3) end
-	end
-
-	--TIMER
-	if ptrig==0 then t=t+1 end
-
-	--CREDITS
-	if m==0 then
-		map(0,0,30,17)
-		if options.debug then
-			print(t,0,0,15,true,1,true)
-			print(et,0,6,15,true,1,true)
-		end
-		fade_in(0)
-		if t==(3*60) or keyp(50) then
-			et=t
-			t=180
-		end
-		if t>(et+(3*60)) and et>=0 then 
-			m=m+1
-			t=0
-			et=-255
-		else 
-			fade_out(et)
-			return
-		end
-	end
-	
-	--TITLE SCREEN
-	if m==1 then
-		l=5
-		--REMAP
-		cls()
-		particleupdate()
-		particledraw()
-
-		map(30*m%270,17*((m-1)//8),30,17,0,0,0,1)
-
-		fade_in(0)
-		
-		if t<0.4*60 then return end 
-			if options.debug then
-				print("DEBUG: Press X/A and Y/S to switch levels",8,131)
-				print(et,0,0,15,true,1,true)
-			end
-		if keyp(50) and et<=0 then
-			music()
-			sfx(51,43,-1,0,15)
-			et=t
-		end
-		if t>(et+(3*60)) and et>=0 then 
-			m=m+1
-			level(m)
-		else 
-			fade_out(et)
-			return
-		end
-
-	end
-
-	--LEVEL DISPLAY
-	if m>1 then
-		fade_in(0)
-		--REMAP
-		cls()
-		if ptrig==0 then
-			particleupdate()
-		end
-		particledraw()
-		rect(0,0,240,8,0)
-		map(30*m%240,17*(m//8),30,17,0,0,0,1,
-			function(tile)
-				if tile>=80 and tile<=111 and anix==0 and aniy==0 and px==0 and aepx==0 then
-					return tile*(t%38//19)
-				end
-				if tile==6 or tile==22 or tile==38 or tile==54 then
-					return tile+(t%38//19)
-				else
-					if tile~=6 and tile~=22 and tile~=38 and tile~=54 and not (tile>=64 and tile<=79) then return tile end
-				end
-			end
-		)
-
-	--PIXELS DISPLAY
-	map(30*m%240,17*(m//8),30,17,0,0,0,1,
-		function(tile)
-			if tile==64 or tile==72 then
-				return tile+(t%20//2.5)
-			end
-			if tile==65 or tile==73 then
-				return tile+(((t+2.5)%20//2.5)-1)
-			end
-			if tile==66 or tile==74 then
-				return tile+(((t+5)%20//2.5)-2)
-			end
-			if tile==67 or tile==75 then
-				return tile+(((t+7.5)%20//2.5)-3)
-			end
-			if tile==68 or tile==76 then
-				return tile+(((t+10)%20//2.5)-4)
-			end
-			if tile==69 or tile==77 then
-				return tile+(((t+12.5)%20//2.5)-5)
-			end
-			if tile==70 or tile==78 then
-				return tile+(((t+15)%20//2.5)-6)
-			end
-			if tile==71 or tile==79 then
-				return tile+(((t+17.5)%20//2.5)-7)
-			end
-		end
-	)
-
-	--SKULLH LIMITS(1-28,1-14)
-	--skullh(12,10,0,0)
-	--if btn(5) then	skullh(25,3,0,0) end
-	--skullh(20,6,0,0)
-
-	--LEVEL CLEAR
-	if px==0 and aepx==0 and anix==0 and aniy==0 then
-		if et<0 then
-			sfx(52,36,90,0)
-			for i=0,29 do
-				mset((30*m%240)+i,(17*(m//8)),0)
-			end
-			mset((30*m%240)+10,(17*(m//8)),91)
-			mset((30*m%240)+11,(17*(m//8)),84)
-			mset((30*m%240)+12,(17*(m//8)),101)
-			mset((30*m%240)+13,(17*(m//8)),84)
-			mset((30*m%240)+14,(17*(m//8)),91)
-			mset((30*m%240)+16,(17*(m//8)),82)
-			mset((30*m%240)+17,(17*(m//8)),91)
-			mset((30*m%240)+18,(17*(m//8)),84)
-			mset((30*m%240)+19,(17*(m//8)),80)
-			mset((30*m%240)+20,(17*(m//8)),97)
-			et=t
-		end
-		if et>0 then
-			spr(257+(f*3),animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
-			spr(265,aex,aey,0,1,0,0,1,2)
-			fade_out(et)
-		end
-		if t<et+(3*60) then
-		return end
-		m=m+1
-		t=1
-		level(m)
-	end
-
-	--STATUS DISPLAY
-	mset((30*m%240)+3,(17*(m//8)),112+l)
-	mset((30*m%240)+7,(17*(m//8)),112+s)
-	end
-
-	--GAME OVER
-	if l==0 then
-		map(210,119,30,17)
-		sfx(-1,-1,-1,0)
-		sfx(-1,-1,-1,1)
-		sfx(-1,-1,-1,2)
-		sfx(-1,-1,-1,3)
-		if t==1 then
-			music(6,-1,-1,false)
-		end
-		fade_in(0)
-		if t<8*60 then
-			return
-		end
-		m=1
-		level()
-		t=0
-	end
-
-	--DEATH
-	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
-		if et<0 then
-			sfx(56,45,-2,0)
-			sfx(60,45,-2,1)
-			et=t
-		end
-		if et>0 then
-			spr(331+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
-			spr(329+t%8//4,aex,aey,0,1,0,0,1,2)
-			fade_out(et)
-		end
-		if t<et+(3*60) then
-		return end
-		ftrig=0
-		l=l-1
-		t=0
-		level(m)
-	end
-	
-	--FALL
-	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
-		if ftrig==0 and l>0 then sfx(57,82,-1,0) end
-		ftrig=1
-		animy=animy+1
-		aniy=-80
-		spr(263+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
-	end
-
-	--NOTHING
-	if anix==0 and aniy==0 and t>(2*60) then
-		if ftrig==1 and strig==0 then sfx(58,24,-1,0) end
-		if strig==0 then
-			spr(256+c,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
-		else
-			spr(301+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
-		end
-		ftrig=0
-		btrig=0
-	end
-
-	if t<(2*60) then
-		spr((256+c)+((t%20//10)*15),animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
-	end
-		
-	if m>1 then
-		--CONTROLS, COLLISION and SFX
-		--UP(0),DOWN(1),LEFT(2),RIGHT(3)
-		if strig==0 and t>(2*60) and ptrig==0 then
-			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
-				ftrig=0
-				sfx(63,84,-1,3)
-				animy=animy-1
-				aniy=80
-			end
-
-			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
-				ftrig=0
-				sfx(63,84,-1,3)
-				animy=animy+1
-				aniy=-80
-			end
-
-		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
-			ftrig=0
-			--BRIDGE
-			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
-				sfx(61,0,-1,3)
-				mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,0)
-				btrig=1
-			else
-				sfx(62,0,-1,3)
-			end
-			animx=animx-1
-			anix=80
-		end
-
-		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
-			ftrig=0
-			--BRIDGE
-			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
-				sfx(61,0,-1,3)
-				mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+2,0)
-				btrig=1
-			else
-				sfx(62,0,-1,3)
-			end
-			animx=animx+1
-			anix=-80
-		end
-
-		--A/Z(4),B/X(5),X/A(6),Y/S(7)	
-		if (btnp(4) or btnp(5)) and m>=2 then
-			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
-				sfx(53,72,-1,3)
-				s=s-1
-				strig=1
-			else
-				if s==0 then
-					sfx(55,31,-1,2)
-				else
-					sfx(59,60,-1,3)
-				end
-			end
-		end
-		if btnp(6) and m<=21 then
-			m=m+1
-			level(m)
-		end
-		if btnp(7) and m>=3 and m<=21 then
-			m=m-1
-			level(m)
-			end
-		end
-
-		if t>=2*60 then
-			if keyp(50) then
-				if ptrig==0 then
-					sfx(51,43,-1,0,15)
-					ptrig=1
-					pal(0.5)
-					must=peek(0x13ffc)
-					musf=peek(0x13ffd)
-					musr=peek(0x13ffe)
-					musl=peek(0x13fff)
-					music()
-				else
-					sfx(51,43,-1,0,15)
-					ptrig=0
-					pal(1)
-					music(must,musf,musr,musl)
-				end
-			end
-		end
-
-		--MOVEMENT PROPERTIES
-		if strig==1 and anix==0 and aniy==0 then
-			if aeo==0 then strig=(aex)-(animx*8+(anix//10)) end
-			if aeo==1 then strig=(aey)-(animy*8+(aniy//10)) end
-		end
-		if strig~=1 then
-		if strig<0 and ptrig==0 then
-			if aeo==0 then animx=animx-0.5 end
-			if aeo==1 then animy=animy-0.5 end
-			strig=strig+4
-		end
-		if strig>0 and ptrig==0 then
-			if aeo==0 then animx=animx+0.5 end
-			if aeo==1 then animy=animy+0.5 end
-			strig=strig-4
-		end
-	end
-
-	if anix>0 then
-		if	btrig==1 then	
-			if m<=11 then spr(48,(animx*8)+8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
-			if m>=12 then spr(49,(animx*8)+8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
-		end
-		c=0
-		f=0
-		if ptrig==0 then anix=anix-8 end
-			spr(257+t%8//2,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
-		end
-		if anix<0 then
-			if btrig==1 then	
-				if m<=11 then spr(48,(animx*8)-8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end
-				if m>=12 then spr(49,(animx*8)-8,(animy*8+(aniy//10))+16+(8-(math.abs(anix//10))),0) end			
-			end
-			c=0
-			f=1
-			if ptrig==0 then anix=anix+8 end
-				spr(257+t%8//2,animx*8+(anix//10),animy*8+(aniy//10),0,1,f,0,1,2)
-			end 
-		if aniy>0 then
-			c=5
-			if ptrig==0 then aniy=aniy-8 end
-			spr(261+t%6//3,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
-		end
-		if aniy<0 then
-			c=5
-			if ptrig==0 then aniy=aniy+8 end
-			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
-				spr(263+t%8//4,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
-			else
-				if ftrig==1 then c=0 end
-				spr(261+t%14//7,animx*8+(anix//10),animy*8+(aniy//10),0,1,0,0,1,2)
-			end
-		end
-
-		--PIXEL COLLISION
-		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
-			px=px-1
-			sfx(54,72,-1,0)
-			mset((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+((animy*8+(aniy//10))//8)+1,0)
-		end
-
-		--PHANTOM PIXEL COLLISION
-		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
-			aepx=aepx-1
-			sfx(54,69,-1,0)
-			mset((30*m%240)+aex//8,(17*(m//8))+((aey+8)//8),0)
-		end
-		
-		--HERO DISPLAY
-		
-		--ALTER EGO DISPLAY
-		if aeo==0 then
-			--120=ZX spectrum Mirrored, 116=NES Mirrored
-			aex=120-((animx*8+(anix//10))-120)
-			aey=animy*8+(aniy//10)
-		end
-		if aeo==1 then
-			aex=animx*8+(anix//10)
-			aey=64-((animy*8+(aniy//10))-64)
-		end
-	
-		if t>(2*60) then	
-			if strig==0 then
-				spr(265+t%8//2,aex,aey,0,1,0,0,1,2)
-			else
-				spr(297+t%16//4,aex,aey,0,1,0,0,1,2)
-			end
-		else
-			spr(265+((t%20//10)*6),aex,aey,0,1,0,0,1,2)
-		end
-	
-	end
-
-	if options.debug then
-		print("DEBUG",0,0,15,true,1,true)
-		--TIMER DEBUG
-		print(t,0,6,15,true,1,true)
-		--SWAP ACTION INPUT DEBUG
-		if btn(4)==true or btn(5)==true then
-			print("true",0,12,15,true,1,true)
-		else
-			print("false",0,12,15,true,1,true)
-		end
-		--MAP SCREEN DEBUG
-		print(m,0,18,15,true,1,true)
-
-		--SWAP TRIGGER DEBUG	
-		print(strig,22,18,15,true,1,true)
-		
-		--SCREEN HERO SPR POSITION DEBUG
-		print((animx*8+(anix//10)),0,24,15,true,1,true)
-		print((animy*8+(aniy//10))+8,0,30,15,true,1,true)
-		
-		--SCREEN ALTER EGO SPR POSITION DEBUG
-		print(aex,22,24,15,true,1,true)
-		print(aey+8,22,30,15,true,1,true)
-
-		--MAP HERO SPR POSITION DEBUG
-		print((30*m%240)+(animx*8+(anix//10))//8,0,42,15,true,1,true)
-		print((17*(m//8))+((animy*8+(aniy//10))//8)+1,0,48,15,true,1,true)
-		
-		--MAP ALTER EGO SPR POSITION DEBUG
-		print((30*m%240)+aex//8,22,42,15,true,1,true)
-		print((17*(m//8))+((aey+8)//8),22,48,15,true,1,true)
-		
-		--MOVEMENT DEBUG
-		print(anix//10,0,60,15,true,1,true)
-		print(aniy//10,0,66,15,true,1,true)
-		
-		--PIXEL AND PHANTOM PIXEL DEBUG
-		print(px,22,60,15,true,1,true)
-		print(aepx,22,66,15,true,1,true)	
-
-		--MGET DEBUG
-		print(mget((30*m%240)+(animx*8+(anix//10))//8,(17*(m//8))+(animy*8+(aniy//10))//8),22,78,15,true,1,true)	
-		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)
-		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)
-		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)
-		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)
-	
-		--MUSIC SPEED DEBUG (0-7)
-		--print(peek(0x13e96),0,102)
-		--print(peek(0x13ec9),22,102)
-		--print(peek(0x13efc),0,108)
-		--print(peek(0x13f2f),22,108)
-		--print(peek(0x13f62),0,114)
-		--print(peek(0x13f95),22,114)
-		--print(peek(0x13fc8),0,120)
-		--print(peek(0x13ffb),22,120)
-
-		--MUSIC POSITION DEBUG
-		print("track:",44,102,15,true,1,true)
-		print(peek(0x13ffc),88,102,15,true,1,true)
-		print("frame:",44,108,15,true,1,true)
-		print(peek(0x13ffd),88,108,15,true,1,true)
-		print("row  :",44,114,15,true,1,true)
-		print(peek(0x13ffe),88,114,15,true,1,true)
-		print("loop :",44,120,15,true,1,true)
-		print(peek(0x13fff),88,120,15,true,1,true)
-		
-		--wait: Time event (2 sec)
-		--if t<2*60 then return end
-		--stuff to do
-			
-		--spr command: spr(id+t%nf//f,x,y,z,s,f,r,w,h)
-		--id=sprite id
-		--t=timer
-		--f=frames to wait for switch sprites
-		--n=number of sprites to switch
-		--Compare between f and n variables for speed
-		--x=x position
-		--y=y position
-		--z=colorkey id to set alpha
-		--s=scale
-		--f=flip(Hflip(1),Vflip(2),HVflip(3))
-		--r=rotate(90 deg(1),180 deg(2),270 deg(3))
-		--w=width of composite sprite
-		--h=height of composite sprite
-	end --if options.debug
-
-	--end of function TIC()
-end

+ 69 - 0
palettefade.lua

@@ -0,0 +1,69 @@
+-- title:  palettefade
+-- author: pixelbath
+-- desc:   fades elements of the palette
+-- script: lua
+
+-- TODO: read the TIC palette at runtime
+local basepalette = {
+	0x1a1c2c, 0x29366f, 0x3b5dc9, 0x1a1c2c, 0x5d275d, 0x38b764, 0xb13e53, 0x333c57, 0x41a6f6, 0xef7d57, 0x94b0c2, 0xa7f070, 0xe06f8b, 0x73eff7, 0xffcd75, 0xf4f4f4
+}
+function pal(v)
+	if v>1 then v=1 end
+	if v<0 then v=0 end
+	for i = 1, #basepalette do
+		local offset, color = i-1, basepalette[i]
+		poke(0x3fc0+(offset*3), ((color//65536) * v))
+		poke(0x3fc1+(offset*3), ((color//256)%256) * v)
+		poke(0x3fc2+(offset*3), (color%256) * v)
+	end
+end
+
+local palval=0
+local palinc=0.1
+
+t=0
+x=96
+y=24
+
+function TIC()
+	if btn(0) then y=y-1 end
+	if btn(1) then y=y+1 end
+	if btn(2) then x=x-1 end
+	if btn(3) then x=x+1 end
+
+	cls(13)
+	spr(1+t%60//30*2,x,y,14,3,0,0,2,2)
+	print("HELLO WORLD!",84,84)
+	t=t+1
+	
+	palval=palval+palinc
+	if palval > 0.9 then palinc=-0.1 end
+	if palval < 0.1 then palinc=0.1 end
+	pal(palval)
+end
+
+-- <TILES>
+-- 001:7fffffffff111111f8888888f8111111f8fffffff8ff0ffff8ff0ffff8ff0fff
+-- 002:fffff7771111ff7788880f7711180f77fff80fff0ff80f0f0ff80f0f0ff80f0f
+-- 003:7fffffffff111111f8888888f8111111f8fffffff8fffffff8ff0ffff8ff0fff
+-- 004:fffff7771111ff7788880f7711180f77fff80ffffff80f0f0ff80f0f0ff80f0f
+-- 017:f8fffffff8888888f888f888f8888ffff8888888f1111111ff000fff7fffff7f
+-- 018:fff800ff88880ff7f8880f7788880f7788880f771111ff77000ff777ffff7777
+-- 019:f8fffffff8888888f888f888f8888ffff8888888f1111111ff000fff7fffff7f
+-- 020:fff800ff88880ff7f8880f7788880f7788880f771111ff77000ff777ffff7777
+-- </TILES>
+
+-- <WAVES>
+-- 000:00000000ffffffff00000000ffffffff
+-- 001:0123456789abcdeffedcba9876543210
+-- 002:0123456789abcdef0123456789abcdef
+-- </WAVES>
+
+-- <SFX>
+-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
+-- </SFX>
+
+-- <PALETTE>
+-- 000:1a1c2c29366f3b5dc91a1c2c5d275d38b764b13e53333c5741a6f6ef7d5794b0c2a7f070e06f8b73eff7ffcd75f4f4f4
+-- </PALETTE>
+