void ProcessKeyboard() { if (VK_LEFT == GetPressedKeyboard()) { myRect.MoveLeft(5); } if (VK_RIGHT == GetPressedKeyboard()) { myRect.MoveRight(5); } if (VK_UP == GetPressedKeyboard()) { myRect.MoveUp(5); } if (VK_DOWN == GetPressedKeyboard()) { myRect.MoveDown(5); } if (VK_SPACE == GetPressedKeyboard()) { //스페이스바를 눌렀을 경우 // 화면 임의의 위치에 새로운 shape를 만들어서 그릴수 있도록 준비해 주세요 } }
void MainWindow::on_editHLCol_clicked() { MyRect * r = MyRect::m_selectedRect; QColor col = QColorDialog::getColor(r->getColor(), this, QString("Choose Text Background Color"), QColorDialog::ShowAlphaChannel); if(col.isValid()) r->setColor(col); }
void MainWindow::on_editText_clicked() { MyRect * r = MyRect::m_selectedRect; bool ok; QString text = QInputDialog::getText(this, tr("Enter Text"), tr("Text:"), QLineEdit::Normal, r->getText(), &ok); if(ok && !text.isEmpty()) r->setText(text); }
void MainWindow::on_goToScene_activated(const QString &arg1) { MyRect * r = MyRect::m_selectedRect; if(!ui->goToScene->currentIndex()) { r->setId(0); ui->badgeWidg->setHidden(true); return; } r->setId(m_scenes->id(arg1)); ui->badgeWidg->setHidden(false); }
void MainWindow::on_sndPitch_valueChanged(int value) { ScreenQGV::EditorType edType = ui->graphicsView->editorType(); if(edType == ScreenQGV::MAP || edType == ScreenQGV::SCENE) { MyRect * r = MyRect::m_selectedRect; r->setPitch(value); } else { ui->graphicsView->setRewardSoundPitch(value); } }
void DjvuPic::SetViewRgn(MyRect rgn) { CSize size=rgn.Size(); CPoint topleft=rgn.TopLeft(); if(size.cx>Buffer->w) size.cx=Buffer->w; if(size.cy>Buffer->h) size.cy=Buffer->h; if(rgn.left<0) topleft.x=0; if(rgn.right>Buffer->w) topleft.x=Buffer->w-size.cx; if(rgn.top<0) topleft.y=0; if(rgn.bottom>Buffer->h) topleft.y=Buffer->h-size.cy; ViewRgn=CRect(topleft,size); return; }
Game::Game(QWidget* parent){ QGraphicsScene * scene = new QGraphicsScene(); scene->setSceneRect(0,0,800,600); setBackgroundBrush(QBrush(QImage(":/images/bg4.jpg"))); setWindowTitle("Taiko~"); setScene(scene); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFixedSize(800,600); //create the player MyRect * rect = new MyRect(); // setPixmap(QPixmap(":/images/rect.jpg")); // rect -> setRect (0,0,10,10); // rect->setPos(width()/2,height()-rect->rect().height()); rect->setPos(230,235); //make the player focusable rect->setFlag(QGraphicsItem::ItemIsFocusable); rect->setFocus(); // add the rect to the scene scene->addItem(rect); //create the score score = new Score(); score->setPos(40,210); scene->addItem(score); //create the time time = new Time(); time->setPos(42,243); scene->addItem(time); //time->countdown ->start(); //spawn enemies QTimer * timer = new QTimer(); QObject::connect(timer, SIGNAL(timeout()),rect,SLOT(spawn())); timer->start(1000); }
//Returns true is the vector "v" contains a rect that is similar to "r". //If s0, "r" is replaced by that rect. bool History::RectInVect(MyRect &r, const vector<MyRect> &v) { vector<MyRect>::const_iterator iter; for(iter=v.begin(); iter!=v.end(); ++iter) { if(r.similar(*iter)) {r = *iter; return true;} } return false; }
void ProcessKeyboard() { if (VK_LEFT == GetPressedKeyboard()) { myRect.MoveLeft(2); } if (VK_RIGHT == GetPressedKeyboard()) { myRect.MoveRight(3); } if (VK_UP == GetPressedKeyboard()) { myRect.MoveUp(2); } if (VK_DOWN == GetPressedKeyboard()) { myRect.MoveDown(4); } if (VK_SPACE == GetPressedKeyboard()) { npcinit(gX, gY, gWidth, gHeight); gX += 8; if( gX > 60) { gY += 4; gX = 0; } } if( VK_LBUTTON == GetPressedKeyboard()) { MyTriangle triangle; triangle.m_x = 15; triangle.m_y = 3; triangle.m_height = 5; triangles.push_back(triangle); } }
void MainWindow::on_delSnd_clicked() { ScreenQGV::EditorType edType = ui->graphicsView->editorType(); if(edType == ScreenQGV::MAP || edType == ScreenQGV::SCENE) { MyRect * r = MyRect::m_selectedRect; r->setHasSound(false); m_fileManager.deleteFile(r->sndFilepath()); } else { ui->graphicsView->setRewardSoundFile(L"None"); ui->graphicsView->setRewardSoundVolume(50); ui->graphicsView->setRewardSoundPitch(1); } ui->addSnd->setHidden(false); ui->delSnd->setHidden(true); ui->sndVolWidg->setHidden(true); ui->sndPitchWidg->setHidden(true); }
void ProcessKeyboard() { if (VK_LEFT == GetPressedKeyboard()) { myRect.MoveLeft(5); } if (VK_RIGHT == GetPressedKeyboard()) { myRect.MoveRight(5); } if (VK_UP == GetPressedKeyboard()) { myRect.MoveUp(5); } if (VK_DOWN == GetPressedKeyboard()) { myRect.MoveDown(5); } <<<<<<< .mine
void MainWindow::on_addSnd_clicked() { ScreenQGV::EditorType edType = ui->graphicsView->editorType(); QString selfilter = tr("All files (*.wav)"); QString filename = QFileDialog::getOpenFileName( this, QString("Select Sound"), QString(""), tr("All files (*.wav)" ), &selfilter ); if(filename.isEmpty()) return; QString newFile = m_fileManager.copyFile(filename, FileManager::OTHERSND); if(edType == ScreenQGV::MAP || edType == ScreenQGV::SCENE) { MyRect * r = MyRect::m_selectedRect; r->setSndFilepath(newFile); r->setVol(50); r->setPitch(1); } else { cout << "sound file is " << filename.toStdString() << endl; ui->graphicsView->setRewardSoundFile(newFile.toStdWString()); ui->graphicsView->setRewardSoundVolume(ui->sndVol->value()); ui->graphicsView->setRewardSoundPitch(1); QString qS = QString::fromStdWString(ui->graphicsView->getRewardSoundFile()); cout << "screen's sound file is " << qS.toStdString() << endl; } ui->addSnd->setHidden(true); ui->delSnd->setHidden(false); ui->sndVolWidg->setHidden(false); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); // Create a scene QGraphicsScene * mygamescene = new QGraphicsScene(); MyRect * player = new MyRect(); player->setRect(0,0,50,50); mygamescene->addItem(player); // Make rect respond to events player->setFlag(QGraphicsItem::ItemIsFocusable); player->setFocus(); QGraphicsView * myview = new QGraphicsView(mygamescene); myview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); myview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); myview->show(); myview->setFixedSize(800,600); mygamescene->setSceneRect(0,0,800,600); player->setPos((myview->width()-player->rect().width())/2,myview->height()-player->rect().height()); return a.exec(); }
void Draw() { // 화면 지우기 system("cls"); for (int i = 0; i < npcs.size(); i = i + 1) { // npcs[i] == MyRect npcs[i].Draw(); } /* npc1.Draw(); npc2.Draw(); npc3.Draw(); npc4.Draw(); npc5.Draw(); npc6.Draw(); npc7.Draw(); npc8.Draw(); npc9.Draw(); npc10.Draw(); */ myRect.Draw(); }
/*Tutorial: QGraphicsScene: world, player (Inivisble ~concept) QGraphicsItem(QGraphicsRectitem): goes into scene QGraphicsView: */ int main(int argc, char *argv[]) { QApplication a(argc, argv); //Create a scene QGraphicsScene *scene = new QGraphicsScene(); //Create an item to put into the scene MyRect *rect = new MyRect(); rect->setRect(0,0,100,100); //(x,y,width,height) //Add item to the Scene scene->addItem(rect); //Make Rect focusable rect->setFlag(QGraphicsItem::ItemIsFocusable); //Only one focused item at a time //Allowing rect to be focusable rect->setFocus(); //Setting rect item to focus //Add a view QGraphicsView *view = new QGraphicsView(scene); //Initializing in constructor //view->setScene(scene); alternative view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->show(); view->setFixedSize(800,600); scene->setSceneRect(0,0,800,600); rect->setPos(view->width()/2,view->height() - rect->rect().height()); //Spawn Enemies QTimer *timer = new QTimer(); QObject::connect(timer,SIGNAL(timeout()),rect,SLOT(spawn())); timer->start(2000); return a.exec(); }
void MainWindow::on_goToActivity_activated(const QString &arg1) { MyRect * r = MyRect::m_selectedRect; if(!ui->goToActivity->currentIndex()) { cout << "Setting MyRect with " << r->id() << " 0" << endl; r->setId(0); r->setGameType(GameType::NONE); ui->actPieceWidg->setHidden(true); r->setActPieceFilepath(QString("None")); if(!ui->graphicsView->actsAreInScene()) ui->chooseRewardBadge->setEnabled(false); return; } QString actType = ui->goToActivity->currentText().section(QChar('-'), 0, 0); actType = actType.remove(QChar(' ')); QString str = ui->goToActivity->currentText().section(QChar('-'), 1, 1); if(ui->graphicsView->rewardBadgeId()) ui->actPieceWidg->setHidden(false); if(!r->id()) { r->setActPieceFilepath(m_fileManager.errorImgFilepath()); ui->actPieceImg->setPixmap(QPixmap(r->actPieceFilepath()).scaled(50, 50, Qt::KeepAspectRatioByExpanding, Qt::FastTransformation)); } if(actType == QString("Pairing")) { r->setId(m_pairActs->id(str.remove(0, 1))); r->setGameType(GameType::PAIR); } else if(actType == QString("Matching")) { r->setId(m_matchActs->id(str.remove(0, 1))); r->setGameType(GameType::MATCHING); cout << "set matching" << endl; } if(r->id()) { string actFileName = MyRect::m_selectedRect->actFileName().toStdString(); Activity *act = new Activity(actFileName, NULL); act->load(); ui->actPieceImg->setPixmap(QPixmap(QString::fromStdWString(act->m_badge_piece.m_image)).scaled(50, 50, Qt::KeepAspectRatioByExpanding, Qt::FastTransformation)); r->setActPieceFilepath(QString::fromStdWString(act->m_badge_piece.m_image)); } if(ui->graphicsView->actsAreInScene()) ui->chooseRewardBadge->setEnabled(true); }
void MainWindow::on_hovLineEdit_textEdited(const QString &arg1) { MyRect * r = MyRect::m_selectedRect; r->setHoverText(arg1); }
/* GameBored contstructor * @param QWidget is the parent widget */ GameBored::GameBored(QWidget *parent) : QWidget(parent), ui(new Ui::GameBored) { ui->setupUi(this); // make scene QGraphicsScene * scene= new QGraphicsScene(); scene->setSceneRect(0,0,800,600); scene->setBackgroundBrush(QBrush(QImage(":/pics/bg"))); // make and add item to scene MyRect * player = new MyRect(); scene->addItem(player); // focus item so that it can receive keyboard events player->setFlag(QGraphicsItem::ItemIsFocusable); player->setFocus(); // add scene to new view QGraphicsView * view = new QGraphicsView(scene); //turn off scrollbars view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); Board= new QWidget; //Board->setFixedSize(400,400); // add view to new layout // add layout to central widget QVBoxLayout * vlayout = new QVBoxLayout(Board); vlayout->addWidget(view); this->setLayout(vlayout); // this->show(); view->setFixedSize(800,600); scene->setSceneRect(0,0,800,600); player->setPos(view->width()/2 -player->pixmap().width()/2, -28 /*view->height()- player->pixmap().height()*/); // constant creation of enemies QTimer* timer = new QTimer(); QObject::connect(timer,SIGNAL(timeout()),player,SLOT(spawn())); timer->start(2400); QTimer* timer2 = new QTimer(); QObject::connect(timer2,SIGNAL(timeout()),player,SLOT(spawn2())); timer2->start(5000); // play music mp3player = new QMediaPlayer(); mp3player->setMedia(QUrl("qrc:/audio/starfox.mp3")); mp3player->play(); // add score class to screen score = new Score(); scene->addItem(score); }
void RectScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPointF pos = event->scenePos(); MyRect * item = dynamic_cast<MyRect *>(itemAt(pos,QTransform())); switch (mode) { case Add: { buffer.push_back(pos); if (buffer.size() == 2) { MyRect * newrect = new MyRect(buffer[0],buffer[1]); addItem(newrect); buffer.clear(); newrect->label = giveName(namePool++); auto x = new QGraphicsTextItem(newrect->label,newrect); x->setPos(newrect->rect().center()); treescene->tree->insert(newrect->entry); update(); treescene->drawTree(); } } break; case Remove: { if (item) { removeItem(item); treescene->tree->deleteEntry(item->entry); delete item; update(); treescene->drawTree(); } } break; case Search: { if (!insearch) { insearch = true; buffer.push_back(pos); } else { insearch = false; QRectF rect(pos,buffer[0]); searchBuf.push_back(new QGraphicsRectItem(rect)); addItem(searchBuf.back()); deque<LeafEntry*> x = treescene->tree->searchOverlap(to2D(rect)); MyRect * rectpt; int n = x.size(); for (int i = 0; i<n; ++i) { rectpt =(MyRect*) x[i]->data; rectpt->setSelected(true); } buffer.clear(); } } break; } }
void MainWindow::on_mD_engage_chkBox_toggled(bool checked) { MyRect * r = MyRect::m_selectedRect; r->setMouseDownEngage(checked); }
bool CollisionProceed(MyRect& rv, MyRect& lv) { if (CollisionCheck(rv, lv)) { //물리법칙 흉내 버전 float rvCenterX = rv.x1 + rv.size / 2.0f; float lvCenterX = lv.x1 + lv.size / 2.0f; float rvCenterY = rv.y1 + rv.size / 2.0f; float lvCenterY = lv.y1 + lv.size / 2.0f; float xForce = (rv.size + lv.size) / (rvCenterX - lvCenterX) *2.0f; float yForce = (rv.size + lv.size) / (rvCenterY - lvCenterY) *2.0f; //적게 겹친 쪽만 적용. if (std::abs(xForce) < std::abs(yForce)) { rv.xVelocity += xForce / rv.size; lv.xVelocity -= xForce / lv.size; } else { rv.yVelocity += yForce / rv.size; lv.yVelocity -= yForce / lv.size; } rv.Move(rv.xVelocity/2, rv.yVelocity/2); lv.Move(lv.xVelocity/2, lv.yVelocity/2); //단순 충돌 /*float xCollisionDepth ; if (rv.x1 + rv.size - lv.x1 > 0) xCollisionDepth = rv.x1 + rv.size - lv.x1; else if (lv.x1 + lv.size - rv.x1 > 0) xCollisionDepth = lv.x1 + lv.size - rv.x1; else assert(false); float yCollisionDepth; if (rv.y1 + rv.size - lv.y1 > 0) yCollisionDepth = rv.y1 + rv.size - lv.y1; else if (lv.y1 + lv.size - rv.y1 > 0) yCollisionDepth = lv.y1 + lv.size - rv.y1; else assert(false); if (xCollisionDepth < yCollisionDepth) { rv.xVelocity = -rv.xVelocity; lv.xVelocity = -lv.xVelocity; if (rv.xVelocity > 0) { rv.Move(xCollisionDepth / 2.0f, 0); lv.Move(-xCollisionDepth / 2.0f, 0); } else { rv.Move(-xCollisionDepth / 2.0f, 0); lv.Move(xCollisionDepth / 2.0f, 0); } } else { rv.yVelocity = -rv.yVelocity; lv.yVelocity = -lv.yVelocity; if (rv.yVelocity > 0) { rv.Move(0, yCollisionDepth / 2.0f); lv.Move(0, -yCollisionDepth / 2.0f); } else { rv.Move(0, -yCollisionDepth / 2.0f); lv.Move(0, yCollisionDepth / 2.0f); } }*/ return true; } return false; }
void MainWindow::on_mU_select_chkBox_toggled(bool checked) { MyRect * r = MyRect::m_selectedRect; r->setMouseUpSelect(checked); }
void MainWindow::on_hov_select_chkBox_toggled(bool checked) { MyRect * r = MyRect::m_selectedRect; r->setHoverSelect(checked); }