/** *Reference to the function declaration * @brief UIController::createAFlower */ UIController::UIController(QObject *parent) : QObject(parent) { //Initialize the main window with its components mainWindow = new MainWindow(); mainWindow->show(); //Seeding the value for a random qsrand(time(NULL)); //Initializing all the timers cFlowerTimer = new QTimer(this); mFlowerTimer = new QTimer(this); gBirdTimer = new QTimer(this); //Connecting timer to the behaviors of flowers in the main scene connect(cFlowerTimer,SIGNAL(timeout()),this,SLOT(createFlowers())); connect(mFlowerTimer,SIGNAL(timeout()),mainWindow,SLOT(moveFlowers())); //Connecting timer to the behaviors of the bird connect(gBirdTimer,SIGNAL(timeout()),mainWindow,SLOT(freeFallBird())); //Getting connect to the key event of the main window connect(mainWindow,SIGNAL(pressSpaceKey()),this,SLOT(processSpaceKeyPress())); //Getting a notify from the main window for a collision connect(mainWindow,SIGNAL(processCollision()),this,SLOT(processCollision())); //Waiting for a user to start the game isGameStarted = false; }
void specialChar( int key, int x, int y ) { if (activeBeam) //do not respond to events when tractor beam is puling in objects return; if(!gameInPlay) return; Obstacle tmpObj=(Obstacle)vehicle; switch( key ) { case GLUT_KEY_UP: tmpObj.setOrigin(currentOrigin+originInSpace); tmpObj.setOrigin(tmpObj.getOrigin()+Point(0,originInSpaceIncrement,0)); if(!processCollision(tmpObj )) { translate(0,-translateUpwardsIncrement,0); originInSpace.y+=originInSpaceIncrement; } break; case GLUT_KEY_DOWN: tmpObj.setOrigin(currentOrigin+originInSpace); tmpObj.setOrigin(tmpObj.getOrigin()-Point(0,originInSpaceIncrement,0)); if(!processCollision(tmpObj ) ) { translate(0,translateUpwardsIncrement,0); originInSpace.y-=originInSpaceIncrement; } break; case GLUT_KEY_RIGHT: rotate( 3, 0, 1, 0 ); break; case GLUT_KEY_LEFT: rotate( -3, 0, 1, 0 ); break; } display(); }
// this function handles the snowballs flying through the air void advanceProjectiles() { if(!projectiles.empty()) { vector<Snowball*>::iterator iter = projectiles.begin(); while(iter!=projectiles.end()) { if( !(*iter)->getCrashed()) { if(vehicle.objectWithinBoundingBox((Obstacle)**iter)) { //apply the damage vehicle.applyDamage((*iter)->getDamage()); sprintf_s(msgDamage,"Damage %d out of %d",vehicle.getDamage(),vehicle.getMaxDamage()); sb.setMsg2(msgDamage); if(!vehicle.getIsAlive()) { gameInPlay=false; sb.setMessage(msgMissionFailed); sb.setDisplayScore(false); } (*iter)->setCrashed(true); //we have collided with an object so hide the snowball } } if( processCollision(**iter)) (*iter)->setVisibility(false); else if(!(*iter)->getCrashed()) (*iter)->moveObstacle(); iter++; } //end of while }//end of if projectiles empty vector<Snowball*>::iterator iter = projectiles.begin(); while(iter!=projectiles.end()) { if(!(*iter)->getVisibility()) { delete *iter; projectiles.erase(iter); iter= projectiles.begin(); }else iter++; } }//end of manage projectiles
void GameRoot::collisionCheck() { // keep array safe cleanupArray->removeAllObjects(); const CCRect &rect = figure->boundingBox(); CCObject *obj; CCSprite *child; CCARRAY_FOREACH(getChildren(), obj) { child = dynamic_cast<CCSprite *> (obj); if (child && child != figure) { if (child->getPositionX() < -child->boundingBox().size.width / 2) { cleanupArray->addObject(child); } else { // check for collision if (rect.intersectsRect(child->boundingBox())) { processCollision(figure, child); } } } }
void update() { Obstacle tmpObj = vehicle; tmpObj.moveObstacle(); //MapNode *location =currMap.getNode(tmpObj.getOrigin()); //MapNode *currLocation =currMap.getNode(vehicle.getOrigin()); if (processCollision(tmpObj)) //process collisions and damage taken { //make accomodations to ensure that vehicle.setSpeed(0); vehicle.moveObstacle(); } vehicle.moveObstacle(); translate(0,0,vehicle.getSpeed()); if(activeBeam) //do not respond to events when beam is activated-drop vehicle velocity to zero { vehicle.setSpeed( -vehicle.getSpeed()); return; } //if (speed>0) if ( vehicle.getSpeed()>0 ) vehicle.setSpeed(vehicle.getSpeed()-0.001f); else vehicle.setSpeed(0); //move the enemy player controller.advanceCharacter(); display(); }
void Framework::update(){ if ( !gCircles ){ gCircles = new Circle[ N*N ]; //初期配置 for ( int i = 0; i < N*N; ++i ){ gCircles[ i ].mPosition.set( static_cast< double >( ( ( i % N ) - N/2 ) * 4 ) + 0.001 * i, //ちょっとずらす static_cast< double >( ( ( i / N ) - N/2 ) * 4 ) ); } } //速度初期化 for ( int i = 0;i < N*N; ++i ){ //速度を原点方向で初期化 gCircles[ i ].mVelocity.setMul( gCircles[ i ].mPosition, -0.001 ); } int test; int hit; processCollision( &test, &hit ); //衝突検出関数 //更新 for ( int i = 0;i < N*N; ++i ){ gCircles[ i ].mPosition += gCircles[ i ].mVelocity; //描画 double p[ 4 ][ 2 ]; p[ 0 ][ 0 ] = p[ 1 ][ 0 ] = gCircles[ i ].mPosition.x - 0.5 + 160.0; p[ 2 ][ 0 ] = p[ 3 ][ 0 ] = gCircles[ i ].mPosition.x + 0.5 + 160.0; p[ 0 ][ 1 ] = p[ 2 ][ 1 ] = gCircles[ i ].mPosition.y - 0.5 + 120.0; p[ 1 ][ 1 ] = p[ 3 ][ 1 ] = gCircles[ i ].mPosition.y + 0.5 + 120.0; drawTriangle2D( p[ 0 ], p[ 1 ], p[ 2 ] ); drawTriangle2D( p[ 3 ], p[ 1 ], p[ 2 ] ); } ostringstream oss; oss << frameRate() << " " << test << " " << hit; drawDebugString( 0, 0, oss.str().c_str() ); }
void update() { Obstacle tmpObj = vehicle; tmpObj.moveObstacle(); //MapNode *location =currMap.getNode(tmpObj.getOrigin()); //MapNode *currLocation =currMap.getNode(vehicle.getOrigin()); if (processCollision(tmpObj)) //process collisions and damage taken { //make accomodations to ensure that vehicle.setSpeed(0); vehicle.moveObstacle(); } vehicle.moveObstacle(); translate(0,0,vehicle.getSpeed()); if(activeBeam) //do not respond to events when beam is activated-drop vehicle velocity to zero { vehicle.setSpeed( -vehicle.getSpeed()); return; } //if (speed>0) if ( vehicle.getSpeed()>0 ) vehicle.setSpeed(vehicle.getSpeed()-0.001f); else vehicle.setSpeed(0); //move the enemy player controller.advanceCharacter(); //if NPC is throwing snowball then handle it //create a snowball projectile if(npc.getCurrentState()==RELEASE_SNOWBALL) { Snowball *newSnowball = new Snowball( SNOWBALLID, npc.getOrigin(), //startPoint vehicle.getOrigin(),// endPoint npc.getSnowRadius(), snowballSpeed, //speed at which the snowball flies through the air minCoords, //the coords that the snowball will crash and dissolve maxCoords, snowballDamage, snowballGravity, snowballAirFriction, textures[FLOORID] ); projectiles.push_back(newSnowball); } //manage snowballs and the damage inflicted on the vehicle advanceProjectiles(); display(); }
void Player::update(float32 deltaSeconds) { const static float32 JUMP_POWER = 7.0f; const static float32 SPEED = 5.0f; const static float32 ROTATE_SPEED = 0.01f; const static int MAX_JUMP_FRAMES = 15; m_currentPosition = glm::vec3(transform.xPos, transform.yPos, transform.zPos); m_lastPosition = m_currentPosition; // Get current chunk ChunkManager* cm = ChunkManager::instance(); m_chunkValid = cm->getChunkHandle(cm->getCurrentChunk(m_currentPosition), m_currentChunk); // DONT UPDATE ME IF MY CHUNK ISNT VALID YET GOOOSH if (!m_chunkValid) { return; } static bool hasLanded = false; float32 dx = 0; float32 dy = 0; float32 dz = 0; if (m_forwardPressed) { --dz; } if (m_backwardPressed) { ++dz; } if (m_leftPressed) { --dx; } if (m_rightPressed) { ++dx; } glm::vec3 displacement = glm::rotate(transform.rotation, glm::vec3(dx, 0, dz)); displacement.y = 0; displacement = glm::normalize(displacement); displacement *= SPEED * deltaSeconds; // Numerical approximation via Euler Integration dy = m_velocityY * deltaSeconds; m_velocityY += GRAVITY * deltaSeconds; //displacement.y = dy; //transform.translate(displacement); if (dx || dz) { transform.translate(displacement); } if (!m_glueToGround) { transform.translate(0, dy, 0); } if (dx || (dy && !m_glueToGround) || dz) { m_movedDuringFrame = true; } else { m_movedDuringFrame = false; } //transform.translateLocal(dx, 0, dz); //transform.translate(0, dy, 0); // Apply jump if (m_jumpPressed) { // Apply impulse and cancel gravity m_velocityY = JUMP_POWER; m_jumpPressed = false; m_glueToGround = false; } //if (m_jumpPressed) { // if (!m_isJumping && hasLanded) // { // m_isJumping = true; // hasLanded = false; // } //} // //if(m_ready && !m_isJumping) // dy += GRAVITY * deltaSeconds; //else if (m_ready && m_isJumping) //{ // dy -= GRAVITY * deltaSeconds; // m_jumpedFrames++; // // if (m_jumpedFrames > MAX_JUMP_FRAMES) // { // m_jumpedFrames = 0; // m_isJumping = false; // } //} glm::vec3 deltaPos(dx, dy, dz); deltaPos = (glm::normalize(deltaPos) * SPEED * deltaSeconds); // if you are in the water (below it), move half as much per frame if (m_currentPosition.y < m_swimY) deltaPos = glm::clamp(deltaPos, -0.45f, 0.45f); else deltaPos = glm::clamp(deltaPos, -0.9f, 0.9f); //Check if the chunk you are in has changed //checkChunk(); // //glm::vec3 newPosition = glm::vec3(transform.xPos + deltaPos.x, transform.yPos + deltaPos.y, transform.zPos + deltaPos.z); // //Collision coll = checkForSurroundingBlocks(newPosition); // //switch (coll) //{ //case(Collision::Colliding): // std::cout << "Colliding" << std::endl; // hasLanded = true; // break; //case(Collision::NoCollision): // if (dx != 0 || dy != 0 || dz != 0) // transform.translateLocal(deltaPos.x, deltaPos.y, deltaPos.z); // break; //case(Collision::CollidingNotY): // if (dx != 0 || dz != 0) // transform.translateLocal(deltaPos.x, 0.0f, deltaPos.z); // hasLanded = true; // break; //case(Collision::NoCollisionUpOne): // if (dx != 0 || dz != 0) // transform.translateLocal(deltaPos.x, 1.0f, deltaPos.z); // hasLanded = true; // break; //} /* Collision coll = checkForShubbery(newPosition); if (coll) { // congrats you hit a tree... switch (coll) { case(Collision::Colliding): hasLanded = true; break; case(Collision::CollidingXZ): if (dy != 0) transform.translateLocal(0.0f, deltaPos.y, 0.0f); break; } } else { coll = checkForSurroundingBlocks(newPosition); switch (coll) { case(Collision::Colliding): std::cout << "Colliding" << std::endl; hasLanded = true; break; case(Collision::NoCollision): if (dx != 0 || dy != 0 || dz != 0) transform.translateLocal(deltaPos.x, deltaPos.y, deltaPos.z); break; case(Collision::CollidingNotY): if (dx != 0 || dz != 0) transform.translateLocal(deltaPos.x, 0.0f, deltaPos.z); hasLanded = true; break; case(Collision::NoCollisionUpOne): if (dx != 0 || dz != 0) transform.translateLocal(deltaPos.x, 1.0f, deltaPos.z); hasLanded = true; break; } } */ // update the camera's transform m_camera->transform.xPos = transform.xPos; m_camera->transform.yPos = transform.yPos + 1.0f; m_camera->transform.zPos = transform.zPos; glm::vec2 mouseAxis = getMouseAxis() * ROTATE_SPEED; if (true) { if (abs(mouseAxis.x) > abs(mouseAxis.y)) { mouseAxis.y = 0; } else { mouseAxis.x = 0; } transform.rotate(0, -mouseAxis.x, 0); m_camera->transform.rotateLocal(mouseAxis.y, 0, 0); m_camera->transform.rotate(0, -mouseAxis.x, 0); } m_currentPosition = glm::vec3(transform.xPos, transform.yPos, transform.zPos); if (m_movedDuringFrame) { processCollision(); } }