void st03::init(){ increaseStrength(); while(getPoint()){ if(getPoint())increaseHealth(); if(getPoint())increaseSpeed(); } }
void st03::play(){ while(getPoint()){ if(getPoint())increaseHealth(); if(getPoint())increaseSpeed(); } int d=(~0U>>1),x,y; for(int i=1;i<=N;++i) for(int j=1;j<=M;++j) if(askWhat(i,j)==EMPTY){ int t1=abs(i-getX())+abs(j-getY()); if(t1>getSp())continue; for(int k=1;k<=N;++k) for(int l=1;l<=M;++l) if(askWhat(k,l)!=EMPTY){ int tmp=abs(i-k)+abs(j-l); if(tmp<d)d=tmp,x=i,y=j; } } move(x,y); for(int i=-1;i<2;++i) for(int j=-1;j<2;++j){ if(i&&j)continue; if((!i)&&(!j))continue; if(askWhat(x+i,y+j)!=EMPTY){ attack(x+i,y+j); return; } } }
void Player::bonusCollisionCheck() { if (!getExplosionState()){ //Bonus objects if (spriteCollision(&playerSprite, &getStarSprite())){ addToScore((500 * difficulty) * (hardcore + 1)); resetAdditionText(((500 * difficulty) * (hardcore + 1)) / 10, 0); playScoreSound(); resetStar(); } if (spriteCollision(&playerSprite, &getFuelSprite())){ increaseFuel(25); resetAdditionText(25, 2); playFuelSound(); resetFuelSprite(); playedShutdownSound = false; } if (spriteCollision(&playerSprite, &getHealthSprite())){ increaseHealth(10); resetAdditionText(10, 1); playHealSound(); resetHealthSprite(); } } }
void ch_att::init() { myID=getID(); getInfo(); for (int i=1;i<=4;i++) increaseHealth(); for (int i=1;i<=2;i++) increaseStrength(); for (int i=1;i<=4;i++) increaseSpeed(); }
void testAI::play() { while(getPoint()) { increaseSpeed(); increaseStrength(); increaseHealth(); } int i,j,x,y,flag=0,t1,t2; x=getX(); y=getY(); for(i=1;i<=N;i++) { for(j=1;j<=M;j++) { if(abs(i-x)+abs(j-y)<=getSp()) { if(askWhat(i-1,j)>0 || askWhat(i+1,j)>0 || askWhat(i,j-1)>0 || askWhat(i,j+1)>0) { move(i,j); flag=1; break; } t1=i;t2=j; } } if(flag)break; } if(!flag)move(t1,t2); if(askWhat(i-1,j)>0) { attack(i-1,j); return; } if(askWhat(i+1,j)>0) { attack(i+1,j); return; } if(askWhat(i,j-1)>0) { attack(i,j-1); return; } if(askWhat(i,j+1)>0) { attack(i,j+1); return; } }
void ch_att::assignPoints() { long est=0; // Health while (point>0 && hp<att*7/3) { point--; increaseHealth(); } // Speed est=targetSpeed(); while (point>0 && sp<SpeedCap && sp<=est) { point--; increaseSpeed(); } // Strength while (point>0) { point--; increaseStrength(); } }
void Player::updatePlayer() { //Animation logic stuff if (flameAnim > animSteps){ animAscend = false; } else if (flameAnim < -animSteps){ animAscend = true; } //Collision checks //Borders if (!getExplosionState()){ if (playerSprite.getPosition().y <= (playerSprite.getGlobalBounds().height / 2) || playerSprite.getPosition().y + (playerSprite.getGlobalBounds().height / 2) >= VideoMode::getDesktopMode().height){ for (int i = 0; i < 2; i++){ decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(5, 8); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2, ramNum / 2); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-5, 5), collisionCircle[0].getPosition().y + getRandom(-5, 5)); } } } //Obstacles for (int i=0; i<getNumberOfObstacles(); i++){ if (playerCollision(&collisionCircle[0], &getObstacleObject(i))){ if (getPlayerHealth() > 0) decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(5, 8); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2, ramNum / 2); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-5, 5), collisionCircle[0].getPosition().y + (getRandom(-5, 5))); } } if (playerCollision(&collisionCircle[1], &getObstacleObject(i))){ if (getPlayerHealth() > 0) decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(4, 7); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2, ramNum / 2); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[1].getPosition().x + getRandom(-3, 3), collisionCircle[1].getPosition().y + (getRandom(-3, 3))); } } if (playerCollision(&collisionCircle[2], &getObstacleObject(i))){ if (getPlayerHealth() > 0) decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(4, 7); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2.0f, ramNum / 2.0f); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[2].getPosition().x + getRandom(-3, 3), collisionCircle[2].getPosition().y + (getRandom(-3, 3))); } } } } //Explosion if (getPlayerHealth() <= 0 || getExplosionState()){ setExplosionState(true); decreaseFuel(getPlayerFuel()); updateExplosionText(); stopRocketSound(); stopAlarmSound(); stopCrashSound(); if (initExplosion){ for (int i = 0; i < 200; i++){ crashDebrisSpeed2.push_back(Vector2f(getRandom(-2, 2), getRandom(-2, 2))); crashDebris2.push_back(RectangleShape()); short ramNum = getRandom(4, 7); crashDebris2.back().setSize(Vector2f(ramNum, ramNum)); crashDebris2.back().setOrigin(ramNum / 2.0f, ramNum / 2.0f); ramNum = getRandom(50, 160); crashDebris2.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris2.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-3, 3), collisionCircle[0].getPosition().y + (getRandom(-3, 3))); damageParticleSpeed2.push_back(Vector2f(getRandom(-3, 3), getRandom(-3, 3))); damageParticle2.push_back(CircleShape()); damageParticle2.back().setRadius(getRandom(1, 2)); damageParticle2.back().setFillColor(Color::Color(255, 153, 51)); int j = getRandom(0, 2); damageParticle2.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-3, 3), collisionCircle[0].getPosition().y + (getRandom(-3, 3))); } playExplosionSound(); } for (int i = 0; i < crashDebris2.size(); i++){ crashDebris2[i].move(crashDebrisSpeed2[i].x - explosionSpeedCounter, crashDebrisSpeed2[i].y); if (i % 2 == 0){ crashDebris2[i].rotate(2); } else crashDebris2[i].rotate(-2); crashDebrisSpeed2[i].x = crashDebrisSpeed2[i].x * 0.985; crashDebrisSpeed2[i].y = crashDebrisSpeed2[i].y * 0.985; if (crashDebris2[i].getPosition().x < -10){ crashDebris2.erase(crashDebris2.begin() + i); crashDebrisSpeed2.erase(crashDebrisSpeed2.begin() + i); } } for (int i = 0; i < damageParticleSpeed2.size(); i++){ damageParticle2[i].move(damageParticleSpeed2[i].x - explosionSpeedCounter, damageParticleSpeed2[i].y); damageParticleSpeed2[i].x = damageParticleSpeed2[i].x * 0.985; damageParticleSpeed2[i].y = damageParticleSpeed2[i].y * 0.985; if (damageParticle2[i].getPosition().x < -10){ damageParticle2.erase(damageParticle2.begin() + i); damageParticleSpeed2.erase(damageParticleSpeed2.begin() + i); } } if (explosionSpeedCounter <= 10.0){ explosionSpeedCounter *= 1.03; } initExplosion = false; if (Keyboard::isKeyPressed(Keyboard::R)){ setCrashState(true); setExplosionState(false); } else if (Keyboard::isKeyPressed(Keyboard::Escape)) setExitState(true); } //Updates //Crash debris if (showParticles){ for (int i = 0; i < crashDebris.size(); i++){ crashDebris[i].move(crashDebrisSpeed[i].x, crashDebrisSpeed[i].y); if (i % 2 == 0) crashDebris[i].rotate(10); else crashDebris[i].rotate(-10); if (crashDebris[i].getPosition().x < -20){ crashDebris.erase(crashDebris.begin() + i); crashDebrisSpeed.erase(crashDebrisSpeed.begin() + i); } } //Damage particles if (getPlayerHealth() > 0 && getPlayerHealth() <= 75){ if (1 >= getRandom(0, 10)){ damageParticleSpeed.push_back(Vector2f(-(getObstacleBaseSpeed()), 0)); damageParticle.push_back(CircleShape()); damageParticle.back().setRadius(1); damageParticle.back().setFillColor(Color::Color(255, 153, 51)); int i = getRandom(0, 2); damageParticle.back().setPosition(collisionCircle[i].getPosition().x + getRandom(-3, 3), collisionCircle[i].getPosition().y + (getRandom(-3, 3))); } } if (getPlayerHealth() > 0 && getPlayerHealth() <= 50){ if (1 >= getRandom(0, 5)){ damageParticleSpeed.push_back(Vector2f(-(getObstacleBaseSpeed()), 0)); damageParticle.push_back(CircleShape()); damageParticle.back().setRadius(1); damageParticle.back().setFillColor(Color::Color(255, 153, 51)); int i = getRandom(0, 2); damageParticle.back().setPosition(collisionCircle[i].getPosition().x + getRandom(-3, 3), collisionCircle[i].getPosition().y + (getRandom(-3, 3))); } } if (getPlayerHealth() > 0 && getPlayerHealth() <= 25){ if (1 >= getRandom(0, 2)){ damageParticleSpeed.push_back(Vector2f(-(getObstacleBaseSpeed()), 0)); damageParticle.push_back(CircleShape()); damageParticle.back().setRadius(1); damageParticle.back().setFillColor(Color::Color(255, 153, 51)); int i = getRandom(0, 2); damageParticle.back().setPosition(collisionCircle[i].getPosition().x + getRandom(-3, 3), collisionCircle[i].getPosition().y + (getRandom(-3, 3))); } if (1 >= getRandom(0, 50)){ } } for (int i = 0; i < damageParticle.size(); i++){ damageParticle[i].move(damageParticleSpeed[i].x, damageParticleSpeed[i].y); if (damageParticle[i].getPosition().x < -10){ damageParticle.erase(damageParticle.begin() + i); damageParticleSpeed.erase(damageParticleSpeed.begin() + i); } } } if (getPlayerFuel() > 0 && getPlayerHealth() > 0){ if (controlScheme == 1){ if (Keyboard::isKeyPressed(Keyboard::Space)){ if (playerRotation >= -30){ playerRotation -= 15; if (playerRotation < -30) playerRotation = playerRotation - (playerRotation + 30); playerSprite.setRotation(playerRotation); } playerSprite.move(0, baseClimingSpeed); //Climing speed is always constant playerSpeed = -(baseFallingSpeed +3); //Set speed value so that transition from climing to falling feels smooth } else { if (playerRotation <= 20){ playerRotation += 5; playerSprite.setRotation(playerRotation); } playerSprite.move(0, baseFallingSpeed + playerSpeed); if (playerSpeed <= 0) playerSpeed = playerSpeed + 1; else if ((playerSpeed <= baseFallingSpeed) && (playerSpeed > 0)) playerSpeed = playerSpeed * 1.02; } } else if (controlScheme == 2){ if (Keyboard::isKeyPressed(Keyboard::Left) && playerRotation >= -30){ playerRotation -= 3; } else if (Keyboard::isKeyPressed(Keyboard::Right) && playerRotation <= 30){ playerRotation += 3; } else if (Keyboard::isKeyPressed(Keyboard::Space)){ playerRotation = 0; } playerSprite.setRotation(playerRotation); playerSprite.move(0, playerRotation / 3); } else if (controlScheme == 3){ if (Keyboard::isKeyPressed(Keyboard::Left)){ if (playerRotation >= -30) playerRotation -= 5; } else if (Keyboard::isKeyPressed(Keyboard::Right)){ if (playerRotation <= 30) playerRotation += 5; } else { if (playerRotation < 0){ playerRotation += 5; } else if (playerRotation > 0) playerRotation -= 5; } playerSprite.setRotation(playerRotation); playerSprite.move(0, playerRotation / 3); } if (getPlayerHealth() > 0) updateRocketSound(); } else if (getPlayerFuel() <= 0){ if (!playedShutdownSound){ playShutdownSound(); playedShutdownSound = true; } stopRocketSound(); if (playerRotation < 0) playerSprite.move(0, playerRotation / 6); else if (playerRotation > 0) playerSprite.move(0, playerRotation / 3); if (playerRotation < 0) playerSprite.rotate(-1); else if (playerRotation > 0) playerSprite.rotate(1); } //Flame Sprite Bottom flameSpriteBottom.setPosition((playerSprite.getPosition().x - 45) - (playerRotation / 2.4), (playerSprite.getPosition().y + 28) + -(playerRotation / 1.05)); flameSpriteBottom.setRotation(playerSprite.getRotation()); if (animAscend){ flameScale += 0.012; flameSpriteBottom.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim++; } else if (!animAscend){ flameScale -= 0.012; flameSpriteBottom.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim--; } //Flame Sprite Top flameSpriteTop.setPosition(playerSprite.getPosition().x - 45, (playerSprite.getPosition().y - 7) + -(playerRotation / 1.05)); flameSpriteTop.setRotation(playerSprite.getRotation()); if (animAscend){ flameScale += 0.012; flameSpriteTop.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim++; } else if (!animAscend){ flameScale -= 0.012; flameSpriteTop.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim--; } collisionCircle[0].setPosition(playerSprite.getPosition().x + 20, playerSprite.getPosition().y + ((playerRotation / 3) + 2)); collisionCircle[1].setPosition(playerSprite.getPosition().x - (24 - (playerRotation / 5)), playerSprite.getPosition().y - ((playerRotation / 2) + 12)); collisionCircle[2].setPosition(playerSprite.getPosition().x - (24 + (playerRotation / 5)), playerSprite.getPosition().y - ((playerRotation / 2) - 14)); }
void testAI::init() { increaseHealth(); increaseStrength(); while(getPoint())increaseSpeed(); }