Ejemplo n.º 1
0
	int8_t Player::update(const Physics& physics, uint16_t dpf)
	{
		const PlayerState* pst = plstates.get(stance);
		if (pst)
		{
			pst->update(*this);
			physics.moveobject(phobj, dpf);
			pst->nextstate(*this);
		}

		uint16_t lookdpf = dpf;
		switch (stance)
		{
		case PST_WALK:
			lookdpf = static_cast<short>(dpf * (1.0f + abs(phobj.hspeed) / 25));
			break;
		}
		look.update(lookdpf);

		return phobj.fhlayer;
	}
Ejemplo n.º 2
0
	int8_t Drop::update(const Physics& physics)
	{
		physics.moveobject(phobj);

		if (state == DROPPED && phobj.onground)
		{
			phobj.hspeed = 0.0;
			phobj.setflag(PhysicsObject::NOGRAVITY);
			setposition(dest.x(), dest.y() - 4);
			state = FLOATING;
		}
		
		if (state == FLOATING)
		{
			phobj.y = basey + 5.0f + (cos(moved) - 1.0f) * 2.5f;
			moved = (moved < 360.0f) ? moved + 0.025f : 0.0f;
		}
		
		if (state == PICKEDUP)
		{
			static const uint16_t PICKUPTIME = 48;

			if (looter)
			{
				double hdelta = looter->x - phobj.x;
				phobj.hspeed = looter->hspeed / 2.0 + (hdelta - 16.0) / PICKUPTIME;
			}

			opacity -= 1.0f / PICKUPTIME;
			if (opacity <= 1.0f / PICKUPTIME)
			{
				opacity = 0.0f;

				MapObject::deactivate();
				return -1;
			}
		}

		return phobj.fhlayer;
	}
Ejemplo n.º 3
0
	int8_t MapObject::update(const Physics& physics)
	{
		physics.moveobject(phobj);
		return phobj.fhlayer;
	}
Ejemplo n.º 4
0
	int8_t Mob::update(const Physics& physics)
	{
		if (!active)
			return phobj.fhlayer;

		bool aniend = animations.at(stance).update();
		if (aniend && stance == DIE)
		{
			dead = true;
		}

		if (fading)
		{
			opacity -= 0.025f;
			if (opacity.last() < 0.025f)
			{
				opacity.set(0.0f);
				fading = false;
				dead = true;
			}
		}
		else if (fadein)
		{
			opacity += 0.025f;
			if (opacity.last() > 0.975f)
			{
				opacity.set(1.0f);
				fadein = false;
			}
		}

		if (dead)
		{
			active = false;
			return -1;
		}

		effects.update();
		showhp.update();

		if (!dying)
		{
			if (!canfly)
			{
				if (phobj.flagnotset(PhysicsObject::TURNATEDGES))
				{
					flip = !flip;
					phobj.setflag(PhysicsObject::TURNATEDGES);

					if (stance == HIT)
						setstance(STAND);
				}
			}

			switch (stance)
			{
			case MOVE:
				if (canfly)
				{
					phobj.hforce = flip ? flyspeed : -flyspeed;
					switch (flydirection)
					{
					case UPWARDS:
						phobj.vforce = -flyspeed;
						break;
					case DOWNWARDS:
						phobj.vforce = flyspeed;
						break;
					}
				}
				else
				{
					phobj.hforce = flip ? speed : -speed;
				}
				break;
			case HIT:
				if (canmove)
				{
					double KBFORCE = phobj.onground ? 0.2 : 0.1;
					phobj.hforce = flip ? -KBFORCE : KBFORCE;
				}
				break;
			case JUMP:
				phobj.vforce = -5.0;
				break;
			}

			physics.moveobject(phobj);

			if (control)
			{
				counter++;

				bool next;
				switch (stance)
				{
				case HIT:
					next = counter > 200;
					break;
				case JUMP:
					next = phobj.onground;
					break;
				default:
					next = aniend && counter > 200;
					break;
				}

				if (next)
				{
					nextmove();
					updatemovement();
					counter = 0;
				}
			}
		}
		else
		{
			phobj.normalize();
			physics.getfht().updatefh(phobj);
		}

		return phobj.fhlayer;
	}
Ejemplo n.º 5
0
	int8_t Mob::update(const Physics& physics)
	{
		if (!active)
			return phobj.fhlayer;

		bool aniend = animations.at(stance).update();
		if (aniend && dying)
		{
			dead = true;
		}

		if (fading)
		{
			opacity -= 0.025f;
			if (opacity.last() < 0.025f)
			{
				opacity.set(0.0f);
				fading = false;
				dead = true;
			}
		}
		else if (fadein)
		{
			opacity += 0.025f;
			if (opacity.last() > 0.975f)
			{
				opacity.set(1.0f);
				fadein = false;
			}
		}

		Point<int16_t> head = getheadpos(getposition());
		bulletlist.remove_if([&](pair<Bullet, AttackEffect>& bulletattack) {
			bool apply = bulletattack.first.update(head);
			if (apply)
			{
				applyattack(bulletattack.second);
			}
			return apply;
		});
		bool nobullets = bulletlist.size() == 0;

		singlelist.remove_if([&](SingleEffect& single) {
			if (single.delay <= Constants::TIMESTEP)
			{
				applysingle(single);
				return true;
			}
			else
			{
				single.delay -= Constants::TIMESTEP;
				return false;
			}
		});
		bool nosingle = singlelist.size() == 0;

		size_t remove = 0;
		for (auto& dmg : damagenumbers)
		{
			if (dmg.update())
				remove++;
		}
		for (size_t i = remove; i--;)
		{
			damagenumbers.erase(damagenumbers.begin());
		}
		bool nonumbers = damagenumbers.size() == 0;

		if (dead && nobullets && nosingle && nonumbers)
		{
			active = false;
			return -1;
		}

		effects.update();
		showhp.update();

		if (control && !dying)
		{
			if (!canfly)
			{
				if (phobj.flagnotset(PhysicsObject::TURNATEDGES))
				{
					flip = !flip;
					phobj.setflag(PhysicsObject::TURNATEDGES);

					if (stance == HIT)
						setstance(STAND);
				}
			}

			switch (stance)
			{
			case MOVE:
				if (canfly)
				{
					phobj.hforce = flip ? flyspeed : -flyspeed;
					switch (flydirection)
					{
					case UPWARDS:
						phobj.vforce = -flyspeed;
						break;
					case DOWNWARDS:
						phobj.vforce = flyspeed;
						break;
					}
				}
				else
				{
					phobj.hforce = flip ? speed : -speed;
					if (canjump && phobj.onground && counter > 50 && counter < 150 && randomizer.below(0.005f))
					{
						phobj.vforce = -5.0f;
					}
				}
				break;
			case HIT:
				if (canmove)
				{
					double KBFORCE = phobj.onground ? 0.2 : 0.1;
					phobj.hforce = flip ? -KBFORCE : KBFORCE;
				}
				break;
			}

			counter++;
			if (aniend && counter > 200)
			{
				nextmove();
				sendmovement();
				counter = 0;
			}

			physics.moveobject(phobj);
		}
		else
		{
			phobj.normalize();
			physics.getfht().updatefh(phobj);
		}

		return phobj.fhlayer;
	}