Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tilemap drawing and airship ascending/descending animation #546

Merged
merged 2 commits into from
Aug 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,14 @@ int Game_Character::GetScreenY() const {
}

int Game_Character::GetScreenZ() const {
int z = (GetRealY() - Game_Map::GetDisplayY() + 3) / TILE_SIZE + (SCREEN_TILE_WIDTH / TILE_SIZE);
int z = this == Main_Data::game_player.get() ? 1 : 0;

int max_height = Game_Map::GetHeight() * TILE_SIZE;
// For events on the screen, this should be inside a 0-40 range
z += GetScreenY() >> 3;

// wrap on map boundaries
if (z < 0) {
z += max_height;
}

if (GetLayer() == RPG::EventPage::Layers_below) {
z -= TILE_SIZE;
}
if (GetLayer() == RPG::EventPage::Layers_above) {
z += TILE_SIZE;
}

// Prevent underflow (not rendered in this case)
// ToDo: It's probably the best to rework the z-layer part of the tilemap code
if (z < 1) {
z = 1;
}
z += GetLayer() * 50;

// 1 less to correctly render compared to some tile map tiles (star tiles e.g.)
return z - 1;
return z;
}

void Game_Character::Update() {
Expand Down
14 changes: 9 additions & 5 deletions src/game_vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Game_Vehicle::Game_Vehicle(Type _type) :
type = _type;
driving = false;
SetDirection(Left);
SetSpriteDirection(Left);
walk_animation = type != Airship;
animation_type = RPG::EventPage::AnimType_continuous;
LoadSystemSettings();
Expand Down Expand Up @@ -261,7 +262,7 @@ void Game_Vehicle::Refresh() {
SetMoveSpeed(RPG::EventPage::MoveSpeed_normal);
break;
case Airship:
SetLayer(driving ? RPG::EventPage::Layers_above : RPG::EventPage::Layers_below);
SetLayer(driving ? RPG::EventPage::Layers_above : RPG::EventPage::Layers_same);
SetMoveSpeed(RPG::EventPage::MoveSpeed_double);
break;
}
Expand Down Expand Up @@ -308,20 +309,21 @@ void Game_Vehicle::GetOn() {

void Game_Vehicle::GetOff() {
if (type == Airship) {
walk_animation = false;
data.remaining_descent = SCREEN_TILE_WIDTH;
Main_Data::game_player->SetDirection(Left);
} else {
driving = false;
SetDirection(Left);
}
SetDirection(Left);
SetSpriteDirection(Left);
}

bool Game_Vehicle::IsInUse() const {
return driving;
}

void Game_Vehicle::SyncWithPlayer() {
if (!driving || IsAscending() || IsDescending())
return;
SetX(Main_Data::game_player->GetX());
SetY(Main_Data::game_player->GetY());
remaining_step = Main_Data::game_player->GetRemainingStep();
Expand Down Expand Up @@ -378,9 +380,11 @@ void Game_Vehicle::Update() {
data.remaining_descent -= 8;
if (!IsDescending()) {
if (CanLand()) {
SetLayer(RPG::EventPage::Layers_below);
SetLayer(RPG::EventPage::Layers_same);
driving = false;
data.flying = false;
walk_animation = false;
pattern = 1;
} else {
// Can't land here, ascend again
data.remaining_ascent = SCREEN_TILE_WIDTH;
Expand Down
4 changes: 2 additions & 2 deletions src/sprite_airshipshadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ void Sprite_AirshipShadow::Update() {

SetX(Main_Data::game_player->GetScreenX());
SetY(Main_Data::game_player->GetScreenY());
// Bit higher then the rest on the tilemap
SetZ(Main_Data::game_player->GetScreenZ() + TILE_SIZE * 2);
// Higher than the events in the upper layer
SetZ(151);
}
69 changes: 28 additions & 41 deletions src/tilemap_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ TilemapLayer::TilemapLayer(int ilayer) :
memset(autotiles_ab, 0, sizeof(autotiles_ab));
memset(autotiles_d, 0, sizeof(autotiles_d));

int tiles_y = (int)ceil(DisplayUi->GetHeight() / (float)TILE_SIZE) + 1;
for (int i = 0; i < tiles_y + 2; i++) {
tilemap_tiles.push_back(EASYRPG_MAKE_SHARED<TilemapTile>(this, TILE_SIZE * i));
}
// SubLayer for the tiles with Wall or Above passability
// Its z-value should be between the z of the events in the upper layer and the hero
sublayers.push_back(EASYRPG_MAKE_SHARED<TilemapSubLayer>(this, 98+layer));
// SubLayer for the tiles without Wall or Above passability
// Its z-value should be under z of the events in the lower layer
sublayers.push_back(EASYRPG_MAKE_SHARED<TilemapSubLayer>(this, -2+layer));
}

void TilemapLayer::DrawTile(Bitmap& screen, int x, int y, int row, int col, bool autotile) {
Expand Down Expand Up @@ -197,17 +199,8 @@ void TilemapLayer::Draw(int z_order) {
// Get the tile data
TileData &tile = data_cache[map_x][map_y];

int map_draw_z = tile.z;

if (map_draw_z > 0) {
if (map_draw_z < 9999) {
map_draw_z += y * TILE_SIZE;
if (y == 0) map_draw_z += TILE_SIZE;
}
}

// Draw the tile if its z is being draw now
if (z_order == map_draw_z) {
// Draw the sublayer if its z is being draw now
if (z_order == tile.z) {
if (layer == 0) {
// If lower layer

Expand Down Expand Up @@ -306,30 +299,24 @@ void TilemapLayer::CreateTileCache(const std::vector<short>& nmap_data) {

// Calculate the tile Z
if (!passable.empty()) {
if (tile.ID >= BLOCK_F) {
if (tile.ID >= BLOCK_F) { // Upper layer
if ((passable[substitutions[tile.ID - BLOCK_F]] & Passable::Above) != 0)
tile.z = 32;

}
else if (tile.ID >= BLOCK_E) {
if ((passable[substitutions[tile.ID - BLOCK_E + 18]] & Passable::Above) != 0)
tile.z = 32;

}
else if (tile.ID >= BLOCK_D) {
if ((passable[(tile.ID - BLOCK_D) / 50 + 6] & (Passable::Wall | Passable::Above)) != 0)
tile.z = 32;
tile.z = 99; // Upper sublayer
else
tile.z = -1; // Lower sublayer

} else { // Lower layer
int chip_index =
tile.ID >= BLOCK_E ? tile.ID - BLOCK_E + 18 :
tile.ID >= BLOCK_D ? (tile.ID - BLOCK_D) / 50 + 6 :
tile.ID >= BLOCK_C ? (tile.ID - BLOCK_C) / 50 + 3 :
tile.ID / 1000;
if ((passable[chip_index] & (Passable::Wall | Passable::Above)) != 0)
tile.z = 98; // Upper sublayer
else
tile.z = -2; // Lower sublayer

}
else if (tile.ID >= BLOCK_C) {
if ((passable[(tile.ID - BLOCK_C) / 50 + 3] & Passable::Above) != 0)
tile.z = 32;

}
else {
if ((passable[tile.ID / 1000] & Passable::Above) != 0)
tile.z = 32;
}
}
data_cache[x][y] = tile;
}
Expand Down Expand Up @@ -697,30 +684,30 @@ void TilemapLayer::Substitute(int old_id, int new_id) {
}
}

TilemapTile::TilemapTile(TilemapLayer* tilemap, int z) :
TilemapSubLayer::TilemapSubLayer(TilemapLayer* tilemap, int z) :
type(TypeTilemap),
tilemap(tilemap),
z(z)
{
Graphics::RegisterDrawable(this);
}

TilemapTile::~TilemapTile() {
TilemapSubLayer::~TilemapSubLayer() {
Graphics::RemoveDrawable(this);
}

void TilemapTile::Draw() {
void TilemapSubLayer::Draw() {
if (!tilemap->GetChipset()) {
return;
}

tilemap->Draw(GetZ());
}

int TilemapTile::GetZ() const {
int TilemapSubLayer::GetZ() const {
return z;
}

DrawableType TilemapTile::GetType() const {
DrawableType TilemapSubLayer::GetType() const {
return type;
}
11 changes: 7 additions & 4 deletions src/tilemap_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@

class TilemapLayer;

class TilemapTile : public Drawable {
/**
* TilemapSubLayer class.
*/
class TilemapSubLayer : public Drawable {
public:
TilemapTile(TilemapLayer* tilemap, int z);
~TilemapTile();
TilemapSubLayer(TilemapLayer* tilemap, int z);
~TilemapSubLayer();

void Draw();

Expand Down Expand Up @@ -130,7 +133,7 @@ class TilemapLayer {
int z;
};
std::vector<std::vector<TileData> > data_cache;
std::vector<EASYRPG_SHARED_PTR<TilemapTile> > tilemap_tiles;
std::vector<EASYRPG_SHARED_PTR<TilemapSubLayer> > sublayers;
};

#endif