📄 main.cpp
字号:
{ svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row][bricknum+1]].hit(fxMan,spos,svel); } } if(row > 0) { if(nbrick[row-1][bricknum] != -1) { svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row-1][bricknum]].hit(fxMan,spos,svel); } } if(row < 22) { if(nbrick[row+1][bricknum] != -1) { svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row+1][bricknum]].hit(fxMan,spos,svel); } } if(row > 0 && bricknum > 0) { if(nbrick[row-1][bricknum-1] != -1) { svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row-1][bricknum-1]].hit(fxMan,spos,svel); } } if(row > 0 && bricknum < 25) { if(nbrick[row-1][bricknum+1] != -1) { svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row-1][bricknum+1]].hit(fxMan,spos,svel); } } if(row < 22 && bricknum > 0) { if(nbrick[row+1][bricknum-1] != -1) { svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row+1][bricknum-1]].hit(fxMan,spos,svel); } } if(row < 22 && bricknum < 25) { if(nbrick[row+1][bricknum+1] != -1) { svel.x=rndflt(2,0)/3.0; svel.y=rndflt(2,0)/3.0; bricks[nbrick[row+1][bricknum+1]].hit(fxMan,spos,svel); } } } } tex.play(); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, -3.0 ); glTranslatef( posx, posy, 0); glColor4f( color[0], color[1], color[2], opacity ); glBindTexture(GL_TEXTURE_2D, tex.prop.texture); glBegin( GL_QUADS ); glTexCoord2f(tex.pos[0],tex.pos[1]);glVertex3f( -0.0616*zoom, 0.035*zoom, 0.00 ); // øverst venst glTexCoord2f(tex.pos[2],tex.pos[3]);glVertex3f( 0.0616*zoom, 0.035*zoom, 0.00 ); // øverst højre glTexCoord2f(tex.pos[4],tex.pos[5]);glVertex3f( 0.0616*zoom,-0.035*zoom, 0.00 ); // nederst højre glTexCoord2f(tex.pos[6],tex.pos[7]);glVertex3f( -0.0616*zoom,-0.035*zoom, 0.00 ); // nederst venstre glEnd( ); }};#include "loadlevel.cpp"class moving_object : public object { public: GLfloat xvel,yvel,velocity; moving_object () { xvel=0.0; yvel=0.0; }};#include "effects.cpp"#include "background.cpp"void spawnpowerup(char powerup, pos a, pos b);class bulletsClass { private: moving_object bullets[16]; public: bulletsClass(textureClass & texBullet) { int i; for(i=0; i < 16; i++) { bullets[i].active=0; bullets[i].tex = texBullet; bullets[i].width = 0.02; bullets[i].height = 0.02; } } void shoot(pos p) { int i; //Find ledig bullet for(i=0; i < 16; i++) { if(!bullets[i].active) { bullets[i].active=1; bullets[i].posx = p.x; bullets[i].posy = p.y; bullets[i].xvel =0; bullets[i].yvel =1.0; break; } } } void move() { int i; for(i=0; i < 16; i++) { if(bullets[i].active) { //Flyt bullets[i].posy += bullets[i].yvel * globalMilliTicks; } } } void draw() { int i; glColor4f(1,1,1,1); for(i=0; i < 16; i++) { if(bullets[i].active) { //draw bullets[i].tex.play(); glLoadIdentity(); glTranslatef( bullets[i].posx, bullets[i].posy, -3.0 ); glBindTexture(GL_TEXTURE_2D, bullets[i].tex.prop.texture); glBegin( GL_QUADS ); glTexCoord2f(bullets[i].tex.pos[0],bullets[i].tex.pos[1]); glVertex3f( -bullets[i].width, bullets[i].height, 0.0 ); glTexCoord2f(bullets[i].tex.pos[2],bullets[i].tex.pos[3]); glVertex3f( bullets[i].width, bullets[i].height, 0.0 ); glTexCoord2f(bullets[i].tex.pos[4],bullets[i].tex.pos[5]); glVertex3f( bullets[i].width,-bullets[i].height, 0.0 ); glTexCoord2f(bullets[i].tex.pos[6],bullets[i].tex.pos[7]); glVertex3f( -bullets[i].width,-bullets[i].height, 0.0 ); glEnd( ); } } } void coldet(brick & b, effectManager & fxMan) { int i; bool hit; pos v,p; v.x=0; v.y=bullets[0].xvel; for(i=0; i < 16; i++) { if(bullets[i].active) { hit=0; //y if(bullets[i].posy+bullets[i].height/10.0 > b.posy-b.height && bullets[i].posy+bullets[i].height/10.0 < b.posy+b.height) { p.x = b.posx; p.y = b.posy; //Venstre side: if(bullets[i].posx > b.posx-b.width && bullets[i].posx < b.posx+b.width) { hit=1; } if(hit) { b.hit(fxMan, p, v); if(!player.powerup[PO_THRU]) { bullets[i].active=0; } p.x = bullets[i].posx; p.y = bullets[i].posy; if(setting.eyeCandy) { fxMan.set(FX_VAR_TYPE, FX_SPARKS); fxMan.set(FX_VAR_COLDET,1); fxMan.set(FX_VAR_LIFE, 1000); fxMan.set(FX_VAR_NUM, 16); fxMan.set(FX_VAR_SIZE, 0.015f); fxMan.set(FX_VAR_SPEED, 0.4f); fxMan.set(FX_VAR_GRAVITY, 1.0f); fxMan.set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f); fxMan.spawn(p); fxMan.set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f); fxMan.spawn(p); fxMan.set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f); fxMan.spawn(p); fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f); fxMan.spawn(p); } } } else if(bullets[i].posy > 1.6) { bullets[i].active=0; } } } }};void brick::hit(effectManager & fxMan, pos poSpawnPos, pos poSpawnVel){ pos p; //Afgør hvad der skal ske med denne brik udfra dens type og powerup egenskaber. //Hvis det ikke er en type 3, ELLER hvis der er powerup if(type != '3' || player.powerup[PO_THRU]) { player.score += score; hitsLeft--; if(hitsLeft < 1 || type == 'B') //Hvis brikken er explosiv kan den ikke have nogle hits tilbage { collide=0; nbrick[row][bricknum]=-1; gVar.deadTime=0; spawnpowerup(powerup, poSpawnPos, poSpawnVel); if(setting.eyeCandy) { p.x = posx; p.y = posy; fxMan.set(FX_VAR_TYPE, FX_SPARKS); fxMan.set(FX_VAR_COLDET,1); fxMan.set(FX_VAR_LIFE, 1500); fxMan.set(FX_VAR_NUM, 16); fxMan.set(FX_VAR_SIZE, 0.025f); fxMan.set(FX_VAR_SPEED, -0.6f); fxMan.set(FX_VAR_COLOR, color[0],color[1],color[2]); fxMan.set(FX_VAR_GRAVITY, 0.6f); fxMan.spawn(p); } if(type=='B') { isexploding=1; if(setting.eyeCandy) { p.x = posx; p.y = posy; fxMan.set(FX_VAR_TYPE, FX_SPARKS); fxMan.set(FX_VAR_COLDET,1); fxMan.set(FX_VAR_LIFE, 1000); fxMan.set(FX_VAR_NUM, 16); fxMan.set(FX_VAR_SIZE, 0.1f); fxMan.set(FX_VAR_SPEED, 0.4f); fxMan.set(FX_VAR_GRAVITY, -1.0f); fxMan.set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f); fxMan.spawn(p); fxMan.set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f); fxMan.spawn(p); fxMan.set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f); fxMan.spawn(p); fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f); fxMan.spawn(p); } } else { isdyingnormally=1; } } else { //No hits left tex.frame++; tex.play(); } //Hits left }}glAnnounceTextClass announce;//Slet mig måskefloat abs2(float x){ if (x<0) {return -x;} return x;}int LinesCross(float x0,float y0,float x1,float y1,float x2,float y2,float x3,float y3, float *linx, float *liny){ float d=(x1-x0)*(y3-y2)-(y1-y0)*(x3-x2); if (abs2(d)<0.001f) {return -1;} float AB=((y0-y2)*(x3-x2)-(x0-x2)*(y3-y2))/d; if (AB>0.0 && AB<1.0) { float CD=((y0-y2)*(x1-x0)-(x0-x2)*(y1-y0))/d; if (CD>0.0 && CD<1.0) { *linx=x0+AB*(x1-x0); *liny=y0+AB*(y1-y0); return 1; } } return 0;}//Leaves an trail of the ballclass tracer { private: GLfloat x[100], y[100], r[100], g[100], b[100], a[100],s[100], cr,cg,cb,; bool active[100]; int color; GLfloat lastX, lastY; //Last position where we spawned one public: GLfloat height, width; GLuint texture; int len; void draw() { int i; for(i=0; i < len; i++) { if(active[i]) { a[i] -= 4.0*globalMilliTicks; s[i] += 4.0*globalMilliTicks; if(a[i] < 0.0) active[i]=0; glBindTexture( GL_TEXTURE_2D, texture); glLoadIdentity(); glTranslatef(x[i],y[i],-3.0); glColor4f(r[i], g[i], b[i], a[i]); glBegin( GL_QUADS ); glTexCoord2f(0.0, 0.0);glVertex3f( -width*s[i], height*s[i], 0.00 ); // øverst venst glTexCoord2f(0.0, 1.0);glVertex3f( width*s[i], height*s[i], 0.00 ); // øverst højre glTexCoord2f(1.0, 1.0);glVertex3f( width*s[i],-height*s[i], 0.00 ); // nederst højre glTexCoord2f(1.0, 0.0);glVertex3f( -width*s[i],-height*s[i], 0.00 ); // nederst venstre glEnd( ); } } } void colorRotate(bool explosive, GLfloat c[]) { color++; if(color > 5) color=0; if(!explosive) { cr=c[0]; cg=c[1]; cb=c[2]; } else { cr=1.0; cg=0.6; cb=0.0; } } tracer() { len=100; lastX=0; lastY=0; cr=1; cg=0; cb=0; height = 0.01; width = 0.01; int i; for(i=0; i < 100; i++) { active[i]=0; } } void update(GLfloat nx, GLfloat ny) { //If long enough away GLfloat dist = sqrt( pow(nx-lastX, 2) + pow(ny-lastY, 2) ); if(dist > 0.01) { lastX = nx; lastY = ny; //Find en ledig int i; for(i=0; i < len; i++) { if(!active[i]) { active[i]=1; a[i]=1.0; //tweak me x[i]=nx; y[i]=ny; s[i]=1.0; r[i]=cr; g[i]=cg; b[i]=cb; break; } } } }};class ball : public moving_object { private: GLfloat rad; bool growing,shrinking; GLfloat destwidth, growspeed; tracer tail; public: int died; //When did this ball get gravity? bool gravity; //did we get gravity bool explosive; //Makes brick explosive (to get a explosion effect) and explode it bool glued; //Sidder vi fast på padden for øjeblikket? GLfloat gluedX; //Variabler med forududregnede værdier GLfloat bsin[32], bcos[32]; bool aimdir; textureClass fireTex, texTail; GLfloat lastX,lastY; ball() { growing=0; growspeed=0.1; width=0.0; height=0.0; glued=0; posx=0.0f; posy=0.0f; setSize(0.02); aimdir=0; } void hit(pos p, GLfloat c[]) { if(gravity) { yvel /= 1.4; xvel /= 1.01; posy = p.y+height; if(globalTicks-died > 6000) { active=0; } } if(setting.eyeCandy) tail.colorRotate(explosive, c); } void move() { //vi laver lige den her coldet her... if(posx+width > 1.6 && xvel > 0.0) { xvel *= -1; } else if(posx-width < -1.6 && xvel < 0.0) { xvel *= -1; } else if(posy+width > 1.25 && yvel > 0.0) { yvel *= -1; } else if(posy-width < -1.24) { active=0; } if(gravity) { if(yvel != 0) yvel -= 0.6*globalMilliTicks; } posx +=xvel*globalMilliTicks; if(!glued) { posy +=yvel*globalMilliTicks; } else { gVar.deadTime = 0; } if(setting.eyeCandy) tail.update(posx,posy); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -