📄 main.cpp
字号:
void move() { //grav yvel -= gravity*globalMilliTicks; //cout << yvel << endl; posx +=xvel*globalMilliTicks; posy +=yvel*globalMilliTicks; } void coldet(paddle_class & p, effectManager & fxMan, ballManager & bMan) { 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; } //idiotisk lavet... bool ycol=0; bool xcol=0; pos fxpos; //En side if(posx+width > p.posx-p.width && posx+width < p.posx+p.width) { xcol=1; } if(posx-width > p.posx-p.width && posx-width < p.posx+p.width) { xcol=1; } if(posy-height < p.posy+p.height && posy-height > p.posy-p.height) { ycol=1; } if(posy+height < p.posy+p.height && posy+height > p.posy-p.height) { ycol=1; } if(xcol && ycol) { if(setting.eyeCandy) { fxpos.x = posx; fxpos.y = posy; fxMan.set(FX_VAR_TYPE, FX_SPARKS); fxMan.set(FX_VAR_COLDET,1); fxMan.set(FX_VAR_SPEED, yvel/1.2f); fxMan.set(FX_VAR_LIFE, 1500); fxMan.set(FX_VAR_GRAVITY, 0.7f); fxMan.set(FX_VAR_NUM, 16); fxMan.set(FX_VAR_SIZE, 0.015f); fxMan.set(FX_VAR_COLOR, color[0], color[1], color[2]); fxMan.spawn(fxpos); } active=0; //Score player.score += score; //Apply powerup: switch(type) { case PO_GLUE: if(!player.powerup[PO_GLUE]) { player.powerup[PO_GLUE] = 1; announce.write("Glue!",1000, fonts[1]); } break; case PO_BIGBALL: bMan.powerup(PO_BIGBALL); player.powerup[PO_BIGBALL]=1; player.powerup[PO_NORMALBALL]=0; player.powerup[PO_SMALLBALL]=0; break; case PO_NORMALBALL: bMan.powerup(PO_NORMALBALL); player.powerup[PO_NORMALBALL]=1; player.powerup[PO_BIGBALL]=0; player.powerup[PO_SMALLBALL]=0; break; case PO_SMALLBALL: bMan.powerup(PO_SMALLBALL); player.powerup[PO_SMALLBALL]=1; player.powerup[PO_BIGBALL]=0; player.powerup[PO_NORMALBALL]=0; break; case PO_GRAVITY: bMan.powerup(PO_GRAVITY); announce.write("Gravity!",1100, fonts[1]); break; case PO_MULTIBALL: bMan.multiply(); announce.write("Multiball!",1200, fonts[1]); break; case PO_AIM: if(player.difficulty==0) { player.powerup[PO_GLUE]=1; } if(!player.powerup[PO_AIM]) { player.powerup[PO_AIM]=1; player.powerup[PO_LASER]=1; announce.write("Aim!",1300, fonts[1]); } else { if(!player.powerup[PO_GLUE]) { player.powerup[PO_GLUE]=1; } } break; case PO_GROWPADDLE: if(p.width < 0.4) p.grow(p.width+0.02); break; case PO_SHRINKPADDLE: if(p.width > 0.02) p.grow(p.width-0.02); break; case PO_EXPLOSIVE: if(!player.powerup[PO_EXPLOSIVE]) { bMan.powerup(PO_EXPLOSIVE); player.powerup[PO_EXPLOSIVE]=1; announce.write("Explosive!",1300, fonts[1]); } break; case PO_GUN: if(!player.powerup[PO_GUN]) { player.powerup[PO_GUN]=1; announce.write("Gun!", 1400, fonts[1]); } break; case PO_THRU: if(!player.powerup[PO_THRU]) { player.powerup[PO_THRU]=1; announce.write("Heavy!", 1300, fonts[1]); } break; case PO_LASER: if(!player.powerup[PO_LASER]) { player.powerup[PO_LASER]=1; announce.write("Laser!", 1200, fonts[1]); } } } } void draw() { tex.play(); glBindTexture( GL_TEXTURE_2D, tex.prop.texture); glColor4f(1.0, 1.0, 1.0, 1.0); glLoadIdentity(); glTranslatef( posx, posy, -3.0f); glBegin( GL_QUADS ); glTexCoord2f(tex.pos[0],tex.pos[1]);glVertex3f( -width, height, 0.00 ); // øverst venst glTexCoord2f(tex.pos[2],tex.pos[3]);glVertex3f( width, height, 0.00 ); // øverst højre glTexCoord2f(tex.pos[4],tex.pos[5]);glVertex3f( width,-height, 0.00 ); // nederst højre glTexCoord2f(tex.pos[6],tex.pos[7]);glVertex3f( -width,-height, 0.00 ); // nederst venstre glEnd( ); }};#define MAXPOWERUPS 64#define MAXPOTEXTURES 20class powerupManager { private: int i; powerupClass p[MAXPOWERUPS]; textureClass* tex; public: void init(textureClass texPowerup[]) { //Sætter textures op for de forskellige powerups //Poweruptextures //Glue texPowerup[PO_GLUE].prop.frames = 4; texPowerup[PO_GLUE].prop.ticks = 100; texPowerup[PO_GLUE].prop.rows= 2; texPowerup[PO_GLUE].prop.cols= 2; texPowerup[PO_GLUE].prop.xoffset=0.5; texPowerup[PO_GLUE].prop.yoffset=0.5; texPowerup[PO_GLUE].prop.playing=1; //gravity texPowerup[PO_GRAVITY].prop.frames = 4; texPowerup[PO_GRAVITY].prop.ticks = 80; texPowerup[PO_GRAVITY].prop.rows= 2; texPowerup[PO_GRAVITY].prop.cols= 2; texPowerup[PO_GRAVITY].prop.xoffset=0.5; texPowerup[PO_GRAVITY].prop.yoffset=0.5; texPowerup[PO_GRAVITY].prop.bidir=0; texPowerup[PO_GRAVITY].prop.playing=1; //multiball texPowerup[PO_MULTIBALL].prop.frames = 1; texPowerup[PO_MULTIBALL].prop.ticks = 1000; texPowerup[PO_MULTIBALL].prop.rows= 1; texPowerup[PO_MULTIBALL].prop.cols= 1; texPowerup[PO_MULTIBALL].prop.xoffset=1.0; texPowerup[PO_MULTIBALL].prop.yoffset=1.0; texPowerup[PO_MULTIBALL].prop.bidir=0; texPowerup[PO_MULTIBALL].prop.playing=0; //bigball texPowerup[PO_BIGBALL].prop.frames = 4; texPowerup[PO_BIGBALL].prop.ticks = 200; texPowerup[PO_BIGBALL].prop.rows= 2; texPowerup[PO_BIGBALL].prop.cols= 2; texPowerup[PO_BIGBALL].prop.xoffset=0.5; texPowerup[PO_BIGBALL].prop.yoffset=0.5; texPowerup[PO_BIGBALL].prop.bidir=0; texPowerup[PO_BIGBALL].prop.playing=1; //normalball texPowerup[PO_NORMALBALL].prop.frames = 1; texPowerup[PO_NORMALBALL].prop.ticks = 200; texPowerup[PO_NORMALBALL].prop.rows= 2; texPowerup[PO_NORMALBALL].prop.cols= 2; texPowerup[PO_NORMALBALL].prop.xoffset=0.5; texPowerup[PO_NORMALBALL].prop.yoffset=0.5; texPowerup[PO_NORMALBALL].prop.bidir=0; texPowerup[PO_NORMALBALL].prop.playing=1; //smallball texPowerup[PO_SMALLBALL].prop.frames = 4; texPowerup[PO_SMALLBALL].prop.ticks = 200; texPowerup[PO_SMALLBALL].prop.rows= 2; texPowerup[PO_SMALLBALL].prop.cols= 2; texPowerup[PO_SMALLBALL].prop.xoffset=0.5; texPowerup[PO_SMALLBALL].prop.yoffset=0.5; texPowerup[PO_SMALLBALL].prop.bidir=0; texPowerup[PO_SMALLBALL].prop.playing=1; //Aim texPowerup[PO_AIM].prop.frames = 4; texPowerup[PO_AIM].prop.ticks = 200; texPowerup[PO_AIM].prop.rows= 2; texPowerup[PO_AIM].prop.cols= 2; texPowerup[PO_AIM].prop.xoffset=0.5; texPowerup[PO_AIM].prop.yoffset=0.5; texPowerup[PO_AIM].prop.bidir=1; texPowerup[PO_AIM].prop.playing=1; //Growpaddle texPowerup[PO_GROWPADDLE].prop.frames = 4; texPowerup[PO_GROWPADDLE].prop.ticks = 200; texPowerup[PO_GROWPADDLE].prop.rows= 2; texPowerup[PO_GROWPADDLE].prop.cols= 2; texPowerup[PO_GROWPADDLE].prop.xoffset=0.5; texPowerup[PO_GROWPADDLE].prop.yoffset=0.5; texPowerup[PO_GROWPADDLE].prop.bidir=0; texPowerup[PO_GROWPADDLE].prop.playing=1; //Shrinkpaddle texPowerup[PO_SHRINKPADDLE].prop.frames = 4; texPowerup[PO_SHRINKPADDLE].prop.ticks = 200; texPowerup[PO_SHRINKPADDLE].prop.rows= 2; texPowerup[PO_SHRINKPADDLE].prop.cols= 2; texPowerup[PO_SHRINKPADDLE].prop.xoffset=0.5; texPowerup[PO_SHRINKPADDLE].prop.yoffset=0.5; texPowerup[PO_SHRINKPADDLE].prop.bidir=0; texPowerup[PO_SHRINKPADDLE].prop.playing=1; //Explosive texPowerup[PO_EXPLOSIVE].prop.frames = 4; texPowerup[PO_EXPLOSIVE].prop.ticks = 100; texPowerup[PO_EXPLOSIVE].prop.rows= 2; texPowerup[PO_EXPLOSIVE].prop.cols= 2; texPowerup[PO_EXPLOSIVE].prop.xoffset=0.5; texPowerup[PO_EXPLOSIVE].prop.yoffset=0.5; texPowerup[PO_EXPLOSIVE].prop.bidir=1; texPowerup[PO_EXPLOSIVE].prop.playing=1; //Gun texPowerup[PO_GUN].prop.frames = 4; texPowerup[PO_GUN].prop.ticks = 80; texPowerup[PO_GUN].prop.rows= 2; texPowerup[PO_GUN].prop.cols= 2; texPowerup[PO_GUN].prop.xoffset=0.5; texPowerup[PO_GUN].prop.yoffset=0.5; texPowerup[PO_GUN].prop.bidir=0; texPowerup[PO_GUN].prop.playing=1; //Gun texPowerup[PO_THRU].prop.frames = 1; texPowerup[PO_THRU].prop.ticks = 1000; texPowerup[PO_THRU].prop.rows= 1; texPowerup[PO_THRU].prop.cols= 1; texPowerup[PO_THRU].prop.xoffset=1; texPowerup[PO_THRU].prop.yoffset=1; texPowerup[PO_THRU].prop.bidir=0; texPowerup[PO_THRU].prop.playing=0; //Laser texPowerup[PO_LASER].prop.frames = 1; texPowerup[PO_LASER].prop.ticks = 1000; texPowerup[PO_LASER].prop.rows= 1; texPowerup[PO_LASER].prop.cols= 1; texPowerup[PO_LASER].prop.xoffset=1; texPowerup[PO_LASER].prop.yoffset=1; texPowerup[PO_LASER].prop.bidir=0; texPowerup[PO_LASER].prop.playing=0; tex = new textureClass[40]; tex = texPowerup; } powerupManager() { clear(); } /*~powerupManager() { if(tex != NULL) { delete[] tex; } }*/ void clear() { for(i=0; i < MAXPOWERUPS; i++) { p[i].active=0; } } void spawn(pos spawnpos, pos velocity, int type) { for(i=0; i < MAXPOWERUPS; i++) { if(!p[i].active) { p[i].gravity = 0.7; p[i].type = type; p[i].posx = spawnpos.x; p[i].posy = spawnpos.y; p[i].xvel = velocity.x*-1; p[i].yvel = velocity.y*-1; p[i].active=1; //set textur alt efter type if(type==PO_GLUE) { p[i].tex=tex[PO_GLUE]; p[i].score = 50; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_GRAVITY) { p[i].score = -60; p[i].tex=tex[PO_GRAVITY]; p[i].color[0]=1.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_MULTIBALL) { p[i].score = 20; p[i].tex = tex[PO_MULTIBALL]; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_BIGBALL) { p[i].score = 30; p[i].tex = tex[PO_BIGBALL]; p[i].color[0]=0.0f; p[i].color[1]=0.0f; p[i].color[2]=1.0f; } if(type==PO_NORMALBALL) { p[i].score = 40; p[i].tex=tex[PO_NORMALBALL]; p[i].color[0]=0.0f; p[i].color[1]=0.0f; p[i].color[2]=1.0f; } if(type==PO_SMALLBALL) { p[i].score = 60; p[i].tex=tex[PO_SMALLBALL]; p[i].color[0]=0.0f; p[i].color[1]=0.0f; p[i].color[2]=1.0f; } if(type==PO_AIM) { p[i].score = 32; p[i].tex=tex[PO_AIM]; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_GROWPADDLE) { p[i].score = 63; p[i].tex=tex[PO_GROWPADDLE]; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_SHRINKPADDLE) { p[i].score = 10; p[i].tex=tex[PO_SHRINKPADDLE]; p[i].color[0]=1.0f; p[i].color[1]=0.0f; p[i].color[2]=0.0f; } if(type==PO_EXPLOSIVE) { p[i].score = 24; p[i].tex=tex[PO_EXPLOSIVE]; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_GUN) { p[i].score = 80; p[i].tex=tex[PO_GUN]; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } if(type==PO_THRU) { p[i].score = 95; p[i].tex=tex[PO_THRU]; p[i].color[0]=1.0f; p[i].color[1]=1.0f; p[i].color[2]=1.0f; } if(type==PO_LASER) { p[i].score = 13; p[i].tex = tex[PO_LASER]; p[i].color[0]=0.0f; p[i].color[1]=1.0f; p[i].color[2]=0.0f; } break; } } } void coldet(paddle_class & paddle, effectManager & fxMan, ballManager & bMan) { for(i=0; i < MAXPOWERUPS; i++) { if(p[i].active) { p[i].coldet(paddle, fxMan, bMan); } } } void move() { for(i=0; i < MAXPOWERUPS; i++) { if(p[i].active) { p[i].move(); } } } void draw() { for(i=0; i < MAXPOWERUPS; i++) { if(p[i].active) { p[i].draw(); } } }};powerupManager pMan;void spawnpowerup(char powerup, pos a, pos b){ if(powerup == '1') { pMan.spawn(a,b,PO_GROWPADDLE); } if(powerup == '2') { pMan.spawn(a,b,PO_SHRINKPADDLE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -