Пример #1
0
void EnemyBoss::movement(float deltaTime, Background *bg){

        if(_dir == direction::none)     getNewDirection();
        if(_dir == direction::up)       _vel.y = -ENEMSPEED*deltaTime*_movementScaler;
        if(_dir == direction::left)     _vel.x = -ENEMSPEED*deltaTime*_movementScaler;
        if(_dir == direction::down)     _vel.y =  ENEMSPEED*deltaTime*_movementScaler;
        if(_dir == direction::right)    _vel.x =  ENEMSPEED*deltaTime*_movementScaler;

        _movementScaler += deltaTime;
        if(_movementScaler > 1.5) {
            if(_movementScaler < 1.6 && rand()%3 == 0) getNewDirection();
            _movementScaler = 1.6;
        }

        sf::Vector2f dest(_vel.x, _vel.y);

        //colide on y
        sf::FloatRect desrect = getGlobalBounds();
        desrect.top += _vel.y;
        if(bg->rectangleColision( desrect )){
            _vel.y = 0; _dir = direction::none;
        } else move(0, dest.y);
        desrect.top -= _vel.y;
        desrect.left += _vel.x;
        //colide on x
        if(bg->rectangleColision( desrect )){
            _vel.x = 0; _dir = direction::none;
        } else move(dest.x, 0);
}
Пример #2
0
bool Ghost::crossingBlockCenter(int, QPointF newPosition) {
    QPoint newDirection = getNewDirection();

    if(_direction == newDirection) {
        return false;
    }

    _direction = newDirection;

    QPointF center(alignToCenter(newPosition.x()), alignToCenter(newPosition.y()));

    QPointF difference = newPosition - center;
    double dx = fabs(difference.x());
    double dy = fabs(difference.y());
    double distance = fmax(dx, dy);

    _position = center + QPointF(_direction) * distance;

    return true;
}
Пример #3
0
void ES_Wander::update(float dt) {
	
	float checkX = owner->x + owner->dx*dt;
	float checkY = owner->y + owner->dy*dt;
	bool changeDir = false;

	//Change direction if the enemy is going to hit a wall next frame
	owner->futureCollisionBox->SetRadius(checkX, checkY, 28.0f);
	if (smh->environment->enemyCollision(owner->futureCollisionBox,owner,dt)) {
		changeDir = true;

		//Move the enemy all the way up to the wall. This ensures that spikey balls don't
		//get out of synch with each other.
		if (owner->dx > 0.0) {
			owner->x += (64.0 - int(owner->x) % 64 - owner->radius);
		} else if (owner->dx < 0.0) {
			owner->x -= int(owner->x) % 64 - owner->radius;
		}

		if (owner->dy > 0.0) {

		} else if (owner->dy < 0.0) {

		}

	}

	//Change direction after random periods of time
	if (owner->wanderType == WANDER_NORMAL && nextDirChangeTime <= smh->getGameTime()) {
		changeDir = true;
	}

	if (changeDir) {

		nextDirChangeTime = smh->getGameTime() + smh->randomFloat(1.2, 2.0);
		currentAction = getNewDirection();

		//Set dx/dy based on new direction
		switch (currentAction) {
			case WANDER_LEFT:
				if (owner->wanderType != WANDER_UP_DOWN) {
					owner->dx = -owner->speed;
					owner->dy = 0;
					owner->facing = LEFT;
				}
				break;
			case WANDER_RIGHT:
				if (owner->wanderType != WANDER_UP_DOWN) {
					owner->dx = owner->speed;
					owner->dy = 0;
					owner->facing = RIGHT;
				}
				break;
			case WANDER_UP:
				if (owner->wanderType != WANDER_LEFT_RIGHT) {
					owner->dx = 0;
					owner->dy = -owner->speed;
					owner->facing = UP;
				}
				break;
			case WANDER_DOWN:
				if (owner->wanderType != WANDER_LEFT_RIGHT) {
					owner->dx = 0;
					owner->dy = owner->speed;
					owner->facing = DOWN;
				}
				break;
		}

	}
	
}