Sliding.cpp
上传用户:sz83729876
上传日期:2013-03-07
资源大小:4140k
文件大小:4k
- #include "../../main.h"
- #include "sliding.h"
- #include "core.cpp"
- #include "rendering.cpp"
- extern NIMG Sliding;
- GLuint texture[1];
- GLfloat xpos=0;
- GLuint base;
- GLfloat fMove=0;
- GLfloat rot=0;
- BYTE map[50][41];
- GLfloat brmap[50][41];
- GLint nmap[50][41];
- GLuint speedmap[50][2];
- UINT Tick1=0, Tick2=0; // used to help keep speed constant
- UINT DTick;
- namespace sliding
- {
- void Init() {
- LoadLevel();
- }
-
- GLvoid glSetChar(unsigned char ch)
- {
- glCallList(base+ch);
- }
- void RenderLevelScene()
- {
- // glClear(GL_COLOR_BUFFER_BIT );
- // glLoadIdentity();
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- glColor4f(0,0.5f,0,0.75f);
- glTranslatef(-20,-20,-36+fMove);
-
- for(int y=0;y<40;y++)
- {
- for(int x=0;x<50;x++)
- {
- if(brmap[x][y]<0.75f)
- {
- glColor4f(0,0.5f,0,brmap[x][y]);
- }
- else
- {
- glColor4f(brmap[x][y]/2,brmap[x][y],brmap[x][y]/2,0.75f);
- }
- glSetChar(map[x][y]);
- glTranslatef(0,0,40);
- glSetChar(map[x][y]);
- glTranslatef(0,0,40);
- glSetChar(map[x][y]);
- glTranslatef(0,0,40);
- glSetChar(map[x][y]);
- glTranslatef(0,0,40);
- glSetChar(map[x][y]);
- glTranslatef(0,0,40);
- glSetChar(map[x][y]);
- glTranslatef(0.8,0,-200);
- }
- glTranslatef(-40,1,0);
- }
-
- // SwapBuffers(g_hDC);
- }
- GLvoid BuildFont(GLvoid)
- {
- base = glGenLists(256);
- float cx;
- float cy;
- for(GLuint loop=0; loop<256; loop++)
- {
- cx=float(loop%16)/16.0f;
- cy=float(loop/16)/16.0f;
- glNewList(base+loop,GL_COMPILE);
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f(cx,1-cy-0.0625f);
- glVertex3f(0,0,0);
- glTexCoord2f(cx+0.0625f,1-cy-0.0625f);
- glVertex3f(1,0,0);
- glTexCoord2f(cx,1-cy);
- glVertex3f(0,1,0);
- glTexCoord2f(cx+0.0625f,1-cy);
- glVertex3f(1,1,0);
- glEnd();
- glEndList();
- }
- }
- GLvoid KillFont(GLvoid)
- {
- glDeleteLists(base, 256);
- }
- void UnloadLevelTextures()
- {
- glDeleteTextures (1, &texture[0]);
- KillFont();
- }
- void LoadLevelTextures()
- {
- texture[0] = Sliding.ID;
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- BuildFont();
- }
- void LoadLevel()
- {
- srand( (unsigned)time( NULL ) );
- LoadLevelTextures();
- for(int y=0;y<40;y++)
- for(int x=0;x<50;x++)
- {
- int i=rand()%10;
- if(i<2)
- map[x][y]=0;
- else
- map[x][y]=rand()%256;
- brmap[x][y]=0.35f+float(rand()%51)/100;
- nmap[x][y]=(rand()%5)-2;
- speedmap[x][0]=1+rand()%5;
- speedmap[x][1]=0;
- }
- Tick1 = GetTickCount ( );
- Tick2 = GetTickCount ( );
- }
- void UnloadLevel()
- {
- UnloadLevelTextures();
- }
- void ProcessLevel()
- {
- Tick1 = Tick2;
- Tick2 = GetTickCount ( );
- DTick += Tick2 - Tick1;
- fMove-=0.005f*float(Tick2 - Tick1);
- // DTick += 30;
- // fMove-=0.005f*float(30);
- // rot+=0.05f*float(Tick2 - Tick1);
- if(fMove<-200.0f)
- fMove=-120.0f;
-
- if(DTick>25)
- {
- DTick-=25;
- for(int x=0;x<50;x++)
- {
- int m;
- speedmap[x][1]++;
- if(speedmap[x][1]>speedmap[x][0])
- {
- speedmap[x][1]=0;
- m=1;
- }
- else
- m=0;
- for(int y=0;y<40;y++)
- {
- if(m)
- {
- map[x][y]=map[x][y+1];
- brmap[x][y]=brmap[x][y+1];
- nmap[x][y]=nmap[x][y+1];
- }
- brmap[x][y]+=(float(nmap[x][y])*0.01f);
- if(brmap[x][y]>0.95f || brmap[x][y]<0.05f)
- nmap[x][y]=nmap[x][y]*(-1);
- }
-
- }
- for(x=0;x<50;x++)
- {
- int i=rand()%1000;
- if(i<300)
- {
- map[x][40]=0;
- if((rand()%10)<2)
- speedmap[x][0]=1+rand()%5;
- }
- else
- {
- if(i==300 && x<40)
- {
- int f=(rand()%5)-2;
- brmap[x][40]=1.0f;
- nmap[x][40]=f;
- map[x++][40]='A';
- brmap[x][40]=1.0f;
- nmap[x][40]=f;
- map[x++][40]='R';
- brmap[x][40]=1.0f;
- nmap[x][40]=f;
- map[x++][40]='R';
- brmap[x][40]=1.0f;
- nmap[x][40]=f;
- map[x++][40]='O';
- brmap[x][40]=1.0f;
- nmap[x][40]=f;
- map[x][40]='W';
- }
- else
- {
- map[x][40]=rand()%256;
- brmap[x][40]=0.35f+float(rand()%51)/100;
- nmap[x][40]=(rand()%5)-2;
- }
- }
- }
- }
- RenderLevelScene();
- }
- }