void GameMainController::onStart(cocos2d::EventCustom * pEvent) { if (_pEventListenerStartGame) { Director::getInstance()->getEventDispatcher()->removeEventListener(_pEventListenerStartGame); CC_SAFE_RELEASE_NULL(_pEventListenerStartGame); } CC_SAFE_RELEASE_NULL(_pEventListenerStopGame); _pEventListenerStopGame = Director::getInstance()->getEventDispatcher()->addCustomEventListener ( RegitsteredEvents::GAME_OVER, std::bind(&GameMainController::onStop, this, std::placeholders::_1) ); CC_SAFE_RETAIN(_pEventListenerStopGame); CC_SAFE_RELEASE_NULL(_pEventListenerRestartGame); _pEventListenerRestartGame = Director::getInstance()->getEventDispatcher()->addCustomEventListener ( RegitsteredEvents::GAME_RESTART, std::bind(&GameMainController::onRestart, this, std::placeholders::_1) ); CC_SAFE_RETAIN(_pEventListenerRestartGame); CC_SAFE_RELEASE_NULL(_pEventListenerShowRestartButton); _pEventListenerShowRestartButton = Director::getInstance()->getEventDispatcher()->addCustomEventListener ( RegitsteredEvents::SHOW_RESTART, std::bind(&GameMainController::onShowRestart, this, std::placeholders::_1) ); CC_SAFE_RETAIN(_pEventListenerShowRestartButton); _pMapSceneController->startGame(); _pPlayerController->startGame(); _pNpcController->startGame(); setMoveMode(GameMainController::PLAYER); }
void Fodder::setTurnRate(float turn) { setMoveMode(moveMode::kTurn); setRotation3D(Vertex3F(fabsf(turn)*0.15, turn, 0)); _turn = turn; }
Spinwidget::Spinwidget(double *x, double *y, double *z, int *n, int *colors, int* cols, double *max, char** names, char **colnames, QWidget *parent) : QWidget(parent) { // icon dialog first Icondialog icondialog(this); Iconview::Icon selectedIcon = Iconview::Cross; if(icondialog.exec()) { Iconview *iv = static_cast<Iconview *>(icondialog.focusWidget()); selectedIcon = iv->getIcon(); } // Layouts gridLayout = new QGridLayout(this); QVBoxLayout *leftLayout = new QVBoxLayout(0); QVBoxLayout *rightLayout = new QVBoxLayout(0); // OpenGL View view = new Spinview(x, y, z, n, colors, max, selectedIcon, names, colnames, cols, this); //gridLayout->addWidget(view, 0, 1, 7, 4); // Zoom In Button QPushButton *button_zoomin = new QPushButton("+"); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(button_zoomin->sizePolicy().hasHeightForWidth()); button_zoomin->setSizePolicy(sizePolicy); button_zoomin->setFixedSize(QSize(35, 35)); button_zoomin->setToolTip(tr("Zoom in")); //gridLayout->addWidget(button_zoomin, 0, 5, 1, 1); rightLayout->addWidget(button_zoomin); connect(button_zoomin, SIGNAL(clicked()), this, SLOT(zoomInClicked())); // Zoom Slider slider_zoom = new QSlider(this); slider_zoom->setMinimumSize(QSize(30, 0)); slider_zoom->setOrientation(Qt::Vertical); slider_zoom->setMinimum(1); slider_zoom->setMaximum(100); slider_zoom->setSingleStep(1); slider_zoom->setPageStep(10); slider_zoom->setValue(30); slider_zoom->setInvertedAppearance(true); slider_zoom->setInvertedControls(true); slider_zoom->setToolTip(tr("Zoom in/out")); //gridLayout->addWidget(slider_zoom, 1, 5, 5, 1); rightLayout->addWidget(slider_zoom); connect(slider_zoom, SIGNAL(valueChanged(int)), this, SLOT(zoomChanged(int))); // ZoomOut Button QPushButton *button_zoomout = new QPushButton("-"); sizePolicy.setHeightForWidth(button_zoomout->sizePolicy().hasHeightForWidth()); button_zoomout->setSizePolicy(sizePolicy); button_zoomout->setFixedSize(QSize(35, 35)); button_zoomout->setToolTip(tr("Zoom out")); //gridLayout->addWidget(button_zoomout, 6, 5, 1, 1); rightLayout->addWidget(button_zoomout); connect(button_zoomout, SIGNAL(clicked()), this, SLOT(zoomOutClicked())); // info label info = new QLabel(this); gridLayout->addWidget(info, 1, 1); // exit button QPushButton *button_exit = new QPushButton(this); button_exit->setFixedSize(QSize(35, 35)); button_exit->setToolTip(tr("Exit")); QIcon icon7; icon7.addPixmap(QPixmap(QString::fromUtf8(":/images/exit.png")), QIcon::Normal, QIcon::Off); button_exit->setIcon(icon7); gridLayout->addWidget(button_exit, 1, 2); connect(button_exit, SIGNAL(clicked()), this, SLOT(close())); // Rotate Mode Button QPushButton *button_rotate = new QPushButton(this); connect(button_rotate, SIGNAL(clicked()), this, SLOT(setRotateMode())); button_rotate->setFixedSize(QSize(35, 35)); QIcon icon; icon.addPixmap(QPixmap(QString::fromUtf8(":/images/rotate.png")), QIcon::Normal, QIcon::Off); button_rotate->setIcon(icon); button_rotate->setAutoExclusive(true); button_rotate->setCheckable(true); button_rotate->setToolTip(tr("Spin")); //gridLayout->addWidget(button_rotate, 0, 0, 1, 1); leftLayout->addWidget(button_rotate); // Move Mode Button QPushButton *button_move = new QPushButton(this); button_move->setFixedSize(QSize(35, 35)); QIcon icon1; icon1.addPixmap(QPixmap(QString::fromUtf8(":/images/move.png")), QIcon::Normal, QIcon::Off); button_move->setIcon(icon1); button_move->setAutoExclusive(true); button_move->setCheckable(true); button_move->setToolTip(tr("Move")); //gridLayout->addWidget(button_move, 1, 0, 1, 1); leftLayout->addWidget(button_move); connect(button_move, SIGNAL(clicked()), this, SLOT(setMoveMode())); // Brush Mode Button QPushButton *button_brush = new QPushButton(this); button_brush->setFixedSize(QSize(35, 35)); QIcon icon2; icon2.addPixmap(QPixmap(QString::fromUtf8(":/images/brush.png")), QIcon::Normal, QIcon::Off); button_brush->setIcon(icon2); button_brush->setAutoExclusive(true); button_brush->setCheckable(true); button_brush->setToolTip(tr("Brush")); //gridLayout->addWidget(button_brush, 2, 0, 1, 1); leftLayout->addWidget(button_brush); connect(button_brush, SIGNAL(clicked()), this, SLOT(setBrushMode())); // Info Mode Button QPushButton *button_info = new QPushButton(this); button_info->setFixedSize(QSize(35, 35)); QIcon icon3; icon3.addPixmap(QPixmap(QString::fromUtf8(":/images/info.png")), QIcon::Normal, QIcon::Off); button_info->setIcon(icon3); button_info->setAutoExclusive(true); button_info->setCheckable(true); button_info->setToolTip(tr("Info")); //gridLayout->addWidget(button_brush, 2, 0, 1, 1); leftLayout->addWidget(button_info); connect(button_info, SIGNAL(clicked()), this, SLOT(setInfoMode())); QPushButton *button_identify = new QPushButton(this); button_identify->setFixedSize(QSize(35, 35)); QIcon icon8; icon8.addPixmap(QPixmap(QString::fromUtf8(":/images/identify.png")), QIcon::Normal, QIcon::Off); button_identify->setIcon(icon8); button_identify->setAutoExclusive(true); button_identify->setCheckable(true); button_identify->setToolTip(tr("Identify")); //gridLayout->addWidget(button_brush, 2, 0, 1, 1); leftLayout->addWidget(button_identify); connect(button_identify, SIGNAL(clicked()), this, SLOT(setIdentifyMode())); // Spacer leftLayout->addStretch(1); // item change button QPushButton *button_item = new QPushButton(this); button_item->setFixedSize(QSize(35, 35)); QIcon icon6; icon6.addPixmap(QPixmap(QString::fromUtf8(":/images/icons.png")), QIcon::Normal, QIcon::Off); button_item->setIcon(icon6); button_item->setToolTip(tr("Change Item type")); leftLayout->addWidget(button_item); connect(button_item, SIGNAL(clicked()), this, SLOT(changeIcon())); // Spacer leftLayout->addStretch(1); Aboutwidget *about = new Aboutwidget(this); // about S&B Button QPushButton *button_sb = new QPushButton(this); button_sb->setFixedSize(QSize(35, 35)); QIcon icon5; icon5.addPixmap(QPixmap(QString::fromUtf8(":/images/logo.png")), QIcon::Normal, QIcon::Off); button_sb->setIcon(icon5); button_sb->setToolTip(tr("About")); leftLayout->addWidget(button_sb); connect(button_sb, SIGNAL(clicked()), about, SLOT(exec())); // about Qt Button QPushButton *button_qt = new QPushButton(this); button_qt->setFixedSize(QSize(35, 35)); QIcon icon4; icon4.addPixmap(QPixmap(QString::fromUtf8(":/images/qt.png")), QIcon::Normal, QIcon::Off); button_qt->setIcon(icon4); button_qt->setToolTip(tr("About Qt")); //gridLayout->addWidget(button_qt, 6, 0, 1, 1); leftLayout->addWidget(button_qt); connect(button_qt, SIGNAL(clicked()), qApp, SLOT(aboutQt())); move(200, 200); // move widget on screen // Group Widget Groupwidget *groupWidget = new Groupwidget(view, this); groupWidget->setWindowIcon(icon2); connect(button_brush, SIGNAL(toggled(bool)), groupWidget, SLOT(setVisible(bool))); connect(groupWidget, SIGNAL(indexChanged(const int &)), view, SLOT(setGroupIndex(const int &))); connect(groupWidget, SIGNAL(colorChanged(const int &, const QColor &)), view, SLOT(setColor(const int &, const QColor &))); // Rotate Widget Rotatewidget *rotateWidget = new Rotatewidget(view, this); rotateWidget->setWindowIcon(icon); connect(button_rotate, SIGNAL(toggled(bool)), rotateWidget, SLOT(setVisible(bool))); // Identify Widget Identifywidget *identifyWidget = new Identifywidget(*n, names, this); identifyWidget->setWindowIcon(icon8); connect(button_identify, SIGNAL(toggled(bool)), identifyWidget, SLOT(setVisible(bool))); connect(identifyWidget, SIGNAL(identify(int)), view, SLOT(identify(int))); gridLayout->addLayout(leftLayout, 0, 0); gridLayout->addWidget(view, 0, 1); gridLayout->addLayout(rightLayout, 0, 2); setLayout(gridLayout); setWindowTitle(tr("Spin & Brush")); setWindowIcon(icon5); button_rotate->click(); // click() instead of setChecked(true) ist used to emit signal connect(view, SIGNAL(zoomChanged(int)), slider_zoom, SLOT(setValue(int))); Legendwidget *legend = new Legendwidget(colnames, this); legend->show(); }
/** * This method is just called to stop the bots from running amuck * while the mission cycles */ void AIClient::missionCycleCleanup() { setMoveMode( ModeStop ); }
/** * This method gets the move list for an object, in the case * of the AI, it actually calculates the moves, and then * sends them down the pipe. * * @param movePtr Pointer to move the move list into * @param numMoves Number of moves in the move list */ U32 AIClient::getMoveList( Move **movePtr,U32 *numMoves ) { //initialize the move structure and return pointers mMove = NullMove; *movePtr = &mMove; *numMoves = 1; // Check if we got a player mPlayer = NULL; mPlayer = dynamic_cast<Player *>( getControlObject() ); // We got a something controling us? if( !mPlayer ) return 1; // What is The Matrix? MatrixF moveMatrix; moveMatrix.set( EulerF( 0, 0, 0 ) ); moveMatrix.setColumn( 3, Point3F( 0, 0, 0 ) ); moveMatrix.transpose(); // Position / rotation variables F32 curYaw, curPitch; F32 newYaw, newPitch; F32 xDiff, yDiff; F32 moveSpeed = mMoveSpeed; switch( mMoveMode ) { case ModeStop: return 1; // Stop means no action break; case ModeStuck: // Fall through, so we still try to move case ModeMove: // Get my location MatrixF const& myTransform = mPlayer->getTransform(); myTransform.getColumn( 3, &mLocation ); // Set rotation variables Point3F rotation = mPlayer->getRotation(); Point3F headRotation = mPlayer->getHeadRotation(); curYaw = rotation.z; curPitch = headRotation.x; xDiff = mAimLocation.x - mLocation.x; yDiff = mAimLocation.y - mLocation.y; // first do Yaw if( !mIsZero( xDiff ) || !mIsZero( yDiff ) ) { // use the cur yaw between -Pi and Pi while( curYaw > M_2PI_F ) curYaw -= M_2PI_F; while( curYaw < -M_2PI_F ) curYaw += M_2PI_F; // find the new yaw newYaw = mAtan2( xDiff, yDiff ); // find the yaw diff F32 yawDiff = newYaw - curYaw; // make it between 0 and 2PI if( yawDiff < 0.0f ) yawDiff += M_2PI_F; else if( yawDiff >= M_2PI_F ) yawDiff -= M_2PI_F; // now make sure we take the short way around the circle if( yawDiff > M_2PI_F ) yawDiff -= M_2PI_F; else if( yawDiff < -M_2PI_F ) yawDiff += M_2PI_F; mMove.yaw = yawDiff; // set up the movement matrix moveMatrix.set( EulerF( 0.0f, 0.0f, newYaw ) ); } else moveMatrix.set( EulerF( 0.0f, 0.0f, curYaw ) ); // next do pitch F32 horzDist = Point2F( mAimLocation.x, mAimLocation.y ).len(); if( !mIsZero( horzDist ) ) { //we shoot from the gun, not the eye... F32 vertDist = mAimLocation.z; newPitch = mAtan2( horzDist, vertDist ) - ( M_2PI_F / 2.0f ); F32 pitchDiff = newPitch - curPitch; mMove.pitch = pitchDiff; } // finally, mMove towards mMoveDestination xDiff = mMoveDestination.x - mLocation.x; yDiff = mMoveDestination.y - mLocation.y; // Check if we should mMove, or if we are 'close enough' if( ( ( mFabs( xDiff ) > mMoveTolerance ) || ( mFabs( yDiff ) > mMoveTolerance ) ) && ( !mIsZero( mMoveSpeed ) ) ) { if( mIsZero( xDiff ) ) mMove.y = ( mLocation.y > mMoveDestination.y ? -moveSpeed : moveSpeed ); else if( mIsZero( yDiff ) ) mMove.x = ( mLocation.x > mMoveDestination.x ? -moveSpeed : moveSpeed ); else if( mFabs( xDiff ) > mFabs( yDiff ) ) { F32 value = mFabs( yDiff / xDiff ) * mMoveSpeed; mMove.y = ( mLocation.y > mMoveDestination.y ? -value : value ); mMove.x = ( mLocation.x > mMoveDestination.x ? -moveSpeed : moveSpeed ); } else { F32 value = mFabs( xDiff / yDiff ) * mMoveSpeed; mMove.x = ( mLocation.x > mMoveDestination.x ? -value : value ); mMove.y = ( mLocation.y > mMoveDestination.y ? -moveSpeed : moveSpeed ); } //now multiply the mMove vector by the transpose of the object rotation matrix moveMatrix.transpose(); Point3F newMove; moveMatrix.mulP( Point3F( mMove.x, mMove.y, 0.0f ), &newMove ); //and sub the result back in the mMove structure mMove.x = newMove.x; mMove.y = newMove.y; // We should check to see if we are stuck... if( mLocation.x == mLastLocation.x && mLocation.y == mLastLocation.y && mLocation.z == mLastLocation.z ) { // We're stuck...probably setMoveMode( ModeStuck ); } else setMoveMode( ModeMove ); } else { // Ok, we are close enough, lets stop // setMoveMode( ModeStop ); // DON'T use this, it'll throw the wrong callback mMoveMode = ModeStop; throwCallback( "onReachDestination" ); // Callback } break; } // Test for target location in sight RayInfo dummy; Point3F targetLoc = mMoveDestination; // Change this if( mPlayer ) { if( !mPlayer->getContainer()->castRay( mLocation, targetLoc, StaticShapeObjectType | StaticObjectType | TerrainObjectType, &dummy ) ) { if( !mTargetInLOS ) throwCallback( "onTargetEnterLOS" ); } else { if( mTargetInLOS ) throwCallback( "onTargetExitLOS" ); } } // Copy over the trigger status for( int i = 0; i < MaxTriggerKeys; i++ ) { mMove.trigger[i] = mTriggers[i]; mTriggers[i] = false; } return 1; }