Log In  


Some things that might be useful.

Dark palette

Usage:
l: how strong the darkness effect should be

dpal={0,1,1,2,1,13,6,2,4,9,3,13,5,2,9}
function dark(l)
 l=l or 0
 if l>0 then
  for i=0,15 do
   col=dpal[i] or 0
   for a=1,l-0.5 do
    col=dpal[col]
   end
   pal(i,col)
  end
 end
end

Circle map

Usage:
x,y: coordinates to draw the map
r: radius of the map to draw

function circmap(x,y,r)
 for y2=-r,r do
  x2=sqrt(abs(y2*y2-r*r))
  tline(x-x2,y+y2,x+x2,y+y2,(x-x2)/8,(y+y2)/8)
 end
end

Can be used with dark palette to make a light:

-- circle map function
function circmap(x,y,r)
	for y2=-r,r do
		x2=sqrt(abs(y2*y2-r*r))
		tline(x-x2,y+y2,x+x2,y+y2,(x-x2)/8,(y+y2)/8)
	end
end

-- function to darken the palette
function dark(l)
	l=l or 0
	if l>0 then
		for i=0,15 do
			col=dpal[i] or 0
			for a=1,l-0.5 do
				col=dpal[col]
			end
			pal(i,col)
		end
	end
end

function _init()

	-- dark palette
	dpal={0,1,1,2,1,13,6,2,4,9,3,13,5,2,9}

	t=0
	x=64
	y=64
	r=32
end

function _update()

	-- circle position and size
	x=64+sin(t/100)*32
	y=64+cos(t/100)*32
	r=32+sin(t/50)*16

	-- timer and loop
	t+=1

end

function _draw()

	cls()

	-- darkens the palette 2 times
	dark(2)

	-- draws map
	map()

	-- resets palette
	pal()

	-- draws circmap
	circmap(x,y,r)

end


20


Awesome!


@dredds

Thanks!


@cubee this is fantastic! Could you add a code snippit example for the palette swapped circmap function gif?


1

@zerkdev

-- circle map function
function circmap(x,y,r)
	for y2=-r,r do
		x2=sqrt(abs(y2*y2-r*r))
		tline(x-x2,y+y2,x+x2,y+y2,(x-x2)/8,(y+y2)/8)
	end
end

-- function to darken the palette
function dark(l)
	l=l or 0
	if l>0 then
		for i=0,15 do
			col=dpal[i] or 0
			for a=1,l-0.5 do
				col=dpal[col]
			end
			pal(i,col)
		end
	end
end

function _init()

	-- dark palette
	dpal={0,1,1,2,1,13,6,2,4,9,3,13,5,2,9}

	t=0
	x=64
	y=64
	r=32
end

function _update()

	-- circle position and size
	x=64+sin(t/100)*32
	y=64+cos(t/100)*32
	r=32+sin(t/50)*16

	-- timer and loop
	t+=1

end

function _draw()

	cls()

	-- darkens the palette 2 times
	dark(2)

	-- draws map
	map()

	-- resets palette
	pal()

	-- draws circmap
	circmap(x,y,r)

end


Thank you!


@cubee Your circle map function is exactly what I need for a WIP game! Would it be OK if I used it, and if so, what is your preferred method of attribution?


1

@2bitchuck

yes. just leave a little note somewhere saying you used it


@cubee Thank you, I will. This saved me a ton of time!



[Please log in to post a comment]