void editor::listenToMouse() { if (levelLoaded) { if (pressedL) { int x = floor((xMouseReal-xCorner)/double(tilesize)); int y = level.h - floor((yMouseReal-yCorner)/double(tilesize)) - 1; switch (mode) { case 0: case 1: case 2: try { setTile(x, y, mode, mode?selectedColor:(char *)"#ffffff", selectedDurability); } catch (...) {} updateTile(x, y); break; case 3: if (x>=0 && y>=0 && x<level.w && y<level.h && tileType(x, y)) { int h=0, s=0, v=0; int c = 0; for (int i=-1; i<2; i++) for (int j=-1; j<2; j++, c++) { try { QColor tmp(tileColor(x+i, y+j)); h += tmp.hue(); s += tmp.saturation(); v += tmp.value(); } catch (...) { QColor tmp(tileColor(x+(-1*i), y+(-1*j))); h += tmp.hue(); s += tmp.saturation(); v += tmp.value(); } } h /= c; s /= c; v /= c; QColor q; q.setHsv(h, s, v); char m[8]; for (int i=0; i<8; i++) m[i] = (q.name().constData()+i)->toAscii(); qstrcpy(tileColor(x, y), m); updateTile(x, y); break; } } } } }
void editor::renderTile(int x, int y) { int type; QColor color; int connection; try { type = tileType(x, y); color = QColor(tileColor(x, y)); connection = tileConnectionType(x, y); } catch (char *ex) { return; } // cerr << "Rendering tile ("<<x<<"; "<<y<<") as type="<<type<<"\n"; double xDisplay = x*tilesize; double yDisplay = pixmap->height() - (y+1)*tilesize; QPainter painter(pixmap); // tile texture if (type == 0) { painter.setCompositionMode(QPainter::CompositionMode_Source); painter.setBrush(white); painter.setPen(NoPen); painter.drawRect(xDisplay, yDisplay, tilesize, tilesize); } else if (type < 3) { painter.setCompositionMode(QPainter::CompositionMode_Source); painter.drawPixmap(xDisplay, yDisplay, tilesize, tilesize, sprite_tile, 0, connection*tilesize, tilesize, tilesize); painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); painter.setBrush(color); painter.setPen(NoPen); painter.drawRect(xDisplay, yDisplay, tilesize, tilesize); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(xDisplay, yDisplay, tilesize, tilesize, sprite_border, 0, connection*tilesize, tilesize, tilesize); } }
void editor::mousePressEvent(QMouseEvent *event) { xMouseReal = event->x(); yMouseReal = event->y(); switch (event->button()) { case LeftButton: pressedL = true; break; case RightButton: pressedR = true; break; case MiddleButton: { int x = floor((xMouseReal-xCorner)/double(tilesize)); int y = level.h - floor((yMouseReal-yCorner)/double(tilesize)) - 1; qstrcpy(selectedColor, tileColor(x, y)); break; } default: // fixing warnings... break; } listenToMouse(); }
QColor TileWidget::miniTextColor() { return tileColor().light(170); }
QColor TileWidget::tileColor() { return tileColor(m_information); }
void TileWidget::setOriginalInformation(const Quackle::Board::TileInformation &originalInformation) { if (originalInformation.tileType == Quackle::Board::BonusSquareTile) m_backgroundColor = tileColor(originalInformation); }
task main() { calibrateTiles(); pivotLeft(180, 30); moveForward(180,30); moveForward(30); while(tileColor() != 1){ //REMAIN IN LOOP UNTIL BLACK REACHED sleep(50); } while(tileColor() == 1){ //REMAIN IN LOOP WHILST ON BLACK sleep(50); } stopMotors(); //STOP MOTORS WHEN GROUT REACHED moveForward(30); while(tileColor() == 1){ sleep(10); } stopMotors(); int blackwidth = getMotorEncoder(motorC); //$%^&*( CHECK THIS IS NOT A PROBLEM WITH THE ENCODER WIPING PART OF MOVEMETHODS moveForward(blackwidth/2, 30); sleep(500); pivotRight(180, 30); playSound(soundBeepBeep); int tileTotal = 28; int tileCount = 0; prevColor = 1; //ITS ON BLACK at this point while(tileCount < tileTotal){ switch(prevColor) { case 1: while(tileColor() == 1){ sleep(50); } break; case 2: while(tileColor() == 2){ sleep (50); } break; case 3: //error correction begins sleep(100); if(tileColor() == 3){ //check that we're truly on grey pivotLeft(10); while(tileColor() == 3){ sleep(10); } stopMotors(); leftCorrectDist = getMotorEncoder(motorC); pivotRight(leftCorrectDist); if(tileColor() == 3){ pivotRight(10); while(tileColor() == 3){ sleep(10); } } rightCorrectDist = getMotorEncoder(motorB); displayTextLine(6, "ERROR CORRECTION DISTANCES", black ); displayTextLine(7, "LEFT : %d", leftCorrectDist ); displayTextLine(8, "RIGHT : %d", rightCorrectDist ); sleep(500); if(leftCorrectDist < rightCorrectDist){ pivotLeft(rightCorrectDist); pivotLeft(leftCorrectDist); displayTextLine(9, "ERROR CORRECTED WENT LEFT" ); }else{ sleep(50); displayTextLine(9, "ERROR CORRECTED WENT RIGHT" ); } //error correction ends break; default: displayTextLine(6, "Unexpected error at switch 1.1"); break; } if(tileColor() == 1){ switch(prevColor) //begin switch 2.1 { case 1: sleep(20); break; case 2: prevColor = 1; tileCount++; playSound(soundBlip); displayTextLine(6, "Tiles Counted : %d", tileCount ); break; case 3: prevColor = 1; displayTextLine(5, "Error corrected 'back to black'"); break; default: displayTextLine(6, "Unexpected error at switch 2.1"); break; } //End of Switch 2.1 }else{ if(tileColor() == 2){ switch(prevColor){ //begin switch 2.2 case 1: prevColor = 2; tileCount++; playSound(soundBlip); displayTextLine(6, "Tiles Counted : %d", tileCount ); break; case 2: sleep(20); break; case 3: prevColor = 2; displayTextLine(5, "Error corrected 'back from the white'"); break; default: displayTextLine(6, "Unexpected error at switch 2.2"); break; }//end of switch 2.2 }else{ switch(prevColor){ //begin switch 2.3 case 1: lostTile = 1; prevColor = 3; break; case 2: lostTile = 2; prevColor = 3; break; case 3: displayTextLine(10, "HELP WE'RE STILL LOST"); break; default: displayTextLine(6, "Unexpected error at switch 2.3"); break; }// end of switch 2.3 } } } } finalMethod(); }