void drawTurretStuff(turret_struct* t) { if(!t || !t->used || t->dead)return; drawLaser(t->laserOrigin,t->laserDestination); if(t->laserThroughPortal)drawLaser(t->laserOrigin2,t->laserDestination2); //TEMP TEST BILLBOARD vect3D u1=vect(t->OBB->transformationMatrix[0],t->OBB->transformationMatrix[3],t->OBB->transformationMatrix[6]); vect3D u2=vect(t->OBB->transformationMatrix[1],t->OBB->transformationMatrix[4],t->OBB->transformationMatrix[7]); vect3D u3=vect(t->OBB->transformationMatrix[2],t->OBB->transformationMatrix[5],t->OBB->transformationMatrix[8]); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_ID(63)); GFX_COLOR=RGB15(31,31,31); applyMTL(turretShotTexture); if(t->drawShot[0]) { glPushMatrix(); glTranslatef32(t->laserOrigin.x, t->laserOrigin.y, t->laserOrigin.z); glTranslatef32(u3.x/128, u3.y/128, u3.z/128); glTranslatef32(u1.x/32, u1.y/32, u1.z/32); glScalef32(inttof32(1)/16,inttof32(1)/16,inttof32(1)/16); glRotatef32i(t->shotAngle[0],u3.x,u3.y,u3.z); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(-u1.x/2-u2.x, -u1.y/2-u2.y, -u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(0)); glVertex3v16(+u1.x/2-u2.x, +u1.y/2-u2.y, +u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(64)); glVertex3v16(+u1.x/2+u2.x, +u1.y/2+u2.y, +u1.z/2+u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(-u1.x/2+u2.x, -u1.y/2+u2.y, -u1.z/2+u2.z); glPopMatrix(1); } if(t->drawShot[1]) { glPushMatrix(); glTranslatef32(t->laserOrigin.x, t->laserOrigin.y, t->laserOrigin.z); glTranslatef32(u3.x/128, u3.y/128, u3.z/128); glTranslatef32(-u1.x/32, -u1.y/32, -u1.z/32); glScalef32(inttof32(1)/16,inttof32(1)/16,inttof32(1)/16); glRotatef32i(t->shotAngle[1],u3.x,u3.y,u3.z); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(-u1.x/2-u2.x, -u1.y/2-u2.y, -u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(0)); glVertex3v16(+u1.x/2-u2.x, +u1.y/2-u2.y, +u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(64)); glVertex3v16(+u1.x/2+u2.x, +u1.y/2+u2.y, +u1.z/2+u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(-u1.x/2+u2.x, -u1.y/2+u2.y, -u1.z/2+u2.z); glPopMatrix(1); } }
void BlackBoxApp::draw() { toogleRGB(); if(noEffects) return; ofPushMatrix(); ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); switch (drawMethod) { case 1: rotationPointCloud += (kbControlEase - rotationPointCloud)/ease; ofRotateY(rotationPointCloud); zoom += (kbZoom - zoom) / ease; ofScale(400 * zoom, 400 * zoom, 400 * zoom); drawPointCloud(); break; case 2: zoom += (kbZoom - zoom) / ease; ofScale(400 * zoom, 400 * zoom, 400 * zoom); drawCircleCloud(); break; case 3: ofScale(400, 400, 400); drawParticlesCloud(); break; case 4: ofScale(1000, 1000, 1000); drawPixels(); break; case 5: drawTriangleLines(); break; case 6: drawLaser(); break; case 7: drawContour(); break; case 8: drawTriangleColor(); break; case 9: drawTriangleBlue(); break; } ofPopMatrix(); ofSetColor(255, 255, 255); string showrgbString = "showRGB: "+ofToString(showRGB, 2); }
void ofApp::draw(){ fbo_->draw(0,0); for (size_t eachPart = 0; eachPart < robotParticles_->numParticles_; ++eachPart) { drawParticle(robotParticles_->theParticles_[eachPart]->pose_.x_, robotParticles_->theParticles_[eachPart]->pose_.y_, robotParticles_->theParticles_[eachPart]->pose_.theta_); } /// OPTIONAL: draw the simulated robot and its laser. drawLaser(*simBot_); drawParticle(simBot_->pose_.x_, simBot_->pose_.y_, simBot_->pose_.theta_); /// This function has been moved here such that the first iteration /// is visible in the window. if ((MotionModel::rWheelDelta_ != 0.0) || (MotionModel::lWheelDelta_ != 0.0)) { robotParticles_->sampleAndReplace(); } }
void Draw_Map(int map_array[12][20], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) { //int x = map_x_location; int x = 0; int y = 0; SetPlane (LIGHT_PLANE); ClrScr (); SetPlane (DARK_PLANE); ClrScr (); drawRType(pos); if (laser) drawLaser(laserPos); if (missile) drawMissile(missilePos); // Well.. the map_x_location will keep track of where we are on the X-plane on the map array // This way we mask out the stuff in the array that we use.. So we will only read 30x8 elements of the // array (instead of 60x8 which it is at the moment.. ).. This might sound unuseful, and it sort of is // with a small array as this one.. but i'm guessing you will create worlds that are much much bigger.. // so.. to gain more speed.. we mask it out ;) /*while (x<20) {// Again, we can't view more than 30 blocks.. so.. don't calculate more than 30 blocks if ((map_array[y][x]==7)) { // If the array at this location is equal to 1, place a ground piece Sprite8(x*8, y*8, 8, ground_down, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_down, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x]==8)) { // .. and if it's 2, place block1 Sprite8(x*8, y*8, 8, ground_flat, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_flat, GetPlane (LIGHT_PLANE), SPRT_XOR); } if (map_array[y][x]==9) { Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR); } y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT // is the best way to draw the world.. if (y>11) { // We've reached the limit.. restore the Y value, and move 1 block row forward.. y=0; x++; } }*/ for (x = 0; x <= 19; x++) { for (y = 0; y <= 11; y++) { if (map_array[y][x] == 7) { Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } else if (map_array[y][x] == 8) { Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } else if (map_array[y][x] == 9) { Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } } } }
void GameScreen::render(sf::RenderWindow& window) { sf::Clock clock; sf::Time time_1; sf::Time time_2; drawGrid(window); drawEquitment(window); if( GameScreen::tool_manager.getState() == 1 || GameScreen::tool_manager.getState() == 2) { window.draw(*(GameScreen::tool_manager.getCopyEquipment())); } drawLaser(window); }
// function that draws the screen void Draw_Map(int map_x_location, char map_array[12][MAP_SIZE], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) { int x = map_x_location; int y = 0; // clear both planes SetPlane (LIGHT_PLANE); ClrScr(); SetPlane (DARK_PLANE); ClrScr(); // draw ship, and missiles and cannons if they exist drawShip(pos, map_x_location); if (laser) drawLaser(laserPos, map_x_location); if (missile == 1) drawMissile(missilePos, map_x_location); if (missile == -1) drawUpMissile(missilePos, map_x_location); // Well.. the map_x_location will keep track of where we are on the X-plane on the map array // This way we mask out the stuff in the array that we use.. So we will only read 20x12 elements of the // array (instead of MAP_SIZEx12 which it is at the moment.. ) while (x < (map_x_location + 20)) {// Again, we can't view more than 20 blocks.. so.. don't calculate more than 20 blocks if ((map_array[y][x] == 1)) { // If the array at this location is equal to 1, place a broken piece Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 2)) { // If the array at this location is equal to 1, place a broken piece Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 3)) { // .. and if it's 2, place block1 Sprite8((x - map_x_location) * 8, y * 8, 8, block1_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, block1_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 4)) { // a 3 means the indestructible block Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_light, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_mid, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(DARK_PLANE), SPRT_XOR); } y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT // is the best way to draw the world.. if (y > 11) { // We've reached the limit.. restore the Y value, and move 1 block row forward.. y = 0; x++; } } }
inline void moveLaser(POSITION oldPos, POSITION newPos) { eraseLaser(oldPos); drawLaser(newPos); }
inline void eraseLaser(POSITION pos) { drawLaser(pos); }
// Main Function void _main(void) { // This is where the level map is defined // The map is 12 blocks of height 8 tall, and that fills the screen // 0s are blank, 1s are ground blocks, and 2s are the other blocks /*int map1[12][82] = { {0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,0,0,0,2,2,0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0,0,0,9,0,0,0,0,0,0}, {0,0,0,8,0,0,0,0,0,0,7,0,9,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,9,7,0,0}, {0,0,0,0,0,0,0,9,7,0,0,0,0,0,0,9,0,0,7,0}, {0,9,8,8,7,0,9,0,0,7,0,0,0,0,9,0,0,0,0,8}, {8,0,0,0,0,8,0,0,0,0,7,0,0,9,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,7,9,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; int key=0; int laser = 0; int justLaser = 0; int missile = 0; int justMissile = 0; int missileSlow = 2; short int keys[8]; POSITION laserPos; POSITION oldLaserPos; POSITION missilePos; POSITION oldMissilePos; POSITION oldRType; POSITION rTypePos = {0,4}; int score = 0; int forward = 0; //int map_x_location=0; //POSITION pos = {80,5}; //int pos = 0; INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1); // this will save auto int 1 // print a simple title and disclaimer clrscr(); printf("A game by Ben Cherry \nversion 0.2 Beta \nUse at your own risk! \nreport any bugs to me\nArrow keys - move ship\n2nd-fire straight laser\ndiamond-fire down missile\nDestroy the blocks!\nGame may become unstable\npast the ground raise!\nPress Enter to Begin"); while (ngetchx() != KEY_ENTER){} clrscr(); // seed the random numbers randomize(); // get the key masks getKeyMasks(keys); // DESTROY auto-interrupt 1 so as not to mess up _rowread SetIntVec(AUTO_INT_1,DUMMY_HANDLER); if (!GrayOn ()) return; Draw_Map(map1, rTypePos, laserPos, laser, missilePos, missile); // the main game loop while (!quit()) { // if the user has a missile out, deal with it if (missile && missileSlow == 2) { missileSlow = 1; oldMissilePos = missilePos; missilePos.x++; missilePos.y++; if (missilePos.x > 20) missile = 0; if (blowWall(missilePos,map1)) { map1[missilePos.y][missilePos.x]-=2;//= 0; /**/score++; /**/if (map1[missilePos.y][missilePos.x] < 0) map1[missilePos.y][missilePos.x] = 0; missile = 0; justMissile = 0; Draw_Map(map1,rTypePos,laserPos,laser,missilePos,missile); } // if the shot was just fired, then there wont be one to erase if (!justMissile && missile) { moveMissile(oldMissilePos,missilePos); } else if (missile) { drawMissile(missilePos); justMissile = 0; } } else { missileSlow++; } // if the user has a laser shot that is still going, continue it if (laser) { oldLaserPos = laserPos; laserPos.x++; if (laserPos.x > 20) laser=0; if (blowWall(laserPos,map1)) { map1[laserPos.y][laserPos.x]--; //= 0; /**/if (map1[laserPos.y][laserPos.x] == 0) score++; laser = 0; justLaser = 0; Draw_Map(map1,rTypePos,laserPos,laser, missilePos, missile); } // if the shot was just fired, then there wont be one to erase if (!justLaser && laser) { moveLaser(oldLaserPos,laserPos); } else if (laser){ drawLaser(laserPos); justLaser = 0; } } // scroll the screen forward one block every third time through the main loop if (forward == 3) { randMap(&map1); //rTypePos.x++; forward = 0; Draw_Map(map1,rTypePos,laserPos,laser, missilePos, missile); } else { forward++; } // if you ran into a wall, quit if (detectWall(rTypePos,map1)) break; key = _rowread(ARROW_ROW); // if the user pressed right, move the ship right if (key & keys[RIGHT]) { oldRType = rTypePos; rTypePos.x++; if (rTypePos.x > 20) rTypePos.x--; if (!detectWall(rTypePos,map1)){ moveRType(oldRType,rTypePos); } else { //rTypePos.x--; break; } } // If the user pressed left, move the ship left if (key & keys[LEFT]) { oldRType = rTypePos; //rTypePos.x--; if (rTypePos.x - 1 >= 0) rTypePos.x--; if (!detectWall(rTypePos,map1)){ moveRType(oldRType,rTypePos); } else { //rTypePos.x++; break; } } // if the user pressed up, move the ship up if (key & keys[UP]) { oldRType = rTypePos; //rTypePos.y--; if (rTypePos.y - 1 >= 0) rTypePos.y--; if (!detectWall(rTypePos,map1)) { moveRType(oldRType,rTypePos); } else { //rTypePos.y++; break; } } // if the user pressed down, move the ship down if (key & keys[DOWN]) { oldRType = rTypePos; rTypePos.y++; if (rTypePos.y > 12) rTypePos.y = 12; if (!detectWall(rTypePos,map1)) { moveRType(oldRType,rTypePos); } else { //rTypePos.y--; break; } } // if 2nd was pushed, fire the laser if (key & keys[SECOND]) { if (!laser) { justLaser = 1; laser = 1; laserPos.x = rTypePos.x + 1; laserPos.y = rTypePos.y; } } // if diamond was pushed fire the downward missiles if (key & keys[DIAMOND]) { if (!missile) { justMissile = 1; missile = 1; missileSlow = 2; missilePos.x = rTypePos.x; missilePos.y = rTypePos.y; } } // slow down the program because _rowread is too fast delay(); } // somehow the user left the game, either by crashing or quitting, so make sure to disable all changes GrayOff(); SetIntVec(AUTO_INT_1,interrupt1); clrscr(); printf("You destroyed %d blocks!",score); while (ngetchx() != KEY_ENTER){} }
// the main function void _main(void) { unsigned int difficulty = NORMAL; short int key=0; short int keys[8]; unsigned int level_num = 1; unsigned short int score = 0; int done = 0; unsigned int money = 0; int cannon_level = 1; int missile_level = 0; char map[12][MAP_SIZE]; // seed the random numbers randomize(); // get the key masks getKeyMasks(keys); INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1); // this will save auto int 1 // draw title screen and wait for keypress GrayOn(); drawTitle(2); ngetchx(); //draw background title screen and menu drawTitle(1); drawWords(difficulty); POSITION pointer = {10,0}; drawPointer(pointer); // the menu loop while (1) { key = ngetchx(); if (key == KEY_ENTER && pointer.y != OPTIONS) { if (pointer.y == PLAY) break; if (pointer.y == HIGH_SCORES) printHiScores(); if (pointer.y == HELP) doHelp(); if (pointer.y == ABOUT) { SetIntVec(AUTO_INT_1,interrupt1); GrayOff(); exit(0); } GraySetAMSPlane(LIGHT_PLANE); clrscr(); GraySetAMSPlane(DARK_PLANE); clrscr(); drawTitle(1); drawWords(difficulty); pointer=(POSITION) { 10,0 }; drawPointer(pointer); } if (key == KEY_LEFT && pointer.y == OPTIONS && difficulty < VERY_EASY) { difficulty+=1; GraySetAMSPlane(LIGHT_PLANE); clrscr(); GraySetAMSPlane(DARK_PLANE); clrscr(); drawTitle(1); drawPointer(pointer); drawWords(difficulty); } if (key == KEY_RIGHT && pointer.y == OPTIONS && difficulty > IMPOSSIBLE) { difficulty-=1; GraySetAMSPlane(LIGHT_PLANE); clrscr(); GraySetAMSPlane(DARK_PLANE); clrscr(); drawTitle(1); drawPointer(pointer); drawWords(difficulty); } if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer); if (key == KEY_UP && pointer.y > 0) pointer.y--; if (key == KEY_DOWN && pointer.y < 4) pointer.y++; if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer); } key = 0; // turn off gray, so we can destroy auto-int-1 and not mess it up GrayOff(); // DESTROY auto-interrupt 1 so as not to mess up _rowread SetIntVec(AUTO_INT_1,DUMMY_HANDLER); // turn gray back on GrayOn(); // randomize the map randomMap(difficulty, map, level_num); //the main game loop while (!quit() && !done) { done = 0; int fin = 0; int win = 0; int forward = 0; int map_x_location = 0; int laser = 0; int justLaser = 0; int missile = 0; int justMissile = 0; int missileSlow = 2; POSITION laserPos; POSITION oldLaserPos; POSITION missilePos; POSITION oldMissilePos; POSITION oldShip; POSITION ShipPos = {0,5}; // we need to disable gray temporarily to do the shop screen... GrayOff(); SetIntVec(AUTO_INT_1, interrupt1); shop(&money, &cannon_level, &missile_level); SetIntVec(AUTO_INT_1, DUMMY_HANDLER); GrayOn(); // draws the level Draw_Map(map_x_location, map, ShipPos, laserPos, laser, missilePos, missile); // the loop for the action in the level while (!quit()) { // if the user has a missile out, deal with it if (missile && missileSlow == 2) { missileSlow = 1; oldMissilePos = missilePos; missilePos.x++; missilePos.y+=missile; if (missilePos.x > map_x_location + 20) missile = 0; if (missilePos.y < 0 || missilePos.y > 12) { missile = 0; eraseMissile(missilePos, map_x_location); } if (blowWall(missilePos,map)) { if (map[missilePos.y][missilePos.x] < 4) { map[missilePos.y][missilePos.x]-=3; if (map[missilePos.y][missilePos.x] == 0) { score++; money+=BLOCK_VALUE; } } if (map[missilePos.y][missilePos.x] < 0) map[missilePos.y][missilePos.x] = 0; missile = 0; justMissile = 0; Draw_Map(map_x_location,map,ShipPos,laserPos,laser,missilePos,missile); } // if the shot was just fired, then there wont be one to erase if (!justMissile && missile == 1) { moveMissile(oldMissilePos,missilePos,map_x_location); } else if (missile == 1) { drawMissile(missilePos,map_x_location); justMissile = 0; } else if (!justMissile && missile == -1) { moveUpMissile(oldMissilePos, missilePos, map_x_location); } else if (missile == -1) { drawUpMissile(missilePos, map_x_location); justMissile = 0; } } else { missileSlow++; } // if the user has a laser shot that is still going, continue it if (laser) { oldLaserPos = laserPos; laserPos.x++; if (laserPos.x > map_x_location + 20) laser=0; if (blowWall(laserPos,map)) { if (map[laserPos.y][laserPos.x] < 4) { map[laserPos.y][laserPos.x]-=cannon_level; if (map[laserPos.y][laserPos.x] <= 0) { score++; money+=BLOCK_VALUE; map[laserPos.y][laserPos.x] = 0; } } else if (map[laserPos.y][laserPos.x] == 4 && cannon_level == 4) { map[laserPos.y][laserPos.x] = 1; } laser = 0; justLaser = 0; Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile); } // if the shot was just fired, then there wont be one to erase if (!justLaser && laser) { moveLaser(oldLaserPos,laserPos,map_x_location); } else if (laser) { drawLaser(laserPos,map_x_location); justLaser = 0; } } // scroll the screen forward one block every (difficulty) time through the main loop if (forward == difficulty) { map_x_location++; ShipPos.x++; forward = 0; if (map_x_location >= MAP_SIZE - 20) { win = 1; level_num++; break; } // if you ran into a wall, quit if (detectWall(ShipPos,map)) { win = 1; score /= 2 ; break; } Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile); } else { forward++; } // if you ran into a wall, quit if (detectWall(ShipPos,map)) { win = 1; score = 0; break; } if (_rowread(~((short)(1<<1))) & (1<<6) && _rowread(~((short)(1<<2))) & (1<<6)) { win = 1; level_num++; break; } // get keypresses key = _rowread(ARROW_ROW); // if the user pressed right, move the ship right if (key & keys[RIGHT]) { oldShip = ShipPos; ShipPos.x++; if (ShipPos.x > map_x_location + 18) ShipPos.x--; if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // If the user pressed left, move the ship left if (key & keys[LEFT]) { oldShip = ShipPos; ShipPos.x--; if (ShipPos.x < map_x_location) ShipPos.x++; if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // if the user pressed up, move the ship up if (key & keys[UP]) { oldShip = ShipPos; if (ShipPos.y - 1 < 0) { ShipPos.y = 0; } else { ShipPos.y--; } if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // if the user pressed down, move the ship down if (key & keys[DOWN]) { oldShip = ShipPos; ShipPos.y++; if (ShipPos.y > 10) ShipPos.y = 10; if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // if 2nd was pushed, fire the laser if (key & keys[SECOND]) { if (!laser) { justLaser = 1; laser = 1; laserPos.x = ShipPos.x + 1; laserPos.y = ShipPos.y; } } // if diamond was pushed fire the downward missiles if (key & keys[DIAMOND]) { if (missile_level == 3 || missile_level == 1) { if (!missile) { justMissile = 1; missile = 1; missileSlow = 2; missilePos.x = ShipPos.x; missilePos.y = ShipPos.y; } } } // if shift was pushed fire the upward missiles if (key & keys[SHIFT]) { if (missile_level == 2 || missile_level == 3) { if (!missile) { justMissile = 1; missile = -1; missileSlow = 2; missilePos.x = ShipPos.x; missilePos.y = ShipPos.y; } } } /*if (key & keys[ALPHA]) { score += 10; }*/ // slow down the program because _rowread is too fast delay(); } // back to the overall game loop if (win) { if (level_num <= LEVEL_NUM) { won(difficulty, map, level_num); } else { fin = 1; break; } } } // the user left, either by winning or quitting, so make sure everything is reset so the calc will be fine GrayOff(); SetIntVec(AUTO_INT_1,interrupt1); hiScoresGo(score, difficulty, level_num); }
// a function that moves the cannon, by erasing and redrawing inline void moveLaser(POSITION oldPos, POSITION newPos, int map_x_location) { eraseLaser(oldPos, map_x_location); drawLaser(newPos, map_x_location); }
// a function that erases the cannon, by redrawing it inline void eraseLaser(POSITION pos, int map_x_location) { drawLaser(pos, map_x_location); }
int main() { initializeCrap(); install_int_ex(increment_speed_counter,BPS_TO_TIMER(120)); int screenMode = 0; //0 for windowed, 1 for fullscreen srand((unsigned)time(NULL)); BITMAP *buffer = create_bitmap(800,600); BITMAP *titleimg = load_bitmap("quiximgTitle.bmp",NULL); BITMAP *imgPlayers = load_bitmap("quiximgPlayerSet.bmp",NULL); MIDI *song = load_midi("quixsong.mid"); PlayerObject poPlayer[4]; LaserObject loLaser[4]; LevelObject Level; MenuObject Menu; float scrollerX = -150.0, scrollerY = 5.0; int winner; poPlayer[0].setControlScheme(0); poPlayer[1].setControlScheme(1); poPlayer[2].setControlScheme(2); poPlayer[3].setControlScheme(3); poPlayer[0].samSound = load_sample("quixp1Death.wav"); poPlayer[1].samSound = load_sample("quixp2Death.wav"); poPlayer[2].samSound = load_sample("quixp3Death.wav"); poPlayer[3].samSound = load_sample("quixp4Death.wav"); poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); int mouseDown[21]; //Kind of a crappy array --- Each button is a # //and it's set to true if that button was clicked. for (int i = 0; i < 20; i++) { mouseDown[i] = false; } while ( !Menu.isDone() ) { while (speed_counter > 0) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~ MENU SCREEN ~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ if ( Menu.getEnabled() == true ) { if (key[KEY_Z]) { if (Menu.getFullscreen() == true) { Menu.changeScreenSize(0); Menu.setFullscreen(false); } else { Menu.changeScreenSize(1); Menu.setFullscreen(true); } } if (mouse_b & 1) { mouseDownClick(&Menu, mouseDown); } else { mouseUp(&Menu, mouseDown, poPlayer, &Level, song); } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~ IN-GAME ~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ else { //Player Input1 if (key[KEY_ESC]) { play_midi(NULL, false); if (Menu.fragLimitHit == true) { Menu.fragLimitHit == false; for (int i=0; i<4; i++) { poPlayer[i].resetScore(); poPlayer[i].resetDeaths(); } poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); Menu.fragLimitHit = false; Menu.resetPressed = false; mouseDown[19] = false; } Level.setEnabled(false); Menu.setEnabled(true); } for (int i=0; i<4; i++) { if (poPlayer[i].getControlScheme() == 0) { if (key[KEY_W]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_A]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_S]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_D]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_F]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 1) { if (key[KEY_I]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_J]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_K]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_L]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_H]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 2) { if (key[KEY_UP]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_LEFT]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_DOWN]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_RIGHT]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_RCONTROL]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 3) { if (key[KEY_8_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_4_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_2_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_6_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_PLUS_PAD]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 4) { //Joystick #1 poll_joystick(); if (joy[0].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[0].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[0].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[0].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[0].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 5) { //Joystick #2 poll_joystick(); if (joy[1].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[1].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[1].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[1].stick[0].axis[0].d2) {moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[1].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 6) { //Joystick #3 poll_joystick(); if (joy[2].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[2].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[2].stick[0].axis[1].d2) {moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[2].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[2].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 7) { //Joystick #4 poll_joystick(); if (joy[3].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[3].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[3].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[3].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[3].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } } if (Level.timeForAPowerupTimer >= 60) { Level.timeForAPowerupTimer = 0; } else { Level.timeForAPowerupTimer++; } } if ( Level.getFrame() < 32 ) { Level.setFrame( Level.getFrame() + 1 ); } else { Level.setFrame(0); } //Score Bar if (Level.getFragLimit() != 0 && Level.getEnabled() == true) { scrollerX += 0.5; if (scrollerX >= 1200.0) { scrollerX = -150.0; } } for (int i=0; i<4; i++) { //Res circle if (poPlayer[i].getRespawnCounter() >= 0) { poPlayer[i].setRespawnCounter( poPlayer[i].getRespawnCounter() + 1); } //"Laser" movement if (loLaser[i].getEnabled() == true) { if (loLaser[i].getDir() == 'u') { loLaser[i].moveUp('l'); } else if (loLaser[i].getDir() == 'd') { loLaser[i].moveDown('l'); } else if (loLaser[i].getDir() == 'l') { loLaser[i].moveLeft('l'); } else if (loLaser[i].getDir() == 'r') { loLaser[i].moveRight('l'); } checkCollision(&loLaser[i], poPlayer, i, Level); } if ((poPlayer[i].returnScore() == Level.getFragLimit()) && (Level.getFragLimit() > 0)) { //Frag Limit hit Menu.fragLimitHit = true; winner = i; } } speed_counter--; }//while (speed_counter > 0) if ( Menu.getEnabled() == true ) { drawMenuStuff(buffer, Menu, titleimg, imgPlayers, Level); } else if (Menu.fragLimitHit == true) { //Show win window! floodfill (buffer, 0, 0, makecol(0,0,0)); textprintf(buffer,font,348,203,makecol(100,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,347,202,makecol(150,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,346,201,makecol(200,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,345,200,makecol(255,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,330,250,makecol(255,0,0), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,260,makecol(255,0,0), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,270,makecol(255,0,0), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,280,makecol(255,0,0), "Player 4 score: %i", poPlayer[3].returnScore() ); textprintf(buffer,font,330,249,makecol(255,255,255), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,259,makecol(255,255,255), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,269,makecol(255,255,255), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,279,makecol(255,255,255), "Player 4 score: %i", poPlayer[3].returnScore() ); textout_centre(buffer, font, "Hit esc to continue", 400, 300, makecol(255,255,255)); } else { generateBackground(buffer, Level); drawCharacters(poPlayer, Level, buffer); drawScoreBar(buffer, poPlayer, scrollerX, scrollerY, Level); if (loLaser[0].getEnabled() == true) { drawLaser(loLaser[0], buffer, Level, 0); } if (loLaser[1].getEnabled() == true) { drawLaser(loLaser[1], buffer, Level, 1); } if (loLaser[2].getEnabled() == true) { drawLaser(loLaser[2], buffer, Level, 2); } if (loLaser[3].getEnabled() == true) { drawLaser(loLaser[3], buffer, Level, 3); } } acquire_screen(); blit(buffer, screen, 0, 0, 0, 0, 800, 600); clear_bitmap(buffer); release_screen(); }//while ( !Menu.isDone() ) return 0; return 0; }
void GLWidget::drawRobot() { //////////////////////////// Pioneer ////////////////////////////// mutex.lock(); // Robot Frame of Reference float posx = this->robot_x / 100.; float posy = this->robot_y / 100.; float posz = 0.; float foax = this->robot_x / 100.; float foay = this->robot_y / 100.; float foaz = 10.; float roll = this->robot_theta; glTranslatef(posx, posy, posz); float dx = (foax - posx); float dy = (foay - posy); float dz = (foaz - posz); float longiPioneer = (float) atan2(dy, dx)*360. / (2. * PI); glRotatef(longiPioneer, 0., 0., 1.); float r = sqrt(dx * dx + dy * dy + dz * dz); float latiPioneer; if (r < 0.00001) latiPioneer = 0.; else latiPioneer = acos(dz / r)*360. / (2. * PI); glRotatef(latiPioneer, 0., 1., 0.); glRotatef(roll, 0., 0., 1.); // X axis glColor3f(1., 0., 0.); glBegin(GL_LINES); v3f(0.0, 0.0, 0.0); v3f(5.0, 0.0, 0.0); glEnd(); // Y axis glColor3f(0., 1., 0.); glBegin(GL_LINES); v3f(0.0, 0.0, 0.0); v3f(0.0, 5.0, 0.0); glEnd(); // Z axis glColor3f(0., 0., 1.); glBegin(GL_LINES); v3f(0.0, 0.0, 0.0); v3f(0.0, 0.0, 5.0); glEnd(); // robot body glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(1., 0., 0.); // the body it is not centered. With this translation we center it loadModel(); // CARGAMOS EL MODELO DEL PIONEER glPopMatrix(); glDisable(GL_LIGHTING); //sensors drawLaser(); mutex.unlock(); }
void Gui::show_windows() { if ((this->interfacesData->pose3DEncodersInterface.activated) && (this->interfacesData->pose3DMotorsInterface.activated)) { if (this->teleoperatorCameras_window->get_visible()){ displayPose3DEncodersData(); }else{ this->teleoperatorCameras_window->show(); } }else if(this->teleoperatorCameras_window->get_visible()){ this->teleoperatorCameras_window->hide(); } if (this->interfacesData->laserInterface.activated) { if (this->laser_window->get_visible()){ if(this->interfacesData->laserReady) drawLaser(); }else{ this->laser_window->show(); } }else if(this->laser_window->get_visible()){ this->laser_window->hide(); } if (this->interfacesData->motorsInterface.activated) { if (this->motors_window->get_visible()){ displayMotorsData(); }else{ this->motors_window->show(); } }else if(this->motors_window->get_visible()){ this->motors_window->hide(); } if (this->interfacesData->encodersInterface.activated) { if (this->encoders_window->get_visible()){ if(this->interfacesData->encodersReady) displayEncodersData(); }else{ this->encoders_window->show(); } }else if(this->encoders_window->get_visible()){ this->encoders_window->hide(); } pthread_mutex_lock(&interfacesData->imagesData_mutex); if (this->interfacesData->camerasInterface.activated) { if (this->images_window->get_visible()){ displayCameras(); }else{ this->images_window->show(); } }else if(this->images_window->get_visible()){ this->images_window->hide(); } pthread_mutex_unlock(&interfacesData->imagesData_mutex); while (gtkmain.events_pending()) { gtkmain.iteration(true); } }
void DSPNode::setLaserFlag (float newFlag) { laserFlag = newFlag; // note continuous value is used for alpha drawLaser(); BROADCAST(this, "sf", "setLaserFlag", laserFlag); }