void cPlayer::StrafeRight(GLfloat distance) { cVector3D MoveVector, xaux; MoveVector.x = 1 * distance; MoveVector.y = 0; MoveVector.z = 0; xaux.x = Position.x; Position.Add(MoveVector); if (distance < 0){ if (CollidesMapWall(map, false)){ Position.x = xaux.x; while (!CollidesMapWall(map, false)) { Position.x -= 0.1f; } Position.x += 0.1f; } } else{ if (CollidesMapWall(map, true)) { Position.x = xaux.x; while (!CollidesMapWall(map, true)) { Position.x += 0.1f; } Position.x -= 0.1f; } } }
void Enemy::Logic(int *map) { if(enemyType == ENEMY_ONE) { //PROJECTILES if (throwing) { ++timeThrowing; if (timeThrowing > 25) { timeThrowing = 0; throwing = false; } else if (timeThrowing == 20) { int aux = (state == STATE_THROWLEFT) ? 0 : 1; cProjectile p(x,y,w,h,aux,TYPE_2); projectiles.push_back(p); } } for (int i = 0; i < int(projectiles.size()); ++i) { projectiles[i].Logic(map); //Destroy condition if (projectiles[i].Destroy(map)) projectiles.erase(projectiles.begin() + i); } } if(state != STATE_HIT && state != STATE_SNOWBALL && state != STATE_STUNNED && state != STATE_SNOWBALL_MOVING && state != STATE_SNOWBALL_PLAYER) { AI(map); } else if(state != STATE_SNOWBALL_MOVING && state != STATE_SNOWBALL_PLAYER){ ++timecount; if(state == STATE_STUNNED) { if(timecount>=TIME_STUNNED) { timecount =0; state = STATE_LOOKLEFT; } } else if(timecount>=TIME_WITH_SNOW*life) { timecount =0; --life; state = STATE_HIT; if(life ==0) { state = STATE_STUNNED; } } } else { if( (x % TILE_SIZE) == 0) { x += (STEP_LENGTH*direction); if(CollidesMapWall(map,(direction ==1))) { direction *=-1; } } else x += STEP_LENGTH*direction; } cBicho::Logic(map); }
void cProyectil::Logic(int * map) { //Whats next tile? if ((y % TILE_SIZE) <= 1) { y += speedY; x += speedX; //si choca con tile, se autodestruye muy fuerte if (CollidesMapWall(map, false)) delete this; } //Advance, no problem else { y += speedY; x += speedX; //TODO: si choca, hace magia } }
void cVoladorEstatico::Logic(int *map) { double t1 = glutGet(GLUT_ELAPSED_TIME); if (t1 - moveDelaySteering > 20 * 20) { random_variable = rand(); moveDelaySteering = t1; } if (t1 - moveDelay > 20) { int aux = y; y += random_variable%speed - 3; //Whats next tile? if ((y % TILE_SIZE) <= 1) { /*y += speedY; x += speedX;*/ //si choca con tile, se autodestruye muy fuerte if (CollidesMapWall(map, false)) y = aux; //delete this; } //Advance, no problem else { /*y += speedY; x += speedX;*/ //TODO: si choca, hace magia } moveDelay = t1; } //should i shoot if (t1 - lastShootDec > shootChance*50) { int prob = rand();// % 4; prob = fmod(prob,2); if (prob == 0) { shoot = true; } else shoot = false; lastShootDec = t1; } }