void EnemyPatroller::update(double dt) { if(!dying) { //setCurrentAnimation("walk"); const int speed_gravity = 960; const double vision_range = 320; const double vision_min_range = 32; if(isGrounded()) { if (facing_direction == Facing::Left) { if(body->v.x > -walk_speed) cpBodyApplyImpulse(body, cpv(-500, 0), cpv(0, 0)); if(!leftBumper->isGrounded()) facing_direction = Facing::Right; } else if (facing_direction == Facing::Right) { if(body->v.x < walk_speed) cpBodyApplyImpulse(body, cpv(500, 0), cpv(0, 0)); if(!rightBumper->isGrounded()) facing_direction = Facing::Left; } } updateSpriteFacing(); } }
void Troll::update(float dt) { if (!dead) { ai->update(dt); } else { deathTimer += dt; if (!isFading) { if (deathAnim.curFrame != deathAnim.framesInAnimation-1) { rect = deathAnim.update(dt); } if (deathTimer >= timeToDie) { if (isGrounded()) { deleteBody(); isFading = true; deathTimer = 0.f; rect = deathAnim.frameIndex(deathAnim.framesInAnimation-1); } } else if (isGrounded()) { deleteBody(); } } else { if (deathTimer > fadeTime-1.f) { color.a = fadeTime - deathTimer; if (deathTimer >= fadeTime) { parent->removeChild(this, true); } } } } }
void Actor::jump() { if (isGrounded()) { body->SetLinearVelocity(b2Vec2_zero); body->ApplyLinearImpulse(b2Vec2(0.f, jumpForce), body->GetPosition()); } }
void Player::doJump() { if(isGrounded()){ b2Vec2 direction; if(body->GetLinearVelocity().y > -0.01) direction = b2Vec2(0, -250); else direction = b2Vec2(0, -125); body->ApplyForceToCenter(direction); } setState(PlayerJumping); }
void Player::step(float frame, float time) { this->time = time; applyImpulse(frame); run->apply(skeleton.get(), time, true); skeleton->getRootBone()->x = X_OFFSET; skeleton->getRootBone()->y = Y_OFFSET; skeleton->updateWorldTransform(); b2Vec2 speed = body->GetLinearVelocity(); sync(); if(speed.y > 1 && !isGrounded()) { setState(PlayerFalling); } else if(state == PlayerFalling && speed.y > -0.1){ setState(PlayerStanding); } else if(state == PlayerPreJump){ if(time > jumpStart + 0.05) doJump(); } else if(state == PlayerRunning && (impulse == ImpulseNone || impulse == ImpulseBoth) && speed.x < 0.1 && speed.x > -0.1){ setState(PlayerStanding); } }