Пример #1
0
void Blindr::Player::draw() {
	
	ImageAsset *asset = assets->camel_jump;
	if (grounded()) {
		float vx = body->GetLinearVelocity().x;
		if (abs(vx) > 0.02f) {
			asset = assets->camel_walk;
		} else {
			asset = assets->camel;
		}
	}

	vec2 pixelPosition = vec(PixelsPerMeter * body->GetPosition());
	
	int frame = 0;
	int humpOff = 0;
	if (asset == assets->camel_walk) {
		frame = int(Time::seconds() * PlayerWalkFPS) % asset->nframes;
		humpOff = frame % 2; // hack;
	} else {
		frame = Graphics::pingPong(int(Time::seconds() * PlayerIdleFPS), asset->nframes);
	}
	if (facingRight) {
		SpriteBatch::draw(asset, pixelPosition + vec(6, -4), frame);
		SpriteBatch::draw(assets->camel_hump, pixelPosition + vec(0, -10-humpOff));
	} else {
		SpriteBatch::drawFlippedH(asset, pixelPosition + vec(-6, -4), frame);
		SpriteBatch::drawFlippedH(assets->camel_hump, pixelPosition + vec(0, -10-humpOff));
	}
}
Пример #2
0
void Display::ground(Grounder *g)
{
    head_->clear();
    if(inst_.get())
    {
        inst_->reset();
        inst_->ground(g);
    }
    else if(!grounded_)
    {
        grounded_ = true;
        if(head_->match(g)) grounded(g);
    }
}
Пример #3
0
void enemy::update (float elapsed)
{
	if (firstFrame)
	{
		//to ensure that larger AI creatures don't start in walls
		move(1, 0.01f);
		move(-1, 0.01f);
		jump(0.01f);

		firstFrame = false;
	}

	//keep track of position, for animation purposes
	if (!isParalyzed())
		lastX = x;

	if (AItype == 5 || isParalyzed() || summonEffectActive())
	{
		//just stop here; the chest AI doesn't do anything, literally
		//and paralyzed AIs dont either
		creature::update(elapsed);
		return;
	}

	//clean up targets
	if (target != NULL && target != this)
	{
		if (target->dead() || target->invisible())
			target = NULL;
		else
		{
			float xDif = target->getX() + target->getMaskWidth() / 2 - getX() - getMaskWidth() / 2;
			float yDif = target->getY() + target->getMaskHeight() / 2 - getY() - getMaskHeight() / 2;
			float dif = sqrt(xDif * xDif + yDif * yDif);
			if (dif > FORGETRANGE)
				target = NULL; //they got too far away; forget them
		}
	}

	if (!dead())
	{
		//general AI behavior
		if (teleportMagic && healthFraction() <= 0.5f && magic != DATA_NONE && target != NULL)
		{
			//use the magic
			global_map->magic(this, magic, TYPE_PLAYER);

			//halts your attack animation, if necessary
			setAttackAnim(-1);

			//teleport to behind him
			facingX = target->getFacingX();
			x = target->getX() - facingX * (weaponReach() + getMaskWidth() / 2);
			y = target->getY();

			//you can only do this once, so forget your magic
			magic = DATA_NONE;
			teleportMagic = false;
		}
		else if (defenseHops && hopDir == 0 && target != NULL && target->hopCue(this))
		{
			if (target->getX() + target->getMaskWidth() / 2 > getX() + getMaskWidth() / 2)
				hopDir = -1;
			else
				hopDir = 1;
			jump(HOP);
		}
		else if (retreatMagic && healthFraction() < RETREATPOINT && retreatPhase == -1)
		{
			retreatPhase = 0;
			retreatTimer = RETREATDUR;
		}

		if (retreatPhase == 0)
		{
			//run away
			retreatTimer -= elapsed;
			if (retreatTimer <= 0 || target == NULL)
			{
				retreatPhase = 1;
				retreatTimer = RETREATMAGICTIMER;
			}
			else
			{
				int retreatDir;
				if (target->getX() + target->getMaskWidth() / 2 > getX() + getMaskWidth() / 2)
					retreatDir = -1;
				else
					retreatDir = 1;
				move(retreatDir, elapsed * RETREATSPEEDBONUS);
				if (!isOnscreen())
				{
					//you don't want to quite get offscreen, so go back
					move(-retreatDir, elapsed * RETREATSPEEDBONUS);
					retreatTimer = 0;
				}
			}
		}
		else if (retreatPhase == 1)
		{
			if (target != NULL)
			{
				if (target->getX() + target->getMaskWidth() / 2 > getX() + getMaskWidth() / 2)
					facingX = 1;
				else
					facingX = -1;
			}

			retreatTimer -= elapsed;
			if (retreatTimer <= 0)
			{
				retreatTimer = RETREATMAGICTIMER;
				global_map->magic(this, magic, TYPE_PLAYER);
			}

			if (target != NULL && abs(target->getX() + target->getMaskWidth() / 2 - getX() - getMaskWidth() / 2) < STOPRETREATDIS)
				retreatPhase = 2; //retreating is now disabled
			if (healthFraction() == 1.0f)
				retreatPhase = -1; //stop retreating
		}
		else if (hopDir != 0)
		{
			move(hopDir, elapsed);
			if (grounded())
				hopDir = 0;
		}
		else
			switch(AItype)
			{
			case 0:
				basicAI(elapsed);
				break;
			case 1:
				archerAI(elapsed);
				break;
			case 2:
				manhackAI(elapsed);
				break;
			case 3:
				flowerAI(elapsed);
				break;
			case 4:
				animalAI(elapsed);
				break;
			case 5:
				//chest ai
				break;
			case 6:
				bigWolfAI(elapsed);
				break;
			case 7:
				wolfMakerAI(elapsed);
				break;
			case 8:
				wolfMadeAI(elapsed);
				break;
			case 9:
				neoRollerAI(elapsed);
				break;
			case 10:
				copterAI(elapsed);
				break;
			case 11:
				wprinAI(elapsed);
				break;
			case 12:
				kingAI(elapsed);
				break;
			}
	}

	creature::update(elapsed);
}
Пример #4
0
void Blindr::Player::jump() {
	if (grounded()) {
		Audio::playSample(assets->jump);
		body->ApplyLinearImpulse(b2Vec2(0, -PlayerJumpForce), body->GetPosition());
	}
}