void testEnemyMovement()
{
    Enemy e = createTestEnemy();
    
    sput_fail_unless(distanceToEndOfPath(getNumberOfEnemies()) == e->enemyPath->pathLength, "Valid: Enemy has the correct number of steps to the end of its path");
    
    
    int enemyOriginX = e->x;
    int enemyOriginY = e->y;
    for(int i = 0; i < 200; i++) {
        moveEnemy(getNumberOfEnemies());
    }
    sput_fail_unless(e->x != enemyOriginX, "Valid: Enemy has changed X coordinate after 200 moves");
    sput_fail_unless(e->y != enemyOriginY, "Valid: Enemy has changed Y coordinate after 200 moves");
    sput_fail_unless(distanceToEndOfPath(getNumberOfEnemies()) == e->enemyPath->pathLength-(200*e->speed), "Valid: Enemy has the correct number of steps to the end of its path after 200 moves");
    
    int startingHealth = getHealth(getGame(NULL));
    int howFarToGo = distanceToEndOfPath(getNumberOfEnemies());
    int howManyMovesToEnd = (howFarToGo/e->speed)+1;
    for(int i = 0; i < howManyMovesToEnd; i++) {
        moveEnemy(getNumberOfEnemies());
    }
    
    
    sput_fail_unless(isDead(getNumberOfEnemies()), "Valid: Enemy has died after reaching end of path");
    sput_fail_unless(getHealth(getGame(NULL)) == startingHealth-e->damage, "Valid: Enemy has damaged health by correct amount at end of path");
    
}
Exemple #2
0
void Hero::Render()
{
	int height = 0, width = 0, count = 0;
	width = widthHeight(0);
	height = widthHeight(1);

	CharacterSprite::Render();
	int fx = (curFrame % animationColumns * frameWidth);
	int fy = animationRow * frameHeight;

	al_draw_bitmap_region(image, fx, fy, frameWidth, frameHeight, x - frameWidth / 2, y - frameHeight / 2, 0);
	//HUD
	if(mHeroNumber == 0)
	{
		//Health Bar
		al_draw_filled_rectangle(0, height - 100, getHealth() * 5, height - 95, al_map_rgb(255,0,0));
		//Energy Bar
		if (getMana() > 0)
			al_draw_filled_rectangle(0, height - 90, getMana() * 2, height - 85, al_map_rgb(0,0,255));
	}
	else if (mHeroNumber == 1)
	{
		//Health Bar
		al_draw_filled_rectangle(width, height - 100, width - (getHealth() * 5), height - 95, al_map_rgb(255,0,0));
		//Energy Bar
		if (getMana() > 0)
			al_draw_filled_rectangle(width, height - 90, width - (getMana() * 2), height - 85, al_map_rgb(0,0,255));
	}
}
void player::rest()
{
    //Heals by one point and takes up one turn
    if (getHealth() < getMaxHealth())
    {
        int newHealth = getHealth() + 1;
        setHealth(newHealth);
    }
    return;
}
Exemple #4
0
bool Hurtable::heal(int h)
{
    int curHealth = getHealth();
    int maxHealth = getMaxHealth();

    if (curHealth >= maxHealth)
        return false;

    setHealth(std::min(getMaxHealth(), getHealth() + h));
    return true;
}
void Hero::equipItem(Item *inventoryItem)
{
    equippedItem=inventoryItem;
    attackPoints=inventoryItem->attackBonus; //Augments player stats based on item stats
    defendPoints=inventoryItem->defenseBonus;
    setHealth(getHealth()+inventoryItem->healthBonus);
    if(getHealth()<=0) //If Item Takes Away All User's Health
    {
        cout<<"You Have Lost A Life"<<endl;
        lives=lives-1;
        setHealth(10);
    }
}
Exemple #6
0
void Creature::gainHealth(Creature* caster, int32_t healthGain)
{
	if(healthGain > 0)
	{
		int32_t prevHealth = getHealth();
		changeHealth(healthGain);

		int32_t effectiveGain = getHealth() - prevHealth;
		if(caster)
			caster->onTargetGainHealth(this, effectiveGain);
	}
	else
		changeHealth(healthGain);
}
Exemple #7
0
void Creature::gainHealth(const CombatSource& combatSource, int32_t healthGain)
{
	if(healthGain > 0){
		int32_t prevHealth = getHealth();
		changeHealth(healthGain);

		int32_t effectiveGain = getHealth() - prevHealth;
		if(combatSource.isSourceCreature()){
			combatSource.getSourceCreature()->onTargetCreatureGainHealth(this, effectiveGain);
		}
	}
	else{
		changeHealth(healthGain);
	}
}
bool Bludgeoning:: isAlive()
{
    if(getHealth()>0)
        return true;
    else
        return false;
}
Exemple #9
0
bool SMMob::teleport(const Location &location, PlayerTeleportEvent::TeleportCause cause)
{
	if (getHealth() <= 0)
		return false;

	return SMEntity::teleport(location, cause);
}
void Health::checkHealth()
{
    if( getHealth() <= 0 )
    {
        game->GameOver();
    }
}
Exemple #11
0
void Entity::save(QDataStream &s, int version)
{
    s << mNeuralNetwork;
    s << mX;
    s << mY;
    s << mAge;
    s << mGeneration;
    s << getHealth();
    s << getEnergy();
    s << getHydration();
    s << getValueStore1();
    s << getValueStore2();
    s << getValueStore3();
    s << getValueStore4();

    s << getActionMoveLeft();
    s << getActionMoveRight();
    s << getActionMoveUp();
    s << getActionMoveDown();
    s << getActionAttackLeft();
    s << getActionAttackRight();
    s << getActionAttackUp();
    s << getActionAttackDown();
    s << getActionEatV();
    s << getActionEatM();
    s << getActionDrink();
    s << getActionSplit();
    s << getActionResult();
}
// Get the current health points for a given player
int howHealthyIs(HunterView currentView, PlayerID player)
{
    assert(currentView != NULL);
    assert(0 <= player && player < NUM_PLAYERS);

    return getHealth(currentView->g, player);
}
// Get the current health points for a given player
int howHealthyIs(DracView currentView, PlayerID player) {
   int health;
   
   health = getHealth(currentView->gv, player);

   return health;
}
Exemple #14
0
void Creature::onIdleStatus()
{
	if (getHealth() > 0) {
		damageMap.clear();
		lastHitCreatureId = 0;
	}
}
Exemple #15
0
void
Player::printStats(){
	std::cout << "Player Stats:\n";
	std::cout << "- Health: " << getHealth() << "\n";
	std::cout << "- EXP Level: " << getExpLevel() << "\n";
	std::cout << "- RAGE Level: " << getRageLevel() << "\n\n";
}
Exemple #16
0
/// <summary>
/// Draws the enemy
/// </summary>
void Enemy::draw()
{
	// Draw Enemy
	this->window.draw(*this->sprite);


	// Calculates the health bar percentage
	float percent = (100.0f / getStartHealth()) * getHealth();
	float barWidth = (this->sprite->getGlobalBounds().width) / 100.0f;

	// Draws the health bar
	sf::RectangleShape healthBar;
	healthBar.setSize(sf::Vector2f((barWidth * percent) / 2, 2));
	healthBar.setPosition(
		this->sprite->getGlobalBounds().left + (barWidth * 25),
		this->sprite->getGlobalBounds().top - 5);
	healthBar.setFillColor(sf::Color::Green);
	window.draw(healthBar);

	/*sf::FloatRect bounds = this->sprite->getGlobalBounds();
	sf::RectangleShape af(sf::Vector2f(bounds.width,bounds.height));
	af.setPosition(bounds.left, bounds.top);
	af.setOutlineColor(sf::Color(141,23,22,23));
	af.setFillColor(sf::Color(255,255,255,150));
	this->window.draw(af);*/

}
Exemple #17
0
void Monster::Render()
{
	if(++frameCount >= frameDelay + 10)
	{
		if(++curFrame >= maxFrame)
		{
		curFrame = 0;
		}
		frameCount = 0;
	}

	if(Direction == UP)
	{

		al_draw_bitmap_region(Monster::image, curFrame * frameWidth, 0, spriteSize, spriteSize, x, y, 0);
	}

	else if(Direction == LEFT)
	{
		al_draw_bitmap_region(Monster::image, curFrame * frameWidth, spriteSize * 2, spriteSize, spriteSize, x, y, 0);
	}

	else if(Direction == DOWN)
	{
		al_draw_bitmap_region(Monster::image, curFrame * frameWidth, spriteSize * 1, spriteSize, spriteSize, x, y, 0);
	}

	else if(Direction == RIGHT)
	{
		al_draw_bitmap_region(Monster::image, curFrame * frameWidth, spriteSize * 3, spriteSize, spriteSize, x, y, 0);
	}

	drawHealthBar(getHealth(), mFont, x, y);
}
Exemple #18
0
/// <summary>
/// Processes this instance.
/// </summary>
void Player::process()
{
	normalShotTime += timeStep;
	specialShotTime += timeStep;
	pwrUpTime += timeStep;
	pulseTime += timeStep;

	this->hitDetection();
	this->detectEdge();
	this->processPowerUps();

	if (getHealth() <= 0)
	{
		setDeleted(true);
		resourceHandler->getSound(ResourceHandler::Sound::FX_ENEMY_DEATH).play();
	}

	// Ship collision
	for (auto& i : objects)
	{
		if (i->getType() == Shooter::ShooterType::PLAYER) continue;

		if (this->sat(i->sprite, this->sprite))
		{
			// Kill the player, (ship collisions never end well)
			this->setHealth(this->getHealth() - 1);
			i->setHealth(i->getHealth() - 1);
		}
	}
}
Exemple #19
0
bool UnitBase::update() {
    if(active) {
        targeting();
        navigate();
        move();
        if(active) {
            turn();
        }
    }

    if(getHealth() <= 0.0f) {
        destroy();
        return false;
    }

    if(active && (getHealthColor() != COLOR_LIGHTGREEN) && !goingToRepairYard && owner->hasRepairYard() && (owner->isAI() || owner->hasCarryalls())
            && !isInfantry() && !isAFlyingUnit() && !forced && target.getObjPointer() == NULL) {
        doRepair();
    }


    if(recalculatePathTimer > 0) recalculatePathTimer--;
    if(findTargetTimer > 0) findTargetTimer--;
    if(primaryWeaponTimer > 0) primaryWeaponTimer--;
    if(secondaryWeaponTimer > 0) secondaryWeaponTimer--;
    if(deviationTimer != INVALID) {
        if(--deviationTimer <= 0) {
            quitDeviation();
        }
    }

	return true;
}
Exemple #20
0
void Creature::onIdleStatus()
{
	if(getHealth() > 0){
		healMap.clear();
		damageMap.clear();
	}
}
int main(int argc, char * argv[]) {
	playerMessage messages[] = {};
	
	printf("Test basic empty initialisation\n");
	HunterView hv = newHunterView("", messages);
	assert(getCurrentPlayer(hv) == PLAYER_LORD_GODALMING);
	assert(getRound(hv) == 0);
	assert(getHealth(hv, PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS);
	assert(getHealth(hv, PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
        assert(getScore(hv) == GAME_START_SCORE);
        assert(getLocation(hv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION);
        
	disposeHunterView(hv);
	printf("passed\n");

	return 0;
}
Exemple #22
0
void Monster::getMonsterStats()
{
    cout << "[[ " << monsterName << " - level: " << getLevel() << " || "
         << "Health: " << getHealth() << " HP || "
         << "Attack: " << getAttack() << " || "
         << "Strength: " << getStrength() << " || "
         << "Defence: " << getDefence() << " ]] \n";
}
Exemple #23
0
bool Actor::getNextStep(Direction& dir, uint32_t& flags)
{
  if(isIdle || getHealth() <= 0){
    //we dont have anyone watching might aswell stop walking
    eventWalk = 0;
    return false;
  }

  bool result = false;
  if((!followCreature || !hasFollowPath) && !isSummon()){
    if(followCreature){
      result = getRandomStep(getPosition(), dir);
    }else{
      if(getTimeSinceLastMove() > 1000){
        //choose a random direction
        result = getRandomStep(getPosition(), dir);
      }
    }
  }
  else if(isSummon() || followCreature){
    result = Creature::getNextStep(dir, flags);
    if(result){
      flags |= FLAG_PATHFINDING;
    }
    else{
      //target dancing
      if(attackedCreature && attackedCreature == followCreature){
        if(isFleeing()){
          result = getDanceStep(getPosition(), dir, false, false);
        }
        else if(cType.staticAttackChance() < (uint32_t)random_range(1, 100)){
          result = getDanceStep(getPosition(), dir);
        }
      }
    }
  }

  if(result && (canPushItems() || canPushCreatures()) ){
    const Position& pos = Combat::getCasterPosition(this, dir);
    Tile* tile = g_game.getParentTile(pos.x, pos.y, pos.z);
    if(tile){
      if(canPushItems()){
        pushItems(tile);
      }

      if(canPushCreatures()){
        pushCreatures(tile);
      }
    }
#ifdef __DEBUG__
    else{
      std::cout << "getNextStep - no tile." << std::endl;
    }
#endif
  }

  return result;
}
void Bludgeoning:: takeDamage(int d)
{
    int tempHealth = getHealth();
    
    if (d>tempHealth)
        setHealth(0);
    else
        setHealth(tempHealth-d);
}
Exemple #25
0
void Monster::Collided(int objectID)
{
	if(objectID == BULLET)
	{
		loseHealth();
		if(getHealth() <= 0)
			setAlive(false);
	}
}
void CreateGameTest()	{

    GameProperties testGame;
    testGame = getGame(NULL);
    sput_fail_unless(getAvailableMemory() == 1000,"Initializing Memory");
    //sput_fail_unless(getWave(testGame) == 3,"Initializing WaveNo");
    sput_fail_unless(getTotalWaveNo() == 3,"Total Wave Number set to 3 from level file");
    sput_fail_unless(getHealth(testGame) == 100,"Initializing Health");
}
/*
 * Checks if health is 0
 */
int checkIfPlayerDead()   {

    if(getHealth(getGame(NULL)) <= 0)   {
        return 1;
    }

    return 0;

}
Exemple #28
0
bool Player::useItem(bool* myKey)
{	
	Item* ptr = inventory.useItem();

	if(ptr == NULL)
	{
		return false;
	}
	
	if(info.getTimer() > 0.5)
	{
		if(myKey[KEY_L] && health < 100 && ptr->getItemID() == Item::H_POTION)
		{
			if(inventory.removeItem(this->position))
			{
				ptr->setActive(false);
			}
			setHealth(getHealth() + 10);
			if(getHealth() >= 100)
			{
				health = 100;
			}
			my_sfx_man->play_yummy();
			info.setTimer(0);
		}

		else if(myKey[KEY_L] && stamina < 100 && ptr->getItemID() == Item::S_POTION)
		{
			if(inventory.removeItem(this->position))
			{
				ptr->setActive(false);
			}
			setStamina(getStamina() + 20);
			if(getStamina() >= 100)
			{
				stamina = 100;
			}
			my_sfx_man->play_yummy();
			info.setTimer(0);
		}
	}
	return false;
}
Exemple #29
0
void player::print_Score_Screen()
{
    std::cout << std::left;
    std::cout << "PLAYER STATS\n\n";

    std::cout << std::setw(17) << "Health:  " << getHealth() << "\n";
    std::cout << std::setw(17) << "Treasure:  " << getTreasure() << "\n";
    std::cout << std::setw(17) << "Weapon Name:  " << getWeaponName() << "\n";
    std::cout << std::setw(17) << "Monsters Killed: " << getMonstersKilled() << "\n";
}
Exemple #30
0
void Hero::printStats()
{
	cout << "Hero's stats:\n";
	cout << "Level: \t" << getLevel() << "\n";
	cout << "Health: \t" << getHealth() << "\n";
	cout << "Attack: \t" << getAttack() << "\n";
	cout << "Defense: \t" << getDefense() << "\n";
	cout << "Perception: \t" << perception << "\n";
	cout << "Experience: \t" << experience << "/" << requiredXp << "\n";
}