From eb7cde2a10895da166cebe13452ca3b284eab78c Mon Sep 17 00:00:00 2001 From: "chirs241097@gmail.com" Date: Fri, 31 Jan 2014 15:41:18 +0000 Subject: AM resources/b_diff.png AM resources/b_inter.png AM resources/b_null.png D resources/bg.png AM resources/e_skyitem.png AM trunk/CHANGELOG.TXT AM trunk/VERSION.TXT M trunk/background.h M trunk/global.h A trunk/hge/sound.cpp D trunk/hge/sound_openal.cpp M trunk/levels.h M trunk/main.cpp M trunk/menus.h M trunk/towernbullet.h --- background.h | 342 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 288 insertions(+), 54 deletions(-) (limited to 'background.h') diff --git a/background.h b/background.h index 0739e5f..718b42c 100644 --- a/background.h +++ b/background.h @@ -156,73 +156,307 @@ public: } }; //******************************************** -//3D-Clouds Background +//3D-sky Background +//Based on a hge tutorial //******************************************** -class TDClouds +class TDSky { +#define ScreenWidth 800 +#define ScreenHeight 600 +#define Stars 100 +#define SeaDisize 16 +#define SkyHeight (ScreenHeight*0.6f) +#define StarsHeight (SkyHeight*0.9f) +#define OrbitRadius (ScreenWidth*0.43f) private: - hgeQuad CQuad; - double DTime; - int alpha,lima; - bool onFadein,onFadeout; - void DoFadein() + const DWORD skyTopColors[3] = {0xFF15092A, 0xFF6C6480, 0xFF89B9D0}; + const DWORD skyBtmColors[3] = {0xFF303E57, 0xFFAC7963, 0xFFCAD7DB}; + const DWORD seaTopColors[3] = {0xFF3D546B, 0xFF927E76, 0xFF86A2AD}; + const DWORD seaBtmColors[3] = {0xFF1E394C, 0xFF2F4E64, 0xFF2F4E64}; + const int seq[9]={0, 0, 1, 2, 2, 2, 1, 0, 0}; + HTEXTURE skyitem; + hgeSprite *sky,*sun,*moon,*glow,*seaglow,*star; + hgeDistortionMesh *sea,*skylyr; + float timet,speed,skya,skylima,seq_residue; + int seq_id; + float starX[Stars],starY[Stars],starS[Stars],starA[Stars],seaP[SeaDisize]; + hgeColor colWhite,colSkyTop,colSkyBtm,colSeaTop,colSeaBtm; + hgeColor colSun,colSunGlow; + hgeColor colMoon,colMoonGlow,colSeaGlow; + float sunX,sunY,sunS,sunGlowS; + float moonX,moonY,moonS,moonGlowS; + float seaGlowX,seaGlowSX,seaGlowSY; + bool skyOnFadeIn,skyOnFadeOut; + float GetTime() { - int times=1; - if (LOWFPS)times=17; - for (int i=1;i<=times;++i)if (alphatm_sec; + tmp=t->tm_min+tmp/60.0f; + tmp=t->tm_hour+tmp/60.0f; + } + return tmp; } - void DoFadeout() + void SkyDoFadeIn() { - int times=1; - if (LOWFPS)times=17; - for (int i=1;i<=times;++i)if (alpha>0)--alpha; + float dlt=1.0f/hge->Timer_GetFPS(); + if (skya+dltTimer_GetFPS(); + if (skya-dlt>0)skya-=dlt; + else skya=0.0f,skyOnFadeOut=false; } public: - void Init(int _lima) - { - DTime=0.0f; - CQuad.tex=hge->Texture_Load("sky.png"); - CQuad.blend=BLEND_ALPHABLEND; - alpha=0;lima=_lima; - onFadein=onFadeout=false; - for (int i=0;i<4;++i) - CQuad.v[i].col=0x00FFFFFF; - CQuad.v[0].x=0,CQuad.v[0].y=300; - CQuad.v[1].x=800,CQuad.v[1].y=300; - CQuad.v[2].x=1000,CQuad.v[2].y=600; - CQuad.v[3].x=-200,CQuad.v[3].y=600; - CQuad.v[0].tx=0,CQuad.v[0].ty=0; - CQuad.v[0].tx=0.5,CQuad.v[0].ty=0; - CQuad.v[0].tx=0.5,CQuad.v[0].ty=0.5; - CQuad.v[0].tx=0,CQuad.v[0].ty=0.5; - } - void SetFadein() - { - onFadein=true; - onFadeout=false; - alpha=0; - } - void SetFadeout() - { - onFadeout=true; - onFadein=false; - alpha=lima; + bool Init() + { + skyitem=hge->Texture_Load("e_skyitem.png"); + if(!skyitem) return false; + sky=new hgeSprite(0, 0, 0, ScreenWidth, ScreenHeight); + sea=new hgeDistortionMesh(SeaDisize, SeaDisize); + sea->SetTextureRect(0, 0, ScreenWidth, ScreenHeight-SkyHeight); + sun=new hgeSprite(skyitem,81,0,114,114); + sun->SetHotSpot(57,57); + moon=new hgeSprite(skyitem,0,0,81,81); + moon->SetHotSpot(40,40); + star=new hgeSprite(skyitem,195,0,9,9); + star->SetHotSpot(5,5); + glow=new hgeSprite(skyitem,204,0,128,128); + glow->SetHotSpot(64,64); + glow->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE); + seaglow=new hgeSprite(skyitem,204,96,128,32); + seaglow->SetHotSpot(64,0); + seaglow->SetBlendMode(BLEND_COLORADD | BLEND_ALPHAADD | BLEND_NOZWRITE); + skylyr=new hgeDistortionMesh(16, 16); + skylyr->SetTexture(skyitem); + skylyr->SetTextureRect(0,128,512,512); + skylyr->SetBlendMode(BLEND_ALPHAADD); + colWhite.SetHWColor(0xFFFFFFFF); + timet=GetTime(); + speed=skya=0.0f; + for(int i=0;iTexture_Free(skyitem); + } + void SetSpeed(float _speed){speed=_speed;} + void SetSkyA(float _skya){skya=_skya;} + void SkySetFadeIn(float _starta=0.0f,float _lima=1.0f) + { + skya=_starta;skylima=_lima; + skyOnFadeIn=true;skyOnFadeOut=false; + } + void SkySetFadeOut(float _starta=0.0f) + { + if (_starta>1E-4)skya=_starta; + skyOnFadeIn=false;skyOnFadeOut=true; } void Update() { - if (onFadein)DoFadein(); - if (onFadeout)DoFadeout(); - for (int i=0;i<4;++i) - CQuad.v[i].col=ARGB(alpha,0xFF,0xFF,0xFF); - DTime+=0.1*hge->Timer_GetDelta(); - CQuad.v[0].tx=cos(DTime),CQuad.v[0].ty=sin(DTime); - CQuad.v[1].tx=CQuad.v[0].tx+0.5f;CQuad.v[1].ty=CQuad.v[0].ty; - CQuad.v[2].tx=CQuad.v[0].tx+0.5f;CQuad.v[2].ty=CQuad.v[0].ty+0.5f; - CQuad.v[3].tx=CQuad.v[0].tx;CQuad.v[3].ty=CQuad.v[0].ty+0.5f; - hge->Gfx_RenderQuad(&CQuad); + int i, j, k; + float zenith,a,dy,fTime; + float posX,s1,s2; + const float cellw=ScreenWidth/(SeaDisize-1); + hgeColor col1,col2; + DWORD dwCol1,dwCol2; + if(speed==0.0f) timet=GetTime(); + else + { + timet+=hge->Timer_GetDelta()*speed; + if(timet>=24.0f) timet-=24.0f; + } + seq_id=(int)(timet/3); + seq_residue=timet/3-seq_id; + zenith=-(timet/12.0f*pi-pi/2.0f); + col1.SetHWColor(skyTopColors[seq[seq_id]]); + col2.SetHWColor(skyTopColors[seq[seq_id+1]]); + colSkyTop=col2*seq_residue + col1*(1.0f-seq_residue); + col1.SetHWColor(skyBtmColors[seq[seq_id]]); + col2.SetHWColor(skyBtmColors[seq[seq_id+1]]); + colSkyBtm=col2*seq_residue + col1*(1.0f-seq_residue); + col1.SetHWColor(seaTopColors[seq[seq_id]]); + col2.SetHWColor(seaTopColors[seq[seq_id+1]]); + colSeaTop=col2*seq_residue + col1*(1.0f-seq_residue); + col1.SetHWColor(seaBtmColors[seq[seq_id]]); + col2.SetHWColor(seaBtmColors[seq[seq_id+1]]); + colSeaBtm=col2*seq_residue + col1*(1.0f-seq_residue); + if(seq_id>=6 || seq_id<2) + for(int i=0; iRandom_Float(0.6f, 1.0f); + a*=(rand()%40+60.0f)/100.0f; + if(seq_id>=6) a*=sinf((timet-18.0f)/12.0f*pi); + else a*=sinf((1.0f-timet/6.0f)*pi/2); + starA[i]=a; + } + if(seq_id==2) a=sinf(seq_residue*pi/2); + else if(seq_id==5) a=cosf(seq_residue*pi/2); + else if(seq_id>2 && seq_id<5) a=1.0f; + else a=0.0f; + colSun.SetHWColor(0xFFEAE1BE); + colSun=colSun*(1-a)+colWhite*a; + a=(cosf(timet/6.0f*pi)+1.0f)/2.0f; + if(seq_id>=2 && seq_id<=6) + { + colSunGlow=colWhite*a; + colSunGlow.a=1.0f; + } + else colSunGlow.SetHWColor(0xFF000000); + sunX=ScreenWidth*0.5f+cosf(zenith)*OrbitRadius; + sunY=SkyHeight*1.2f+sinf(zenith)*OrbitRadius; + sunS=1.0f-0.3f*sinf((timet-6.0f)/12.0f*pi); + sunGlowS=3.0f*(1.0f-a)+3.0f; + if(seq_id>=6) a=sinf((timet-18.0f)/12.0f*pi); + else a=sinf((1.0f-timet/6.0f)*pi/2); + colMoon.SetHWColor(0x20FFFFFF); + colMoon=colMoon*(1-a)+colWhite*a; + colMoonGlow=colWhite; + colMoonGlow.a=0.5f*a; + moonX=ScreenWidth*0.5f+cosf(zenith-pi)*OrbitRadius; + moonY=SkyHeight*1.2f+sinf(zenith-pi)*OrbitRadius; + moonS=1.0f-0.3f*sinf((timet+6.0f)/12.0f*pi); + moonGlowS=a*0.4f+0.5f; + if(timet>19.0f || timet<4.5f) + { + a=0.2f; + if(timet>19.0f && timet<20.0f) a*=(timet-19.0f); + else if(timet>3.5f && timet<4.5f) a*=1.0f-(timet-3.5f); + colSeaGlow=colMoonGlow; + colSeaGlow.a=a; + seaGlowX=moonX; + seaGlowSX=moonGlowS*3.0f; + seaGlowSY=moonGlowS*2.0f; + } + else if(timet>6.5f && timet<19.0f) + { + a=0.3f; + if(timet<7.5f) a*=(timet-6.5f); + else if(timet>18.0f) a*=1.0f-(timet-18.0f); + colSeaGlow=colSunGlow; + colSeaGlow.a=a; + seaGlowX=sunX; + seaGlowSX=sunGlowS; + seaGlowSY=sunGlowS*0.6f; + } + else colSeaGlow.a=0.0f; + for(i=1; iTimer_GetTime(); + a*=20; + for(j=0; jSetColor(j, i, dwCol1); + dy=a*sinf(seaP[i]+(float(j)/(SeaDisize-1)-0.5f)*pi*16.0f-fTime); + sea->SetDisplacement(j, i, 0.0f, dy, HGEDISP_NODE); + } + } + float t=0.1*hge->Timer_GetTime(); + skylyr->SetTextureRect(128+sin(t)*128.0f,256+cos(t)*128.0f,256,128); + if (skyOnFadeIn)SkyDoFadeIn(); + if (skyOnFadeOut)SkyDoFadeOut(); + for (int i=-8;i<8;++i) + for (int j=-8;j<8;++j) + { + skylyr->SetColor(j+8,i+8,ARGB((int)(skya*((i+9)*16-16)),0xFF,0xFF,0xFF)); + skylyr->SetDisplacement(j+8,i+8,j*(16.0f*((i+9)/16.0f)+64.0f),i*24,HGEDISP_CENTER); + } + dwCol1=colSeaTop.GetHWColor(); + dwCol2=colSeaBtm.GetHWColor(); + for(j=0; jSetColor(j, 0, dwCol1); + sea->SetColor(j, SeaDisize-1, dwCol2); + } + if(timet>19.0f || timet<5.0f) + { + a=0.12f; + if(timet>19.0f && timet<20.0f) a*=(timet-19.0f); + else if(timet>4.0f && timet<5.0f) a*=1.0f-(timet-4.0f); + posX=moonX; + } + else if(timet>7.0f && timet<17.0f) + { + a=0.14f; + if(timet<8.0f) a*=(timet-7.0f); + else if(timet>16.0f) a*=1.0f-(timet-16.0f); + posX=sunX; + } + else a=0.0f; + if(a!=0.0f) + { + k=(int)floorf(posX/cellw); + s1=(1.0f-(posX-k*cellw)/cellw); + s2=(1.0f-((k+1)*cellw-posX)/cellw); + if(s1>0.7f) s1=0.7f; + if(s2>0.7f) s2=0.7f; + s1*=a;s2*=a; + for(i=0; iGetColor(k,i)); + col1+=colSun*s1*(1-a); + col1.Clamp(); + sea->SetColor(k, i, col1.GetHWColor()); + col1.SetHWColor(sea->GetColor(k+1,i)); + col1+=colSun*s2*(1-a); + col1.Clamp(); + sea->SetColor(k+1, i, col1.GetHWColor()); + } + } + } + void Render() + { + sky->SetColor(colSkyTop.GetHWColor(), 0); + sky->SetColor(colSkyTop.GetHWColor(), 1); + sky->SetColor(colSkyBtm.GetHWColor(), 2); + sky->SetColor(colSkyBtm.GetHWColor(), 3); + sky->Render(0, 0); + if(seq_id>=6 || seq_id<2) + for(int i=0; iSetColor((DWORD(starA[i]*255.0f)<<24) | 0xFFFFFF); + star->RenderEx(starX[i], starY[i], 0.0f, starS[i]); + } + glow->SetColor(colSunGlow.GetHWColor()); + glow->RenderEx(sunX, sunY, 0.0f, sunGlowS); + sun->SetColor(colSun.GetHWColor()); + sun->RenderEx(sunX, sunY, 0.0f, sunS); + glow->SetColor(colMoonGlow.GetHWColor()); + glow->RenderEx(moonX, moonY, 0.0f, moonGlowS); + moon->SetColor(colMoon.GetHWColor()); + moon->RenderEx(moonX, moonY, 0.0f, moonS); + sea->Render(0, SkyHeight); + seaglow->SetColor(colSeaGlow.GetHWColor()); + seaglow->RenderEx(seaGlowX, SkyHeight, 0.0f, seaGlowSX, seaGlowSY); + skylyr->Render(ScreenWidth/8*3,ScreenHeight/3*2); } }; -TDClouds Sky; +TDSky sky; DWORD ColorTransfer(DWORD a,DWORD t) { -- cgit v1.2.3