Skip to content

Commit

Permalink
Implement bush depth for character sprites and fix screen center
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegeri committed Aug 7, 2014
1 parent 0cb68c5 commit 74c660f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 37 deletions.
18 changes: 5 additions & 13 deletions src/bitmap_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,14 @@ void BitmapScreen::BlitScreen(int x, int y, Rect const& src_rect) {

Rect rect = src_rect_effect.GetSubRect(src_rect);

Rect bush_rect = src_rect_effect;
bush_rect.height -= bush_effect;
bush_rect = bush_rect.GetSubRect(src_rect);
int bush_y = (rect.y + rect.height) - (bush_rect.y + bush_rect.height);

bool need_scale = false;
BitmapRef draw_bitmap = Refresh(rect, need_scale, bush_y);
BitmapRef draw_bitmap = Refresh(rect, need_scale);

bitmap_changed = false;
needs_refresh = false;

if(draw_bitmap) {
BlitScreenIntern(*draw_bitmap, x, y, rect, need_scale, bush_y);
BlitScreenIntern(*draw_bitmap, x, y, rect, need_scale, bush_effect);
}
}

Expand All @@ -94,10 +89,9 @@ void BitmapScreen::BlitScreenTiled(Rect const& src_rect, Rect const& dst_rect, i
return;

Rect rect = src_rect_effect.GetSubRect(src_rect);
int bush_y = 0;

bool need_scale = false;
BitmapRef draw_bitmap = Refresh(rect, need_scale, bush_y);
BitmapRef draw_bitmap = Refresh(rect, need_scale);

bitmap_changed = false;
needs_refresh = false;
Expand Down Expand Up @@ -330,14 +324,12 @@ double BitmapScreen::GetWaverEffectPhase() const {
}

void BitmapScreen::BlitScreenIntern(Bitmap const& draw_bitmap, int x, int y,
Rect const& src_rect, bool need_scale, int bush_y) {
Rect const& src_rect, bool need_scale, int opacity_split) {
if (! &draw_bitmap)
return;

BitmapRef dst = DisplayUi->GetDisplaySurface();

int opacity_split = bush_y;

double zoom_x = need_scale ? zoom_x_effect : 1.0;
double zoom_y = need_scale ? zoom_y_effect : 1.0;

Expand All @@ -347,7 +339,7 @@ void BitmapScreen::BlitScreenIntern(Bitmap const& draw_bitmap, int x, int y,
waver_effect_depth, waver_effect_phase);
}

BitmapRef BitmapScreen::Refresh(Rect& rect, bool& need_scale, int& bush_y) {
BitmapRef BitmapScreen::Refresh(Rect& rect, bool& need_scale) {
need_scale = false;

rect.Adjust(bitmap->GetWidth(), bitmap->GetHeight());
Expand Down
2 changes: 1 addition & 1 deletion src/bitmap_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class BitmapScreen {
void BlitScreenIntern(Bitmap const& draw_bitmap, int x, int y, Rect const& src_rect,
bool need_scale, int bush_y);

BitmapRef Refresh(Rect& rect, bool& need_scale, int& bush_y);
BitmapRef Refresh(Rect& rect, bool& need_scale);

BitmapRef bitmap_effects;
BitmapRef bitmap_scale;
Expand Down
5 changes: 2 additions & 3 deletions src/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ void Bitmap::EffectsBlit(int x, int y, Bitmap const& src, Rect const& src_rect,
EffectsBlit(x, y, src, blit_rect,
top_opacity, waver_depth, waver_phase);

blit_rect = src_rect;
blit_rect.y = src_rect.height - opacity_split;
blit_rect.y += blit_rect.height;
blit_rect.height = opacity_split;
x += src_rect.height - opacity_split;
y += src_rect.height - opacity_split;
EffectsBlit(x, y, src, blit_rect,
bottom_opacity, waver_depth, waver_phase);
}
Expand Down
4 changes: 2 additions & 2 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,8 @@ bool Game_Character::IsSpinning() {
return animation_type == RPG::EventPage::AnimType_spin;
}

void Game_Character::UpdateBushDepth() {
// TODO
int Game_Character::GetBushDepth() {
return Game_Map::GetBushDepth(GetX(), GetY());
}

void Game_Character::SetGraphic(const std::string& name, int index) {
Expand Down
7 changes: 6 additions & 1 deletion src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,12 @@ class Game_Character {
*/
bool IsSpinning();

virtual void UpdateBushDepth();
/**
* Gets the bush depth of the tile where this character is standing
*
* @return Bush depth at this character's position
*/
int GetBushDepth();

void SetGraphic(const std::string& name, int index);

Expand Down
5 changes: 2 additions & 3 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,8 @@ bool Game_Map::IsLandable(int x, int y, const Game_Character *self_event)
return true;
}

bool Game_Map::IsBush(int /* x */, int /* y */) {
// TODO
return false;
int Game_Map::GetBushDepth(int x, int y) {
return Data::data.terrains[GetTerrainTag(x,y) - 1].bush_depth;
}

bool Game_Map::IsCounter(int x, int y) {
Expand Down
6 changes: 3 additions & 3 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ namespace Game_Map {
bool IsLandable(int x, int y, const Game_Character* self_event = NULL);

/**
* Gets if a tile has bush flag.
* Gets the bush depth at a certain tile.
*
* @param x tile x.
* @param y tile y.
* @return whether has the bush flag.
* @return bush depth.
*/
bool IsBush(int x, int y);
int GetBushDepth(int x, int y);

/**
* Gets if a tile has counter flag.
Expand Down
13 changes: 5 additions & 8 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ bool Game_Player::IsTeleporting() const {
}

void Game_Player::Center(int x, int y) {

int center_x = (DisplayUi->GetWidth() / ( TILE_SIZE/16) - TILE_SIZE) * 8;
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE/16) - (TILE_SIZE/2)) * 8;
int center_x = (DisplayUi->GetWidth() / ( TILE_SIZE / 16) - TILE_SIZE * 2) * 8;
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE / 16) - TILE_SIZE) * 8;
int max_x = (Game_Map::GetWidth() - DisplayUi->GetWidth() / TILE_SIZE) * (SCREEN_TILE_WIDTH);
int max_y = (Game_Map::GetHeight() - DisplayUi->GetHeight() / TILE_SIZE) * (SCREEN_TILE_WIDTH);
Game_Map::SetDisplayX(max(0, min((x * SCREEN_TILE_WIDTH - center_x), max_x)));
Expand All @@ -249,10 +248,9 @@ void Game_Player::MoveTo(int x, int y) {
}

void Game_Player::UpdateScroll(int last_real_x, int last_real_y) {
int center_x = (DisplayUi->GetWidth() / ( TILE_SIZE/16) - TILE_SIZE) * 8;
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE/16) - (TILE_SIZE/2)) * 8;
int center_x = (DisplayUi->GetWidth() / (TILE_SIZE / 16) - TILE_SIZE * 2) * 8;
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE / 16) - TILE_SIZE) * 8;


if (Game_Map::IsPanLocked())
return;

Expand All @@ -267,8 +265,7 @@ void Game_Player::UpdateScroll(int last_real_x, int last_real_y) {
Game_Map::ScrollDown(dy);
if (dy < 0)
Game_Map::ScrollUp(-dy);
}
else {
} else {
if (real_y > last_real_y && real_y - Game_Map::GetDisplayY() > center_y)
Game_Map::ScrollDown(real_y - last_real_y);

Expand Down
1 change: 0 additions & 1 deletion src/game_vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ void Game_Vehicle::SyncWithPlayer() {
real_x = Main_Data::game_player->GetRealX();
real_y = Main_Data::game_player->GetRealY();
SetDirection(Main_Data::game_player->GetDirection());
UpdateBushDepth();
}

int Game_Vehicle::GetScreenY() const {
Expand Down
5 changes: 3 additions & 2 deletions src/sprite_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ void Sprite_Character::Update() {
SetX(character->GetScreenX());
SetY(character->GetScreenY());
SetZ(character->GetScreenZ(chara_height));

//SetBlendType(character->GetBlendType());
//SetBushDepth(character->GetBushDepth());
int bush_split = 4 - character->GetBushDepth();
SetBushDepth(bush_split > 3 ? 0 : GetHeight() / bush_split);
}

Game_Character* Sprite_Character::GetCharacter() {
Expand Down

0 comments on commit 74c660f

Please sign in to comment.