void SchoolFish::onUpdate(float dt) { BBGE_PROF(SchoolFish_onUpdate); /* Quad::onUpdate(dt); return; */ /* if (dsq->continuity.form == FORM_BEAST) this->activationType = ACT_CLICK; else this->activationType = ACT_NONE; */ /* if (burstDelay == 0) { maxSpeedLerp = 2; Vector v = getNormal(); vel = 0; v *= -5000; vel += v; //float t = (100 + rand()%100)/100.0; float t = 2; maxSpeedLerp.interpolateTo(1, t); burstDelay = 10;// + (rand()%100)/100.0; //rotateToVec(v, 0, 90); //rotation.interpolateTo(0, 1); if (v.x > 0 && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (v.x < 0 && isfh()) { flipHorizontal(); flipDelay = 0.5; } } else */ { burstDelay -= dt; if (burstDelay < 0) { burstDelay = 0; } } if (stickToNaijasHead && alpha.x < 0.1) stickToNaijasHead = false; if (this->layer < LR_ENTITIES) { //debugLog("background fish!"); /* setDamageTarget(DT_AVATAR_SHOCK, false); setDamageTarget(DT_AVATAR_BITE, false); setDamageTarget(DT_AVATAR_VOMIT, false); setDamageTarget(DT_AVATAR_ENERGYBLAST, false); */ setEntityType(ET_NEUTRAL); collideRadius = 0; } if (getState() == STATE_DEAD) { FlockEntity::onUpdate(dt); respawnTimer -= dt; if (!(dsq->game->avatar->position - this->position).isLength2DIn(2000)) { if (respawnTimer < 0) { respawnTimer = 0; perform(STATE_IDLE); } } } else { /* if (layer == LR_ENTITIES || layer == LR_ENTITIES2) { rippleTimer -= dt; if (rippleTimer < 0) { if (core->afterEffectManager) core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),position,0.04,0.06,15,0.2f)); rippleTimer = 0.5; } } */ FlockEntity::onUpdate(dt); if (dsq->game->isValidTarget(this, 0)) dsq->game->handleShotCollisions(this); /* soundDelay -= dt; if (soundDelay <= 0) { //sound(swimSound, 1000 + rand()%100); soundDelay = 4+(rand()%50)/100.0; } */ /* 1. if distance_to(closest_boid) <= too_close then set direction away from closest_boid 2. speed_of_neighbors := average(speed(x), for all x where distance_to(x) <= neighborhood_size) direction_of_neighbors := avg(direction(x), for all x where distance_to(x) <= neighborhood_size) if speed < speed_of_neighbors then increase speed if speed > speed_of_neighbors then decrease speed turn towards direction_of_neighbors 3. position_of_neighbors := avg(position(x), for all x where distance_to(x) <= neighborhood_size) turn towards position_of_neighbors */ float seperation = 1; float alignment = 0; float cohesion = 0.75; /* FlockPiece flock; getFlockInRange(160, &flock); */ // if flock in 160 ? if (true) { VectorSet newDirection; if (avoidTime>0) { avoidTime -= dt; if (avoidTime<0) avoidTime=0; } Vector dir = getFlockHeading(); Vector accumulator; applyCohesion(accumulator); applyAlignment(accumulator, dir); // alignment applySeparation(accumulator); applyAvoidance(accumulator); updateVelocity(accumulator); /* if (dsq->game->isValidTarget(this, 0)) doSpellAvoidance(dt, 96, dodgeAbility); */ Vector lastPosition = position; Vector newPosition = position + (vel*velocityScale*dt) + vel2*dt; position = newPosition; if (dsq->game->isObstructed(position)) { position = lastPosition; /* position = Vector(newPosition.x, lastPosition.y); if (dsq->game->isObstructed(position)) { position = Vector(lastPosition.x, newPosition.y); if (dsq->game->isObstructed(position)) { position = lastPosition; } } */ } //updateCurrents(dt); updateVel2(dt); /* if (flipDelay > 0) { flipDelay -= dt; if (flipDelay < 0) { flipDelay = 0; } } */ flipDelay = 0; //dir.normalize2D(); if (flipDelay <= 0) { const float amt = 0; /* if (fabs(dir.x) > fabs(dir.y)) { if (dir.x > amt && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (dir.x < -amt && isfh()) { flipHorizontal(); flipDelay = 0.5; } } */ if (vel.x > amt && !isfh()) { flipHorizontal(); } if (vel.x < -amt && isfh()) { flipHorizontal(); } } //rotateToVec(accumulator, 5, 90); float angle = atan(dir.y/dir.x); angle = ((angle*180)/3.14); if (angle > 45) angle = 45; if (angle < -45) angle = -45; rotation = Vector(0,0,angle); //rotation.interpolateTo(Vector(0, 0, angle), 0); } } }
void CollideEntity::updateMovement(float dt) { if (isEntityDead()) return; if (position.isFollowingPath()) return; vel.capLength2D(getMaxSpeed()*maxSpeedLerp.x); /* if (vel.getSquaredLength2D() > sqr(getMaxSpeed())) { vel.setLength2D(getMaxSpeed()); vel.z = 0; } */ //Vector lastPos = pos; updateVel2(dt); if (doCusion) { Vector push; TileVector t(position+vel*dt); if (dsq->game->isObstructed(TileVector(t.x-1, t.y))) { push += Vector(1.25,0); } if (dsq->game->isObstructed(TileVector(t.x+1, t.y))) { push += Vector(-1.25,0); } if (dsq->game->isObstructed(TileVector(t.x, t.y-1))) { push += Vector(0,1.25); } if (dsq->game->isObstructed(TileVector(t.x, t.y+1))) { push += Vector(0,-1.25); } if (dsq->game->isObstructed(TileVector(t.x-1, t.y-1))) { push += Vector(0.5,0.5); } if (dsq->game->isObstructed(TileVector(t.x-1, t.y+1))) { push += Vector(0.5,-0.5); } if (dsq->game->isObstructed(TileVector(t.x+1, t.y-1))) { push += Vector(-0.5,0.5); } if (dsq->game->isObstructed(TileVector(t.x+1, t.y+1))) { push += Vector(-0.5,-0.5); } // cushion if (push.x != 0 || push.y != 0) { if (vel.getSquaredLength2D() > sqr(10)) { push.setLength2D(100 * dt * 60); push.z = 0; } vel += push; } } Vector lastPosition = position; bool underWater = isUnderWater(); if (!canLeaveWater) { if (!underWater && wasUnderWater) { // do clamp if (waterBubble) { waterBubble->clampPosition(&position, collideRadius); } else { position.y = dsq->game->getWaterLevel()+collideRadius; } } } /* if (!canLeaveWater) { if (waterBubble) { } else { if (position.y-collideRadius < dsq->game->getWaterLevel()) { } } } */ bool collided = false; if (vel.x != 0 || vel.y != 0) { const int hw = collideRadius; bool freeRange = false; if (isv(EV_COLLIDELEVEL,1)) { bool doesFreeRange = !isPullable(); if (doesFreeRange) { if (dsq->game->collideCircleWithGrid(position, hw)) { // starting in a collision state freeRange = true; } } } //Vector lastPosition = lastPos; Vector newPosition = position + (getMoveVel() * dt); position = newPosition; if (isv(EV_COLLIDELEVEL,1)) { if (getState() == STATE_PUSH) { if (!freeRange && dsq->game->collideCircleWithGrid(position, hw)) { position = lastPosition; collided = true; bounce(bounceAmount); } } else { if (!freeRange && ((!canLeaveWater && !isUnderWater() && wasUnderWater) || dsq->game->collideCircleWithGrid(position, hw))) { position = lastPosition; onHitWall(); bounce(bounceAmount); collided = true; } } } } if (collided && friction != 0 && (vel.x != 0 || vel.y != 0)) { Vector fric = vel; fric.setLength2D(-friction); vel.z = 0; vel += fric*dt; } //doFriction(dt); if (!collided && weight != 0) { vel += Vector(0, weight*dt); } for (int i = 0; i < attachedEntities.size(); i++) { attachedEntities[i]->position = this->position + attachedEntitiesOffsets[i]; attachedEntities[i]->rotation = this->rotation; } wasUnderWater = underWater; }