void Animation::update(float dt) { if (m_pastStartTime < m_startAfterSeconds && isRunning()) { m_pastStartTime += dt; return; } if (!isRunning() || m_parent == nullptr) { return; } bool updatedSome{ false }; if (m_isRotationRunning) { updateRotation(dt); updatedSome = true; } if (m_isMovementRunning) { updateMovement(dt); updatedSome = true; } // When there was an update and the animation is not running anymore, the // animation was completed if (updatedSome && !isRunning()) { if (m_onAnimationCompleted) { m_onAnimationCompleted(); } } }
void display(void) { /* basic draw code here */ glClearColor(0.5f,0.5f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(x,1.0f,z,x+lx,1.0f,z+lz,0.0f,1.0f,0.0f); glColor3f(0.5f,0.5f,0.5f); glBegin(GL_QUADS); glVertex3f(-100.0f,0.0f,-100.0f); glVertex3f(-100.0f,0.0f,100.0f); glVertex3f(100.0f,0.0f,100.0f); glVertex3f(100.0f,0.0f,-100.0f); glEnd(); for(i=-3; i<3; i++) { for(j=-3; j<3; j++) { glPushMatrix(); glTranslatef(i*10.0,0,j*10.0); drawSnowMan(); glPopMatrix(); } } updateMovement(); glutSwapBuffers(); }
//-------------------------------------------------------------------- // animate the view BOOL GuiTestAll::animate( double now, // current time (ms) double since) // milliseconds since last pass { // rotate the cube m_angle += since/100.0; // construct eye matrix m_eyeMatrix.loadIdentity(); m_eyeMatrix.rotateZDeg(m_eyeRotZ); m_eyeMatrix.rotateYDeg(m_eyeRotY); m_eyeMatrix.rotateXDeg(m_eyeRotX); // update move/turn BOOL changed = updateMovement(now, since); changed |= m_eyeChanged; m_eyeChanged = false; if (m_ui != NULL) { m_ui->setValue(m_eyePt.x, m_eyePt.z); m_ui->animate(now, since); } return true; // cube is rotating, so it's always updating }
TetrisManager::TetrisManager(QWidget* parent, const char* name) :QMainWindow(parent, name), state(Tetris::stopped) { //Resize window to a fixed size setFixedSize(BOARD_WIDTH + 30 + 100, BOARD_HEIGHT + 20); //Create member gameBoard = new TetrisBoard(this, "board"); gameStats = new TetrisStats(this, "stats"); timer = new QTimer(this); //Set location gameBoard->move(10, 10); gameStats->move(BOARD_WIDTH + 20, 10); //Connect events related to board connect(gameBoard, SIGNAL(gameover()), this, SLOT(gameover())); connect(gameBoard, SIGNAL(blockFallen()), this, SLOT(blockFallen())); //Connect events between board and stats connect(gameBoard, SIGNAL(rowClear(int)), gameStats, SLOT(rowClear(int))); //Connect events related to timer connect(timer, SIGNAL(timeout()), this, SLOT(updateMovement())); }
void Enemy::update(float dt){ followTimer -= dt; if (followTimer <= 0) { updateMovement(); // TODO: Targt update하는 주기 상수 followTimer = 0.2f; } auto target = getTarget(); enemyAttackData.position = position; stage->ally[_OPPOSITE(ally)]->processAttack(enemyAttackData); if (skill) { if (target && cooltime <= 0.f) { useSkill(skill->id, target->position); // skill->use(this, target->position); cooltime = skill->cooltime; } else cooltime -= dt; } Unit::update(dt); }
glm::vec3 Car::movementGain(std::list<TrackTile*> allTracks, float delta) { int i; //cout << "Current: " << currentTile << "\n"; std::list<TrackTile*>::const_iterator auxTile = allTracks.begin(); for (i = 0; i < ((currentTile +1) % 40) ; i++) { ++auxTile; } glm::vec3 auxPos = glm::vec3(xPosition, yPosition, zPosition); glm::vec3 distance = (*auxTile)->getPosition() - auxPos; distance.y += yPosition; acceleration = glm::normalize(distance); glm::vec3 zAxis = glm::vec3(0, 0, 1.0f); float dot = acceleration.y * zAxis.y + acceleration.z * zAxis.z; float det = acceleration.y * zAxis.z - acceleration.z * zAxis.y; angle = atan2(det, dot) * 90/pi; //cout << angle << "\n"; updateMovement(delta); /*xPosition += direction.x * delta * 3; yPosition += direction.y; zPosition += direction.z * delta * 3;*/ //std::cout << "Dentro: " << xPosition << " " << zPosition << " " << delta << "\n"; }
void SimMovingShape::updateMoveState(SimTime dt) { float delta = dt * record.timeScale; float startTime = time; switch (state) { case Forward: { if ((time += delta) > 1.0f) { time -= 1.0f; ++wayPoint; if (!buildMovementVector(wayPoint)) { removeFromSet(SimTimerSetId); state = End; lPosition += lVector; aPosition += aVector; lVector.set(0.0f,0.0f,0.0f); aVector.set(0.0f,0.0f,0.0f); time = 0.0f; if (record.flags.test(Record::AutoBackward)) SimMessageEvent::post(this, float(manager->getCurrentTime()) + record.backwardDelay, Backward); } } if (!updateMovement()) time = startTime; break; } case Backward: { if ((time -= delta) < 0.0f) { time += 1.0f; --wayPoint; if (!buildMovementVector(wayPoint)) { removeFromSet(SimTimerSetId); time = 0.0f; state = Start; if (record.flags.test(Record::AutoForward)) SimMessageEvent::post(this, float(manager->getCurrentTime()) + record.forwardDelay, Forward); } } if (!updateMovement()) time = startTime; break; } } }
void HelloWorld::move(int _dir) { if (moveDir == _dir) { return; } moveDir = _dir; updateMovement(); }
void Locomotion::update() { if(!isActive()) return; updateMovement(Config::getParamF(Agent_Param::LocomotionSpeedMult_F), Config::getParamF(Agent_Param::LocomotionAnimSpeed_F)); //apply changes to scene graph utils::setEntityPosition(m_agent_eID, m_current); }
void Orientation::update() { if(!isActive()) return; updateMovement(Config::getParamF(Agent_Param::OrientationSpeedMult_F), Config::getParamF(Agent_Param::OrientationAnimSpeed_F)); m_current = m_morph->update(); //apply changes to scene graph utils::setEntityRotation(m_agent_eID, m_current); }
void Player::update(float dt) { if (currentState == newState || isLockState()) { updateMovement(); } else { currentState = newState; updateAnimation(); } }
void Enemy::resetAggro(){ auto players = stage->ally[Ally::Type::allyPlayer]; auto pos = position; for (auto player : *players){ auto playerPos = player->position; aggros[player] = pos.getDistance(playerPos); } updateMovement(); }
void AquariaGuiQuad::update(float dt) { // super hacky if (hasInput()) { Quad::update(dt); } else { updateMovement(dt); Quad::onUpdate(dt); } }
void Player::update(sf::Time elapsedTime) { updateMovement(elapsedTime); updateProjectiles(elapsedTime); if (getInvisible()) { invisibleTime += elapsedTime; if (invisibleTime >= sf::seconds(10)) { clearInvisible(); } } }
void EnemyBossGreen::updateAI() { if(p_player->isDead()) return; updateMovement(900.f, 1200.f, 0.5f); sf::Vector2f playerPosition = p_player->call(&sz::Transform::getPosition); sz::Transform* transform = getComponent<sz::Transform>(); sf::Vector2f myPosition = transform->getPosition(); float myangle = sz::toRadians(transform->getRotation()); float shootdistance = 1200.f; shootdistance *= shootdistance; float distance = sz::distance(myPosition, playerPosition); if(distance <= shootdistance) { if(!m_isShooting && m_shootTimer.getElapsedTime() >= m_shootDelay) { m_isShooting = true; m_shootDelay = sf::milliseconds(thor::random(40, 500)); m_shootAmount = thor::random(2, 3); m_shotCounter = 0; m_shootTimer.restart(); resetBrainfart(); } } if(m_isShooting) { if(m_shootTimer.getElapsedTime() >= m_shootDelay) { shoot<EnemyHeavyBullet>(myangle, 15.f, 40.f); m_shootTimer.restart(); if(++m_shotCounter >= m_shootAmount) { m_isShooting = false; m_shootDelay = sf::milliseconds(thor::random(2000, 3000)); } } } }
void UserCharacter::update(double time_elapsed) { _brain->process(); if (_target_system->isTargetPresent()) { if (!_target_system->getTarget()->isAlive()) _target_system->clearTarget(); } if (!isAlive()) return; updateMovement(time_elapsed); updateBuffNerf(); }
//-------------------------------------------------------------------- // animate the view BOOL Landscape::appViewAnimate( double now, // current time (ms) double since) // milliseconds since last pass { // construct eye matrix m_eyeMatrix.loadIdentity(); if (m_mapView) { m_eyeMatrix.rotateZDeg(m_eyeRotZ); m_eyeMatrix.rotateYDeg(m_eyeRotY); } else { m_eyeMatrix.rotateZDeg(m_eyeRotZ); m_eyeMatrix.rotateYDeg(m_eyeRotY); m_eyeMatrix.rotateXDeg(m_eyeRotX); } // update position BOOL changed = updateMovement(now, since); // update vertical position of eye based on landscape if (changed) { double ht = Terrain::heightAtPt(m_eyePt.x, m_eyePt.z); ht = max(ht, WATER_LEVEL); m_eyePt.y = max(m_eyePt.y, ht + MIN_HEIGHT); } // mark changed if mouse moved changed |= m_eyeChanged; m_eyeChanged = false; // animate the sky changed |= m_sky->animate(now, since); // update the terrain after movement changed |= updateTerrain(); if (m_ui != NULL) changed |= m_ui->animate(now, since); return changed; }
//------------------------------ Update --------------------------------------- //----------------------------------------------------------------------------- void TargetSplashSkill::update(double time_elapsed) { if (Clock.getCurrentTime() > _survive_time + _time_of_creation) { _dead = true; } if (_activated) { _impact_strategy->impact(); } else { _activated = _activate_strategy->test(); updateMovement(time_elapsed); } }
void TetrisManager::keyPressEvent(QKeyEvent* e) { switch(e->key()) { case Qt::Key_Up: if(state == Tetris::stopped) { start(); } break; //Block Movement case Qt::Key_Down: if(state == Tetris::playing) { //Forcedly move down updateMovement(); } break; case Qt::Key_Left: if(state == Tetris::playing) { //Move left gameBoard->moveLeft(); } break; case Qt::Key_Right: if(state == Tetris::playing) { //Move right gameBoard->moveRight(); } break; case Qt::Key_Z: if(state == Tetris::playing) { //Rotate clockwise gameBoard->rotateRight(); } break; case Qt::Key_X: if(state == Tetris::playing) { //Rotate counter-clockwise gameBoard->rotateRight(); } break; default: //Send the event to parent e->ignore(); break; } }
//-------------------------------------------------------------------- // animate the view BOOL MovementApp::appViewAnimate( double now, // current time (ms) double since) // milliseconds since last pass { // construct eye matrix m_eyeMatrix.loadIdentity(); m_eyeMatrix.rotateZDeg(m_eyeRotZ); m_eyeMatrix.rotateYDeg(m_eyeRotY); m_eyeMatrix.rotateXDeg(m_eyeRotX); // update move/turn BOOL changed = updateMovement(now, since); changed |= m_eyeChanged; m_eyeChanged = false; if (m_ui != NULL) changed |= m_ui->animate(now, since); return changed; }
void ProjectileManager::update( float dm ) { removeAllCanRemoveProjectile(); for (auto tmpIterator = m_projectilesMap.begin(); tmpIterator != m_projectilesMap.end(); tmpIterator++) { auto tmpProjectile = tmpIterator->second; if (tmpProjectile->canUpdateMovement()) { tmpProjectile->updateMovement(dm); } if (tmpProjectile->canUpdate()) { tmpProjectile->update(dm); } } removeAllCanRemoveProjectile(); }
void MissileWeapon::update(float delta) { updateMovement(); if (!launch_sound_played) { soundManager->playSound("missile_launch.wav", getPosition(), 200.0, 1.0); launch_sound_played = true; } lifetime -= delta; if (lifetime < 0) { lifeEnded(); destroy(); } setVelocity(sf::vector2FromAngle(getRotation()) * speed); if (delta > 0) ParticleEngine::spawn(sf::Vector3f(getPosition().x, getPosition().y, 0), sf::Vector3f(getPosition().x, getPosition().y, 0), sf::Vector3f(1, 0.8, 0.8), sf::Vector3f(0, 0, 0), 5, 20, 5.0); }
void HelloWorld::updateWeapon() { face = mouseX > armature->getDisplay()->getPositionX()?1: -1; if (armature->getDisplay()->getScaleX() != face) { armature->getDisplay()->setScaleX(face); updateMovement(); } float _r = 0; if(face>0) { _r = atan2(mouseY - armature->getDisplay()->getPositionY(), mouseX - armature->getDisplay()->getPositionX()) * 180 / M_PI; } else { _r = 180 - atan2(mouseY - armature->getDisplay()->getPositionY(), mouseX - armature->getDisplay()->getPositionX()) * 180 / M_PI; if (_r > 180) { _r -= 360; } } _r = -_r; CCBone *_chest = armature->getBone("chest"); _chest->getNode()->rotation=_r*0.5; CCBone *_head = armature->getBone("head"); if(_r>0) { _head->getNode()->rotation=_r*0.2; } else { _head->getNode()->rotation=_r*0.4; } CCBone *_armR = armature->getBone("upperarmR"); CCBone *_armL = armature->getBone("upperarmL"); _armR->getNode()->rotation = _r*0.5; if(_r>0) { _armL->getNode()->rotation=_r*0.8; } else { _armL->getNode()->rotation=_r*0.6; } }
void IndianaJonesUnit::update() { if (isDead() || reachedGoal){ return; } if (slowtimer > 0) { slowtimer -= gameEngine->deltaTime.asMilliseconds(); if (slowtimer <= 0) { speed = maxspeed; slowed = false; } } updateMovement(); sf::Vector2f offset(moveDirection.x * speed * gameEngine->deltaTime.asMilliseconds(), (moveDirection.y * speed * gameEngine->deltaTime.asMilliseconds())); posX += offset.x; posY += offset.y; moveHealthBar(offset); moveAnimations[currentMoveAnimationIndex]->setPos(posX, posY); moveAnimations[currentMoveAnimationIndex]->update(); float percentageHP = currentHealth / maxHealth; if (percentageHP < 0) { percentageHP = 0; } healthBarFG->setSize(healthBarBG->getSize().x * percentageHP, healthBarFG->getSize().y); groundTilesChanged = false; towerRemoved = false; }
void display(void) { glClearColor(0.2,0.5,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(x,1.0f,z,x+lx,1.0f,z+lz,0.0f,1.0f,0.0f); // Draw ground glColor3f(0.75f,0.75f,0.75f); glBegin(GL_QUADS); glVertex3f(-100.0f,0.0f,-100.0f); glVertex3f(-100.0f,0.0f,100.0f); glVertex3f(100.0f,0.0f,100.0f); glVertex3f(100.0f,0.0f,-100.0f); glEnd(); // Draw 36 SnowMen for(int i=-3; i<3; i++) { for(int j=-3; j<3; j++) { glPushMatrix(); glTranslatef(i*10.0,0,j*10.0); drawSnowman(); glPopMatrix(); } } updateMovement(); updateScene(); // if(colorMode) // glColorMask(red,green,blue,1.0f); // else // glColorMask(1.0f,1.0f,1.0f,1.0f); glutSwapBuffers(); }
void Enemy::update(float timeStep) { setMoving(false); for (auto& e : getManager()->getAll<Player>()) { Player* p = reinterpret_cast<Player*>(e); if (p->isMoving() && !p->isDead()) { setMoving(true); break; } } if (!isMoving()) return; //Update target depending on players movement and deadness. updateTarget(); if (currentTarget == NULL) return; //Determine direction of enemy so correct sprite is drawn. updateDirection(); //Movement phase updateMovement(timeStep); }
// CCSceneObject void CCSceneMoveable::update(const CCGameTime &gameTime) { super::update( gameTime ); updateMovement( gameTime.delta ); }
//-------------------------------------------------------------- // main entry int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { #ifdef DEBUG_MEMORY mgDebugMemoryInit(); #endif mgDebugReset(); // reset trace file mgOSInitTimer(); // performance timer // initialize random numbers time_t seed; time(&seed); srand(12123123); // srand(seed & 0xFFFF); mgOSFindWD("docs"); // handle utility error messages m_errorTable = new mgUtilErrorTable(); try { initWindow(); createWindow(); createBitmap(); createUI(); // create the terrain m_flatWorld = new FlatWorld(); m_flatWorld->resize(m_windowWidth, m_windowHeight); m_ui->setValue(m_flatWorld->m_playerX, m_flatWorld->m_playerY); // check for screen update every 25 ms SetTimer(m_window, 123, 25, NULL); while (true) { MSG msg; // if there is no input pending if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { // update any movement keys still down updateMovement(); // if the ui needs an update if (m_surface != NULL && m_surface->isDamaged()) { // redraw ui at damaged area mgRectangle bounds; m_surface->getDamage(bounds); m_ui->m_top->surfacePaint(bounds); // copy bits from surface into bitmap m_surface->repair(bounds); // tell windows to redraw the updated area RECT rect; rect.left = bounds.m_x; rect.right = rect.left + bounds.m_width; rect.top = bounds.m_y; rect.bottom = rect.top + bounds.m_height; InvalidateRect(m_window, &rect, false); } } GetMessage(&msg, NULL, 0, 0); // end on quit if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } // shutdown destroyUI(); destroyBitmap(); destroyWindow(); termWindow(); } catch (mgErrorMsg* e) { mgString msg; m_errorTable->msgText(msg, e); mgDebug("%s", (const char*) msg); MessageBox(m_window, msg, "Error", MB_OK | MB_ICONINFORMATION); return 0; } catch (mgException* e) { mgDebug("%s", (const char*) e->m_message); MessageBox(m_window, e->m_message, "Error", MB_OK | MB_ICONINFORMATION); return 0; } delete m_errorTable; m_errorTable = NULL; #ifdef DEBUG_MEMORY // display all memory leaks mgDebugMemory(); #endif return 0; }
void AquariaGuiQuad::onUpdate(float dt) { updateMovement(dt); Quad::onUpdate(dt); }
void RobotController::update(){ toggleRecord(); updateData(); updateMovement(); }