📄 background.cpp
字号:
/* ************************************************************************* * SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux Copyright (C) 2008 DusteD.dk This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. * ************************************************************************* */class backgroundClass { private: GLfloat rot, zoom,zoomb; GLfloat r[12], g[12], b[12], a[12]; textureClass tex; bool dir; bool firstTexture; public: backgroundClass() { initb(); firstTexture=1; } void init(textureManager & texMgr) { //Så vi ikke kommer til at slette texture 0 første gang funktionen bliver kaldt if(!firstTexture) glDeleteTextures(1, &tex.prop.texture); float t = 0.25 * ((float)player.level+1); if(t <= 1.0) texMgr.load("data/gfx/bg/1.png", tex); else if(t <= 2.0) texMgr.load("data/gfx/bg/2.png", tex); else if(t <= 3.0) texMgr.load("data/gfx/bg/3.png", tex); else if(t <= 4.0) texMgr.load("data/gfx/bg/4.png", tex); else if(t <= 5.0) texMgr.load("data/gfx/bg/5.png", tex); else if(t <= 6.0) texMgr.load("data/gfx/bg/6.png", tex); else if(t <= 7.0) texMgr.load("data/gfx/bg/7.png", tex); else if(t <= 8.0) texMgr.load("data/gfx/bg/8.png", tex); else if(t <= 9.0) texMgr.load("data/gfx/bg/9.png", tex); else if(t <= 10.0) texMgr.load("data/gfx/bg/10.png", tex); else if(t <= 11.0) texMgr.load("data/gfx/bg/11.png", tex); else if(t <= 12.0) texMgr.load("data/gfx/bg/12.png", tex); else if(t <= 13.0) texMgr.load("data/gfx/bg/13.png", tex); else if(t <= 14.0) texMgr.load("data/gfx/bg/14.png", tex); else if(t <= 15.0) texMgr.load("data/gfx/bg/15.png", tex); else if(t <= 16.0) texMgr.load("data/gfx/bg/16.png", tex); else if(t <= 17.0) texMgr.load("data/gfx/bg/17.png", tex); else if(t <= 18.0) texMgr.load("data/gfx/bg/18.png", tex); else if(t <= 19.0) texMgr.load("data/gfx/bg/19.png", tex); else if(t <= 20.0) texMgr.load("data/gfx/bg/20.png", tex); else if(t <= 21.0) texMgr.load("data/gfx/bg/21.png", tex); else if(t <= 22.0) texMgr.load("data/gfx/bg/22.png", tex); else if(t <= 23.0) texMgr.load("data/gfx/bg/23.png", tex); else if(t <= 24.0) texMgr.load("data/gfx/bg/24.png", tex); else if(t <= 25.0) texMgr.load("data/gfx/bg/25.png", tex); else texMgr.load("data/gfx/bg/final.png", tex); firstTexture=0; initb(); } void initb() { int i; for(i = 0; i < 4; i++) { r[i] = rndflt(1,0); g[i] = rndflt(1,0); b[i] = rndflt(1,0); a[i] = 1; } for(i = 4; i < 12; i++) { r[i] = rndflt(1,0); g[i] = rndflt(1,0); b[i] = rndflt(1,0); a[i] = 0.6; } rot=0; zoom=1.0; zoomb=1.0; dir=1; } void draw() { glLoadIdentity(); glTranslatef( 0, 0, -3.0 ); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, tex.prop.texture); glBegin( GL_QUADS ); glColor4f(r[0],g[0],b[0],a[0]); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.66, 1.25, 0.0f ); glColor4f(r[1],g[1],b[1],a[1]); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.66, 1.25, 0.0f ); glColor4f(r[2],g[2],b[2],a[2]); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.66,-1.25, 0.0f ); glColor4f(r[3],g[3],b[3],a[3]); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.66,-1.25, 0.0f ); glEnd( ); if(setting.eyeCandy) { if(dir) { zoomb+= globalTicks/200000.0; zoom += globalTicks/400000.0; } else { zoomb-= globalTicks/100000.0; zoom -= globalTicks/200000.0; } if(zoomb > 2.0) dir=0; if(zoomb < 1.0) dir=1; glBegin( GL_QUADS ); glColor4f(r[4],g[4],b[4],a[4]); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.66*zoom, 1.25*zoom, 0.0f ); glColor4f(r[5],g[5],b[5],a[5]); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.66*zoom, 1.25*zoom, 0.0f ); glColor4f(r[6],g[6],b[6],a[6]); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.66*zoom,-1.25*zoom, 0.0f ); glColor4f(r[7],g[7],b[7],a[7]); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.66*zoom,-1.25*zoom, 0.0f ); glEnd( ); glBegin( GL_QUADS ); glColor4f(r[8],g[8],b[8],a[8]); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.66*zoomb, 1.25*zoomb, 0.0f ); glColor4f(r[9],g[9],b[9],a[9]); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.66*zoomb, 1.25*zoomb, 0.0f ); glColor4f(r[10],g[10],b[10],a[10]); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.66*zoomb,-1.25*zoomb, 0.0f ); glColor4f(r[11],g[11],b[11],a[11]); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.66*zoomb,-1.25*zoomb, 0.0f ); glEnd( ); } }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -