Exemplo n.º 1
0
void Game_Event::Setup(RPG::EventPage* new_page) {
	bool from_null = page == NULL;
	page = new_page;

	// Free resources if needed
	if (interpreter) {
		// If the new page is null and the interpreter is running, it should
		// carry on executing its command list during this frame
		if (page)
			interpreter->Clear();
		Game_Map::ReserveInterpreterDeletion(interpreter);
		interpreter.reset();
	}

	if (page == NULL) {
		tile_id = 0;
		SetSpriteName("");
		SetSpriteIndex(0);
		SetDirection(RPG::EventPage::Direction_down);
		//move_type = 0;
		trigger = -1;
		list.clear();
		return;
	}
	SetSpriteName(page->character_name);
	SetSpriteIndex(page->character_index);

	tile_id = page->character_name.empty() ? page->character_index : 0;

	if (original_pattern != page->character_pattern) {
		pattern = page->character_pattern;
		original_pattern = pattern;
	}

	move_type = page->move_type;
	SetMoveSpeed(page->move_speed);
	SetMoveFrequency(page->move_frequency);
	max_stop_count = (GetMoveFrequency() > 7) ? 0 : (int)pow(2.0, 8 - GetMoveFrequency());
	original_move_frequency = page->move_frequency;
	original_move_route = page->move_route;
	SetOriginalMoveRouteIndex(0);

	bool last_direction_fixed = IsDirectionFixed() || IsFacingLocked();
	animation_type = page->animation_type;

	if (from_null || !(last_direction_fixed || IsMoving()) || IsDirectionFixed())
		SetSpriteDirection(page->character_direction);
	if (!IsMoving())
		SetDirection(page->character_direction);

	SetOpacity(page->translucent ? 160 : 255);
	SetLayer(page->layer);
	data.overlap_forbidden = page->overlap_forbidden;
	trigger = page->trigger;
	list = page->event_commands;

	if (trigger == RPG::EventPage::Trigger_parallel) {
		interpreter.reset(new Game_Interpreter_Map());
	}
}
Exemplo n.º 2
0
void Game_Character::Move(int dir) {
	int dx = (dir == Right || dir == UpRight || dir == DownRight) - (dir == Left || dir == DownLeft || dir == UpLeft);
	int dy = (dir == Down || dir == DownRight || dir == DownLeft) - (dir == Up || dir == UpRight || dir == UpLeft);

	SetDirection(dir);
	if (!(IsDirectionFixed() || IsFacingLocked())) {
		if (dir > 3) // Diagonal
			SetSpriteDirection(GetSpriteDirection() % 2 ? -dx + 2 : dy + 1);
		else
			SetSpriteDirection(dir);
	}

	if (jumping) {
		jump_plus_x += dx;
		jump_plus_y += dy;
		return;
	}

	move_failed = !IsPassable(GetX(), GetY(), dir);
	if (move_failed) {
		if (!CheckEventTriggerTouch(Game_Map::RoundX(GetX() + dx), Game_Map::RoundY(GetY() + dy)))
			return;
	} else {
		SetX(Game_Map::RoundX(GetX() + dx));
		SetY(Game_Map::RoundY(GetY() + dy));
		remaining_step = SCREEN_TILE_WIDTH;
		BeginMove();
	}

	stop_count = 0;
	max_stop_count = (GetMoveFrequency() > 7) ? 0 : pow(2.0, 9 - GetMoveFrequency());
}
Exemplo n.º 3
0
void Game_Event::MoveTypeAwayFromPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();
	int last_direction = GetDirection();

	if ( std::abs(sx) + std::abs(sy) >= 20 ) {
		MoveRandom();
	} else {
		switch (Utils::GetRandomNumber(0, 5)) {
		case 0:
			MoveRandom();
			break;
		case 1:
			MoveForward();
			break;
		default:
			MoveAwayFromPlayer();
		}
	}

	if (move_failed && !starting) {
		if (stop_count >= max_stop_count + 60) {
			stop_count = 0;
		} else {
			SetDirection(last_direction);
			if (!(IsDirectionFixed() || IsFacingLocked()))
				SetSpriteDirection(last_direction);
		}
	}
}
Exemplo n.º 4
0
void Game_Event::StopTalkToHero() {
	if (!(IsDirectionFixed() || IsFacingLocked())) {
		SetSpriteDirection(GetDirection());
	}

	halting = true;
}
Exemplo n.º 5
0
void Game_Event::StartTalkToHero() {
	if (!(IsDirectionFixed() || IsFacingLocked())) {
		int prelock_dir = GetDirection();
		TurnTowardHero();
		SetDirection(prelock_dir);
	}
}
Exemplo n.º 6
0
void Game_Character::MoveUpRight() {
	if (!IsDirectionFixed()) {
		if (GetDirection() % 2) {
			TurnRight();
		} else {
			TurnUp();
		}
	}

	if (jumping) {
		jump_plus_x++;
		jump_plus_y--;
		return;
	}

	if ((IsPassable(GetX(), GetY(), RPG::EventPage::Direction_right)
		&& IsPassable(GetX() + 1, GetY(), RPG::EventPage::Direction_up))
		|| (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_up)
		&& IsPassable(GetX(), GetY() - 1, RPG::EventPage::Direction_right))) {
			SetX(GetX() + 1);
			SetY(GetY() - 1);
			BeginMove();
			stop_count = 0;
			move_failed = false;
	}
}
Exemplo n.º 7
0
void Game_Character::MoveDownLeft() {
	if (!IsDirectionFixed()) {
		if (GetDirection() % 2) {
			TurnLeft();
		} else {
			TurnDown();
		}
	}

	if (jumping) {
		jump_plus_x--;
		jump_plus_y++;
		return;
	}

	if ((IsPassable(GetX(), GetY(), RPG::EventPage::Direction_left)
		&& IsPassable(GetX() - 1, GetY(), RPG::EventPage::Direction_down))
		|| (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_down)
		&& IsPassable(GetX(), GetY() + 1, RPG::EventPage::Direction_left))) {
			SetX(GetX() - 1);
			SetY(GetY() + 1);
			BeginMove();
			stop_count = 0;
			move_failed = false;
	}
}
Exemplo n.º 8
0
void Game_Character::Lock() {
	if (!IsDirectionFixed()) {
		int prelock_dir = GetDirection();
		TurnTowardHero();
		SetPrelockDirection(prelock_dir);
	}
}
Exemplo n.º 9
0
void Game_Event::StopTalkToHero() {
	if (!IsDirectionFixed()) {
		SetSpriteDirection(GetDirection());
	}

	ready1 = true;
}
Exemplo n.º 10
0
void Game_Character::MoveUp() {
	if (!IsDirectionFixed()) TurnUp();

	if (jumping) {
		jump_plus_y--;
		return;
	}

	if (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_up)) {
		SetY(GetY() - 1);
		BeginMove();
		stop_count = 0;
		move_failed = false;
	} else {
		CheckEventTriggerTouch(GetX(), GetY() - 1);
		move_failed = true;
	}
}
Exemplo n.º 11
0
void Game_Event::MoveTypeRandom() {
	int last_direction = GetDirection();
	switch (Utils::GetRandomNumber(0, 5)) {
	case 0:
		stop_count -= Utils::GetRandomNumber(0, stop_count);
		if (stop_count < 0) {
			stop_count = 0;
		}
		return;
	case 1:
		MoveForward();
		break;
	default:
		MoveRandom();
	}
	if (move_failed && !starting) {
		SetDirection(last_direction);
		if (!(IsDirectionFixed() || IsFacingLocked()))
			SetSpriteDirection(last_direction);
	} else {
		max_stop_count = max_stop_count / 5 * Utils::GetRandomNumber(3, 6);
	}
}
Exemplo n.º 12
0
void Game_Character::Unlock() {
	if (!IsDirectionFixed()) {
		SetDirection(GetPrelockDirection());
	}
}