Ejemplo n.º 1
0
void Sprite_Character::Update() {
	Sprite::Update();
	Rect r;
	if (tile_id != character->GetTileId() ||
		character_name != character->GetCharacterName() ||
		character_index != character->GetCharacterIndex()) {
		tile_id = character->GetTileId();
		character_name = character->GetCharacterName();
		character_index = character->GetCharacterIndex();
		if (tile_id > 0) {
			BitmapRef tile = Cache::Tile(Game_Map::GetChipsetName(), tile_id);
			SetBitmap(tile);
			r.Set(0, 0, 16, 16);
			SetSrcRect(r);
			SetOx(8);
			SetOy(16);
		} else {
			if (character_name.empty()) {
				SetBitmap(BitmapRef());
			} else {
				SetBitmap(Cache::Charset(character_name));
				chara_width = GetBitmap()->GetWidth() / 4 / 3;
				chara_height = GetBitmap()->GetHeight() / 2 / 4;
				SetOx(chara_width / 2);
				SetOy(chara_height);
				int sx = (character_index % 4) * chara_width * 3;
				int sy = (character_index / 4) * chara_height * 4;
				r.Set(sx, sy, chara_width * 3, chara_height * 4);
				SetSpriteRect(r);
			}
		}
	}

	if (tile_id == 0) {
		int row = character->GetDirection();
		r.Set(character->GetPattern() * chara_width, row * chara_height, chara_width, chara_height);
		SetSrcRect(r);
	}

	if (character->IsFlashPending()) {
		Color col;
		int dur;
		character->GetFlashParameters(col, dur);
		Flash(col, dur);
	}

	SetVisible(character->GetVisible());
	if (GetVisible()) {
		SetOpacity(character->GetOpacity());
	}

	SetX(character->GetScreenX());
	SetY(character->GetScreenY());
	SetZ(character->GetScreenZ(chara_height));
	
	//SetBlendType(character->GetBlendType());
	//SetBushDepth(character->GetBushDepth());
}
Ejemplo n.º 2
0
void Sprite_Character::Update() {
	Sprite::Update();
	Rect r;
	if (tile_id != character->GetTileId() ||
		character_name != character->GetSpriteName() ||
		character_index != character->GetSpriteIndex()) {
		tile_id = character->GetTileId();
		character_name = character->GetSpriteName();
		character_index = character->GetSpriteIndex();
		if (tile_id > 0) {
			BitmapRef tile = Cache::Tile(Game_Map::GetChipsetName(), tile_id);
			SetBitmap(tile);
			r.Set(0, 0, TILE_SIZE, TILE_SIZE);
			SetSrcRect(r);
			SetOx(8);
			SetOy(16);
		} else {
			if (character_name.empty()) {
				SetBitmap(BitmapRef());
			} else {
				SetBitmap(Cache::Charset(character_name));
				SetOx(chara_width / 2);
				SetOy(chara_height);
				int sx = (character_index % 4) * chara_width * 3;
				int sy = (character_index / 4) * chara_height * 4;
				r.Set(sx, sy, chara_width * 3, chara_height * 4);
				SetSpriteRect(r);
			}
		}
	}

	if (tile_id == 0) {
		int row = (character->IsSpinning() ? character->GetPrelockDirection() : character->GetDirection());
		r.Set(character->GetPattern() * chara_width, row * chara_height, chara_width, chara_height);
		SetSrcRect(r);
	}

	if (character->IsFlashPending()) {
		Color col = character->GetFlashColor();
		int dur = character->GetFlashTimeLeft();
		Flash(col, dur);
		// TODO: Gradual decrease of Flash Time Left
		character->SetFlashTimeLeft(0);
	}

	SetVisible(character->GetVisible());
	if (GetVisible()) {
		SetOpacity(character->GetOpacity());
	}

	SetX(character->GetScreenX());
	SetY(character->GetScreenY());
	SetZ(character->GetScreenZ(chara_height));
	
	//SetBlendType(character->GetBlendType());
	//SetBushDepth(character->GetBushDepth());
}
Ejemplo n.º 3
0
void Sprite_Character::Update() {
	Sprite::Update();
	Rect r;
	if (tile_id != character->GetTileId() ||
		character_name != character->GetCharacterName() ||
		character_index != character->GetCharacterIndex()) {
		tile_id = character->GetTileId();
		character_name = character->GetCharacterName();
		character_index = character->GetCharacterIndex();
		if (tile_id > 0) {
			BitmapRef tile = Cache::Tile(Game_Map::GetChipsetName(), tile_id);
			SetBitmap(tile);
			r.Set(0, 0, 16, 16);
			SetSrcRect(r);
			SetOx(8);
			SetOy(16);
		} else {
			if (character_name.empty()) {
				SetBitmap(BitmapRef());
			} else {
				SetBitmap(Cache::Charset(character_name));
				chara_width = GetBitmap()->GetWidth() / 4 / 3;
				chara_height = GetBitmap()->GetHeight() / 2 / 4;
				SetOx(chara_width / 2);
				SetOy(chara_height);
				int sx = (character_index % 4) * chara_width * 3;
				int sy = (character_index / 4) * chara_height * 4;
				r.Set(sx, sy, chara_width * 3, chara_height * 4);
				SetSpriteRect(r);
			}
		}
	}
	//SetVisible(character->GetVisible());
	if (tile_id == 0) {
		int row = character->GetDirection();
		r.Set(character->GetPattern() * chara_width, row * chara_height, chara_width, chara_height);
		SetSrcRect(r);
	}
	SetX(character->GetScreenX());
	SetY(character->GetScreenY());
	SetZ(character->GetScreenZ(chara_height));
	//SetOpacity(character->GetOpacity());
	//SetBlendType(character->GetBlendType());
	//SetBushDepth(character->GetBushDepth());
	/*if (character->GetAnimationId() != 0) {
		RPG::Animation animation = Data::animations[character->GetAnimationId()]
		this->Animation(animation, true);
		character->SetAnimationId(0);
	}*/
}
Ejemplo n.º 4
0
Text::Text(int x, int y, std::string fontName, std::string text, int taille)
	: text(text),
	taille(taille),
	fontName(fontName),
	surfaceText(nullptr),
	textTexture(nullptr)
{
	fgColor = { 0xFF, 0xFF, 0xFF };
	surfaceText = new SDL_Surface();

	font = TTF_OpenFont(fontName.c_str(), taille);

	surfaceText = TTF_RenderText_Blended_Wrapped(font, text.c_str(), fgColor, 950);
	textTexture = SDL_CreateTextureFromSurface(gEngine->GetRenderer(), surfaceText);

	std::stringstream ss;
	ss << fontName << "_" << taille;

	this->fontName = ss.str();
	SetTexture(this->fontName.c_str(), textTexture);
	SetPosition(x, y);
	SetSrcRect(0, 0, surfaceText->h, surfaceText->w);
	SetSize(surfaceText->w, surfaceText->h);

	SDL_FreeSurface(surfaceText);
}
Ejemplo n.º 5
0
void Sprite_Character::Update() {
	Sprite::Update();
	Rect r;
	if (tile_id != character->GetTileId() ||
		character_name != character->GetSpriteName() ||
		character_index != character->GetSpriteIndex()) {
		tile_id = character->GetTileId();
		character_name = character->GetSpriteName();
		character_index = character->GetSpriteIndex();
		if (tile_id > 0) {
			if (tile_request) {
				tile_request->Unbind(tile_request_id);
			}
			tile_request = AsyncHandler::RequestFile("ChipSet", Game_Map::GetChipsetName());
			tile_request_id = tile_request->Bind(&Sprite_Character::OnTileSpriteReady, this);
			tile_request->Start();
		} else {
			if (character_name.empty()) {
				SetBitmap(BitmapRef());
			} else {
				if (char_request) {
					char_request->Unbind(char_request_id);
				}
				char_request = AsyncHandler::RequestFile("CharSet", character_name);
				char_request_id = char_request->Bind(&Sprite_Character::OnCharSpriteReady, this);
				char_request->Start();
			}
		}
	}

	if (tile_id == 0) {
		int row = character->GetSpriteDirection();
		r.Set(character->GetPattern() * chara_width, row * chara_height, chara_width, chara_height);
		SetSrcRect(r);
	}

	if (character->IsFlashPending()) {
		Color col = character->GetFlashColor();
		int dur = character->GetFlashTimeLeft();
		Flash(col, dur);
		// TODO: Gradual decrease of Flash Time Left
		character->SetFlashTimeLeft(0);
	}

	SetVisible(character->GetVisible());
	if (GetVisible()) {
		SetOpacity(character->GetOpacity());
	}

	SetX(character->GetScreenX());
	SetY(character->GetScreenY());
	SetZ(character->GetScreenZ());

	//SetBlendType(character->GetBlendType());
	int bush_split = 4 - character->GetBushDepth();
	SetBushDepth(bush_split > 3 ? 0 : GetHeight() / bush_split);
}
void BattleAnimation::DrawAt(int x, int y) {
	if (IsDone()) {
		return;
	}
	if (!GetVisible()) {
		return;
	}

	const RPG::AnimationFrame& anim_frame = animation.frames[frame];

	std::vector<RPG::AnimationCellData>::const_iterator it;
	for (it = anim_frame.cells.begin(); it != anim_frame.cells.end(); ++it) {
		const RPG::AnimationCellData& cell = *it;

		if (!cell.valid) {
			// Skip unused cells (they are created by deleting cells in the
			// animation editor, resulting in gaps)
			continue;
		}

		SetX(cell.x + x);
		SetY(cell.y + y);
		int sx = cell.cell_id % 5;
		int sy = cell.cell_id / 5;
		int size = large ? 128 : 96;
		SetSrcRect(Rect(sx * size, sy * size, size, size));
		SetOx(size / 2);
		SetOy(size / 2);
		SetTone(Tone(cell.tone_red * 128 / 100,
			cell.tone_green * 128 / 100,
			cell.tone_blue * 128 / 100,
			cell.tone_gray * 128 / 100));
		SetOpacity(255 * (100 - cell.transparency) / 100);
		SetZoomX(cell.zoom / 100.0);
		SetZoomY(cell.zoom / 100.0);
		Sprite::Draw();
	}

	if (anim_frame.cells.empty()) {
		// Draw an empty sprite when no cell is available in the animation
		SetSrcRect(Rect(0, 0, 0, 0));
		Sprite::Draw();
	}
}
Ejemplo n.º 7
0
void Sprite_Character::OnTileSpriteReady(FileRequestResult*) {
	BitmapRef tile = Cache::Tile(Game_Map::GetChipsetName(), tile_id);
	SetBitmap(tile);

	Rect r;
	r.Set(0, 0, TILE_SIZE, TILE_SIZE);
	SetSrcRect(r);
	SetOx(8);
	SetOy(16);

	Update();
}
void BattleAnimation::OnBattle2SpriteReady(FileRequestResult* result) {
	if (result->success) {
		BitmapRef bitmap = Cache::Battle2(result->file);
		if (bitmap->GetWidth() == 640) {
			large = true;
		}
		SetBitmap(bitmap);
		SetSrcRect(Rect(0, 0, 0, 0));
	}
	else {
		Output::Warning("Couldn't find animation: %s", result->file.c_str());
	}
}
Ejemplo n.º 9
0
void Text::SetText(std::string newText)
{
	text = newText;

	surfaceText = TTF_RenderText_Blended_Wrapped(font, text.c_str(), fgColor, 950);	textTexture = SDL_CreateTextureFromSurface(gEngine->GetRenderer(), surfaceText);
	//SetSurfaceAlpha(textTexture, 128);

	std::stringstream ss;
	ss << fontName << "_" << taille;

	fontName = ss.str();
	SetTexture(fontName.c_str(), textTexture);
	SetSrcRect(0, 0, surfaceText->h, surfaceText->w);
	SetSize(surfaceText->w, surfaceText->h);

	SDL_FreeSurface(surfaceText);
}
void BattleAnimation::OnBattleSpriteReady(FileRequestResult* result) {
	if (result->success) {
		//Normally only battle2 sprites are "large" sprites - but the check doesn't hurt.
		BitmapRef bitmap = Cache::Battle(result->file);
		if (bitmap->GetWidth() == 640) {
			large = true;
		}
		SetBitmap(bitmap);
		
		SetSrcRect(Rect(0, 0, 0, 0));
	}
	else {
		// Try battle2
		FileRequestAsync* request = AsyncHandler::RequestFile("Battle2", result->file);
		request_id = request->Bind(&BattleAnimation::OnBattle2SpriteReady, this);
		request->Start();
	}
}
Ejemplo n.º 11
0
void Sprite_Battler::Update() {
	if (sprite_name != battler->GetSpriteName() ||
		hue != battler->GetHue()) {

		CreateSprite();
	}

	if (!battler->IsHidden() && old_hidden != battler->IsHidden()) {
		SetOpacity(255);
		SetVisible(true);
		SetAnimationState(AnimationState_Idle);
		idling = true;
	}

	old_hidden = battler->IsHidden();

	Sprite::Update();

	++cycle;

	if (battler->GetBattleAnimationId() <= 0) {
		// Animations for monster
		if (anim_state == AnimationState_Idle) {
			SetOpacity(255);
			idling = true;
		}
		else if (anim_state == AnimationState_Dead) {
			if (fade_out > 0) {
				fade_out -= 15;
				SetOpacity(std::max(0, fade_out));
			} else {
				idling = true;
			}
		}
		else if (anim_state == AnimationState_Damage) {
			flash_counter = (flash_counter + 1) % 10;
			SetOpacity(flash_counter > 5 ? 50 : 255);
			if (cycle == 60) {
				SetAnimationState(AnimationState_Idle);
				idling = true;
				cycle = 0;
			}
		}
		else {
			if (cycle == 60) {
				SetAnimationState(AnimationState_Idle);
				idling = true;
				cycle = 0;
			}
		}
	} else if (anim_state > 0) {
		// Animations for allies
		if (Player::IsRPG2k3()) {
			if (animation) {
				animation->Update();

				if (animation->IsDone()) {
					if (loop_state == LoopState_DefaultAnimationAfterFinish) {
						const RPG::State* state = battler->GetSignificantState();
						if (state) {
							SetAnimationState(state->battler_animation_id + 1);
						} else {
							SetAnimationState(AnimationState_Idle);
						}
						idling = true;
					}
					animation->SetFrame(0);
				}

				return;
			}

			static const int frames[] = {0,1,2,1,0};
			int frame = frames[cycle / 10];
			if (frame == sprite_frame)
				return;

			const RPG::BattlerAnimation& anim = Data::battleranimations[battler->GetBattleAnimationId() - 1];
			const RPG::BattlerAnimationExtension& ext = anim.base_data[anim_state - 1];

			SetSrcRect(Rect(frame * 48, ext.battler_index * 48, 48, 48));

			if (cycle == 40) {
				cycle = 0;

				if (loop_state == LoopState_DefaultAnimationAfterFinish)
					idling = true;
			}

			if (idling) {
				const RPG::State* state = battler->GetSignificantState();
				int idling_anim = state ? state->battler_animation_id + 1 : AnimationState_Idle;
				if (idling_anim == 101)
					idling_anim = 7;

				if (idling_anim != anim_state)
					SetAnimationState(idling_anim);
				idling = true;
			}
		}
	}
}
Ejemplo n.º 12
0
void Sprite_Battler::OnBattlercharsetReady(FileRequestResult* result, int battler_index) {
	SetBitmap(Cache::Battlecharset(result->file));
	SetSrcRect(Rect(0, battler_index * 48, 48, 48));
}