// 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,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,2,2,0,0,0,2,2,2,2,2,2,2,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,0,0,2,2,0,0,0,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,2,0,0,0,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,2,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0}, {0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,2,0,0,2,2,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,2,0,0,2,2,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,2,0,0,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,2,0,0,0,2,0,2,2,2,0,0,0}, {0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,2,0,0,0,0,0,0,0,2,2,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,2,0,0,0,0,0,0,0,2,2,0,2,0,2,2,2,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};*/ int map1[12][20] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {8,7,0,0,0,9,7,9,7,0,0,0,0,0,9,8,8,8,8,8}, {0,0,7,0,9,0,0,0,0,7,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){} }
void LaserManager:: drawShapes() { // sort the dots by nearest neighbour if(shapes.size()==0) return; vector<LaserShape*> sortedShapes; for(int i =0; i<shapes.size(); i++ ) { shapes[i]->tested = false; shapes[i]->reversed = false; } int numberSorted = 0; //int dotNum = shapes.size(); int currentIndex = 0; int nextDotIndex = NULL; //float travelDistanceSorted = 0; bool reversed = false; do { LaserShape * shape1 = shapes.at(currentIndex); //LaserDot & nextDot = dots.at(nextDotIndex); shape1->tested = true; sortedShapes.push_back(shape1); shape1->reversed = reversed; float shortestDistance = INFINITY; nextDotIndex = -1; for(int j = 0; j<shapes.size(); j++) { LaserShape * shape2 = shapes.at(j); if((shape1==shape2) || (shape2->tested)) continue; if(shape1->getEndPos().distanceSquared(shape2->getStartPos()) < shortestDistance) { shortestDistance = shape1->getEndPos().distanceSquared(shape2->getStartPos()); nextDotIndex = j; reversed = false; } if((shape2->reversable) && (shape1->getEndPos().distanceSquared(shape2->getEndPos()) < shortestDistance)) { shortestDistance = shape1->getEndPos().distanceSquared(shape2->getEndPos()); nextDotIndex = j; reversed = true; } } /* if(nextDotIndex>-1) { travelDistanceSorted += sqrt(shortestDistance); }*/ currentIndex = nextDotIndex; } while (currentIndex>-1); /* float travelDistanceUnsorted = 0; for(int i = 0; i<shapes.size()-1; i++) { LaserShape* shape1 = shapes.at(i); LaserShape* shape2 = shapes.at(i+1); travelDistanceUnsorted += shape1->endPos.distanceSquared(shape2->startPos); }*/ //ofDrawBitmapString(ofToString(travelDistanceUnsorted)+"\n" +ofToString(travelDistanceSorted), ofPoint(10,40)); ofPoint startPosition = sortedShapes[0]->getStartPos(); for(int i = 0; i<sortedShapes.size(); i++) { LaserShape* shape = sortedShapes.at(i); if(!currentPosition.match(shape->getStartPos(), 0.01)) { moveLaser(shape->getStartPos()); // PRE BLANK for(int i = 0; i<shapePreBlank; i++) { addIldaPoint(shape->getStartPos(), black, 1); } } else { // no blanks if we're there already? // PRE BLANK //for(int i = 0; i<shapePreBlank; i++) { // addIldaPoint(shape->getStartPos(), shape.getC, 1); //} } // Is it a dot? LaserDot * dot = dynamic_cast<LaserDot*>(shape); if(dot) { drawLaserDot(*dot); } // Is it a line? LaserLine * line = dynamic_cast<LaserLine*>(shape); if(line) { drawLaserLine(*line); } // Is it a circle? LaserCircle * circle = dynamic_cast<LaserCircle*>(shape); if(circle) { drawLaserCircle(*circle); } // Is it a line? LaserPolyline * poly = dynamic_cast<LaserPolyline*>(shape); if(poly) { drawLaserPolyline(*poly); } // Is it a spiral? LaserSpiral * spiral = dynamic_cast<LaserSpiral*>(shape); if(spiral) { drawLaserSpiral(*spiral); } // what's the point of pre and post blank? just one blank is enough, right? // POST BLANK for(int i = 0; i<shapePostBlank; i++) { addIldaPoint(shape->getEndPos(), black, 1); } } moveLaser(startPosition); }
// 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); }
void LaserManager::draw() { if(testPattern==1) { //addLaserRectEased(pmin, pmax, white); //addLaserLineEased(maskRectangle.getTopLeft(), maskRectangle.getBottomRight(), white); //addLaserLineEased(maskRectangle.getTopRight(), maskRectangle.getBottomLeft(), white); ofPoint v = maskRectangle.getBottomRight() - maskRectangle.getTopLeft(); for(float x =0 ; x<=1; x+=0.2) { for(float y = 0; y<=1; y+=0.2) { //addLaserDot(ofPoint(maskRectangle.x + (v.x*x), maskRectangle.y + (v.y*y)), white, 1); if(x ==0) { addLaserLineEased(ofPoint(maskRectangle.getLeft(), maskRectangle.getTop()+v.y*y),ofPoint(maskRectangle.getRight(), maskRectangle.getTop()+v.y*y), ofColor::white ); } } addLaserLineEased(ofPoint(maskRectangle.x + v.x*x, maskRectangle.getTop()),ofPoint(maskRectangle.x + v.x*x, maskRectangle.getBottom()), ofColor::red ); } addLaserCircle(maskRectangle.getCenter(), white, 10); addLaserCircle(maskRectangle.getCenter(), ofFloatColor(1,0,0), 50); /* addLaserDot(pmin, white, 1); addLaserDot(ofPoint(pmax.x, pmin.y), white, 1); addLaserDot(pmax, white, 1); addLaserDot(ofPoint(pmin.x, pmax.y), white, 1); */ } else if((testPattern>=2) && (testPattern<=5)) { ofColor c; ofRectangle rect(appWidth*0.3, appHeight*0.3, appWidth*0.3, appHeight*0.3); for(int row = 0; row<5; row ++ ) { float y = rect.getTop() + (rect.getHeight()*row/4); ofPoint left = ofPoint(rect.getLeft(), y); ofPoint right = ofPoint(rect.getRight(), y); moveLaser(left); for(int i = 0; i<shapePreBlank; i++) { addIldaPoint(left, black, 1); } if(testPattern == 2) c.set(255,0,0); else if(testPattern == 3) c.set(0,255,0); else if(testPattern == 4) c.set(0,0,255); else if(testPattern == 5) c.set(255,255,255); switch (row) { case 0 : c.r *= red100; c.g *= green100; c.b *= blue100; break; case 1 : c.r *= red75; c.g *= green75; c.b *= blue75; break; case 2 : c.r *= red50; c.g *= green50; c.b *= blue50; break; case 3 : c.r *= red25; c.g *= green25; c.b *= blue25; break; case 4 : c.r *= red0; c.g *= green0; c.b *= blue0; break; } for(int i = 0; i<shapePreBlank; i++) { addIldaPoint(left, c, 1, true); } float speed = 20 * ( 1- (row*0.25)); if(speed<5) speed = 5; for(float x = rect.getLeft(); x<=rect.getRight(); x+=speed) { addIldaPoint(ofPoint(x,y),c,1, false); } for(int i = 0; i<shapePostBlank; i++) { addIldaPoint(right, c, 1, false); } for(int i = 0; i<shapePostBlank; i++) { addIldaPoint(right, black, 1); } // 0 = normalspeed; // 1 = normalspeed * 0.75 // 2 = normalspeed * 0.5 // 3 = normalspeed * 0.25 // 0 = 1; // 1 = 0.75 // 2 = 0.5; // 3 = 0.25 //float brightness = 1 - (row*0.25); //if(brightness < 0) brightness = } } // if we're using the clever laser render delay // system if(delay > 0) { float currentTime = ofGetElapsedTimef(); //cout << "------------pushing history " << shapes.size() << endl; // add the current shapes and time to the // histories shapesHistory.push_back(shapes); frameTimes.push_back(currentTime); //start from the oldest shapes and while the next set of // shapes are due, delete the oldest int numDeleted = 0; while((frameTimes.size()>1) && (frameTimes[1]+delay < currentTime)) { shapes = shapesHistory.front(); // DELETE ALL SHAPES IN HISTORY.FRONT for(int i = 0; i<shapes.size(); i++) { delete shapes[i]; } shapesHistory.pop_front(); frameTimes.pop_front(); //resetIldaPoints(); //cout << "deleting oldest " << endl; numDeleted++; } shapes = shapesHistory.front(); if(numDeleted == 0 ) { //cout << "NONE DELETED" << endl; } //cout << "using shapes " << shapesHistory.size() << endl; //cout << "shapes size " << shapes.size() << endl; //cout << "pathMesh vertices " << pathMesh.getVertices().size() << endl; /* if((frameTimes.size()>0) && (frameTimes[0]+delay <= ofGetElapsedTimef())) { // if we have too many, we have to delete some! while((frameTimes.size()>1) && (frameTimes[1]+delay <= ofGetElapsedTimef())) { shapes = shapesHistory.front(); shapesHistory.pop_front(); frameTimes.pop_front(); //resetIldaPoints(); } shapes = shapesHistory.front(); shapesHistory.pop_front(); frameTimes.pop_front(); } else { // we're not ready to show the next shapes yet so show // the oldest ones. // need to do this otherwise the shapes get deleted // more than once clearShapes = true; shapes = shapesHistory.front(); //shapes.clear(); }*/ } else if(shapesHistory.size()!=0) { // TODO need to also delete shapes otherwise memory leak for(int i = 0; i<shapesHistory.size(); i++) { for(int j = 0; j<shapesHistory[i].size(); j++) { delete shapesHistory[i][j]; } } shapesHistory.clear(); frameTimes.clear(); } //ofDrawBitmapString(ofToString(shapesHistory.size()), 200,200); drawShapes(); if(renderLaserPreview) { renderPreview(); //ofRect(0,0,100,100); } while(ildaPoints.size()<minPoints) { addIldaPoint(currentPosition, black); } vector<ofxIlda::Point> adjustedPoints; // SORT OUT COLOUR CHANGE DELAY. for(int i = 0; i<ildaPoints.size(); i++) { ofxIlda::Point p = ildaPoints.at(i); int colourPointIndex = i+colourChangeDelay; while(colourPointIndex<0) colourPointIndex+=ildaPoints.size(); ofxIlda::Point colourPoint = ildaPoints.at(colourPointIndex%ildaPoints.size()); p.r = round(colourPoint.r); p.g = round(colourPoint.g); p.b = round(colourPoint.b); adjustedPoints.push_back(p); } if(!useTCP) { etherdream.setPoints(adjustedPoints); etherdream.setPPS(pps); } else { sendPointsTCP(adjustedPoints); } ofPushStyle(); if(maskRectangleBrightness>0) { ofNoFill(); ofSetColor(maskRectangleBrightness * 255); ofRect(maskRectangle); maskRectangleBrightness-=0.01; } ofPopStyle(); // TODO if we're not using the delay system, let's // delete all the shapes if(delay==0) { for(int i = 0; i<shapes.size(); i++) { delete shapes[i]; } } // clear the shapes vector no matter what shapes.clear(); // cout << "pathMesh vertices " << pathMesh.getVertices().size() << " " << ildaPoints.size() << endl; }