Esempio n. 1
0
	Player::Player(int32_t id, CharLook lk, Charstats st)
	{
		cid = id;
		look = lk;
		stats = st;
		name = Textlabel(IO::DWF_14MC, IO::TXC_WHITE, stats.getname(), 0);
		name.gettext().setback(IO::TXB_NAMETAG);
		setstance(PST_STAND);
		setflip(false);
		recalcstats(true);
	}
Esempio n. 2
0
	void Mob::setstance(uint8_t stancebyte)
	{
		flip = (stancebyte % 2) == 0;
		if (!flip)
		{
			stancebyte -= 1;
		}
		if (stancebyte < MOVE)
			stancebyte = MOVE;
		setstance(static_cast<Stance>(stancebyte));
	}
Esempio n. 3
0
	void Mob::sendmovement(Point<int16_t> start, const Movement& movement)
	{
		if (control)
			return;

		setposition(start);
		lastmove = movement;

		uint8_t laststance = lastmove.newstate;
		setstance(laststance);

		phobj.fhid = lastmove.fh;
	}
Esempio n. 4
0
	void Mob::applydamage(int32_t damage, bool toleft)
	{
		hitsound.play();

		if (dying && stance != DIE)
		{
			applydeath();
		}
		else if (control && isalive() && damage >= knockback)
		{
			flip = toleft;
			counter = 170;
			setstance(HIT);

			updatemovement();
			awaitdeath = true;
		}
	}
Esempio n. 5
0
	void Mob::nextmove()
	{
		if (canmove)
		{
			switch (stance)
			{
			case HIT:
			case STAND:
				setstance(MOVE);
				flip = randomizer.nextbool();
				break;
			case MOVE:
			case JUMP:
				if (canjump && phobj.onground && randomizer.below(0.25f))
				{
					setstance(JUMP);
				}
				else
				{
					switch (randomizer.nextint(2))
					{
					case 0:
						setstance(STAND);
						break;
					case 1:
						setstance(MOVE);
						flip = false;
						break;
					case 2:
						setstance(MOVE);
						flip = true;
						break;
					}
				}
				break;
			}

			if (stance == MOVE && canfly)
			{
				flydirection = nextdirection(randomizer);
			}
		}
		else
		{
			setstance(STAND);
		}
	}
Esempio n. 6
0
	void Mob::applydeath()
	{
		setstance(DIE);
		diesound.play();
		dying = true;
	}
Esempio n. 7
0
	Mob::Mob(int32_t oi, int32_t mid, int8_t mode, int8_t st, uint16_t fh, 
		bool newspawn, int8_t tm, Point<int16_t> position) : MapObject(oi) {

		std::string strid = string_format::extend_id(mid, 7);
		nl::node src = nl::nx::mob[strid + ".img"];

		nl::node info = src["info"];

		level = info["level"];
		watk = info["PADamage"];
		matk = info["MADamage"];
		wdef = info["PDDamage"];
		mdef = info["MDDamage"];
		accuracy = info["acc"];
		avoid = info["eva"];
		knockback = info["pushed"];
		speed = info["speed"];
		flyspeed = info["flySpeed"];
		touchdamage = info["bodyAttack"].get_bool();
		undead = info["undead"].get_bool();
		noflip = info["noFlip"].get_bool();
		notattack = info["notAttack"].get_bool();
		canjump = src["jump"].size() > 0;
		canfly = src["fly"].size() > 0;
		canmove = src["move"].size() > 0 || canfly;

		if (canfly)
		{
			animations[STAND] = src["fly"];
			animations[MOVE] = src["fly"];
		}
		else
		{
			animations[STAND] = src["stand"];
			animations[MOVE] = src["move"];
		}
		animations[JUMP] = src["jump"];
		animations[HIT] = src["hit1"];
		animations[DIE] = src["die1"];

		name = nl::nx::string["Mob.img"][std::to_string(mid)]["name"];

		nl::node sndsrc = nl::nx::sound["Mob.img"][strid];

		hitsound = sndsrc["Damage"];
		diesound = sndsrc["Die"];

		speed += 100;
		speed *= 0.001f;

		flyspeed += 100;
		flyspeed *= 0.0005f;

		if (canfly)
			phobj.type = PhysicsObject::FLYING;

		id = mid;
		team = tm;
		setposition(position);
		setcontrol(mode);
		phobj.fhid = fh;
		phobj.setflag(PhysicsObject::TURNATEDGES);

		hppercent = 0;
		dying = false;
		dead = false;
		fading = false;
		awaitdeath = false;
		setstance(st);
		flydirection = STRAIGHT;
		counter = 0;

		namelabel = Text(Text::A13M, Text::CENTER, Text::WHITE);
		namelabel.setback(Text::NAMETAG);
		namelabel.settext(name);

		if (newspawn)
		{
			fadein = true;
			opacity.set(0.0f);
		}
		else
		{
			fadein = false;
			opacity.set(1.0f);
		}

		if (control && stance == Stance::STAND)
		{
			nextmove();
		}
	}
Esempio n. 8
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;
	}