Day night cycle
Hi! I made a function to add a day night cycle. It shifts the palette and takes two arguments, hour and minutes. The palettes can be modified.
First you can see it in action here:

Thing to note
- The night palette is very different from the rest, adjust it based on your sprites. Originally this palette was made by Achie72
- It is very token intensive at the moment. That can surely be optimized by either cleverly contstructing the palettes at runtime or deleting those you don't use. But I kept it like this for readabilities sake.
- Maybe adjust the time to your needs. I took a shorter day as a model but you could also change the times(ho=hour in the function) in code
function set_pal(h,m) local pals={ --night palette from achiegamedev - thx ♥ {[0]=0,129,130,131,132,133,5,13,2,4,137,3,1,141,136,143}, --regular second palette {[0]=128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143}, --sharpen contrast {[0]=128,1,130,131,132,5,134,135,136,137,138,139,140,141,142,143}, {[0]=0,1,130,131,132,5,134,135,136,137,138,139,140,141,142,143}, --introduce greens {[0]=0,1,130,3,132,5,134,135,136,137,138,139,140,141,142,143}, {[0]=0,1,130,3,132,5,134,135,136,137,138,11,140,141,142,143}, --introduce yellows {[0]=0,1,130,3,132,5,134,135,136,9,138,11,140,141,142,143}, {[0]=0,1,130,3,132,5,134,135,136,9,10,11,140,141,142,143}, --introduce reds {[0]=0,1,2,3,4,5,134,135,136,9,10,11,140,141,142,143}, {[0]=0,1,2,3,4,5,134,135,8,9,10,11,140,141,14,15}, } local ho=h or 12 if ho<7 then pal(pals[1],1) elseif ho==7 then pal(pals[2],1) elseif ho==8 then if(m<30)pal(pals[2],1) if(m>20)pal(pals[3],1) if(m>40)pal(pals[4],1) elseif ho==9 then if(m<30)pal(pals[5],1) if(m>20)pal(pals[6],1) elseif ho==10 then if(m<30)pal(pals[7],1) if(m>20)pal(pals[8],1) elseif ho==11 then if(m<30)pal(pals[9],1) if(m>20)pal(pals[10],1) elseif ho==12 then pal() elseif ho==17 then if(m<30)pal(pals[10],1) if(m>20)pal(pals[9],1) elseif ho==18 then if(m<30)pal(pals[8],1) if(m>20)pal(pals[7],1) elseif ho==19 then if(m<30)pal(pals[6],1) if(m>20)pal(pals[5],1) elseif ho==20 then if(m<30)pal(pals[4],1) if(m>20)pal(pals[3],1) elseif ho==21 then if(m<30)pal(pals[2],1) elseif ho>21 then pal(pals[1],1) end end |
I hope this is useful, have fun with it!
[Please log in to post a comment]