Skip to content

Commit

Permalink
Floor + Optimisation + Player strafe (Shift )
Browse files Browse the repository at this point in the history
  • Loading branch information
MackValentine committed Oct 21, 2024
1 parent 93b36c7 commit 8bc7900
Show file tree
Hide file tree
Showing 17 changed files with 786 additions and 504 deletions.
6 changes: 6 additions & 0 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ void Game_Character::UpdateMoveRoute(int32_t& current_index, const lcf::rpg::Mov
}
Move(GetDirection());

static const int move_speed[] = { 16, 8, 6, 4, 3, 2 };
doomWait = move_speed[GetMoveSpeed() - 1];

if (IsStopping()) {
// Move failed
if (current_route.skippable) {
Expand Down Expand Up @@ -359,6 +362,9 @@ void Game_Character::UpdateMoveRoute(int32_t& current_index, const lcf::rpg::Mov
SetFacing(GetDirection());
SetMaxStopCountForTurn();
SetStopCount(0);

static const int turn_speed[] = { 64, 32, 24, 16, 12, 8 };
doomWait = turn_speed[GetMoveSpeed() - 1];
} else {
switch (cmd) {
case Code::wait:
Expand Down
3 changes: 3 additions & 0 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,9 @@ class Game_Character {
static constexpr int GetDxFromDirection(int dir);
static constexpr int GetDyFromDirection(int dir);

/** Wait time for DOOM mode */
int doomWait = 0;

protected:
explicit Game_Character(Type type, lcf::rpg::SaveMapEventBase* d);
/** Check for and fix incorrect data after loading save game */
Expand Down
1 change: 1 addition & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5215,6 +5215,7 @@ bool Game_Interpreter::CommandSetDoomMap(lcf::rpg::EventCommand const& com) {

int picID = ValueOrVariable(com.parameters[0], com.parameters[1]);

Main_Data::game_player->doomMoveType = com.parameters[2];
Main_Data::game_pictures->ShowDoomMap(picID);

return true;
Expand Down
36 changes: 36 additions & 0 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,3 +2037,39 @@ bool Game_Map::Parallax::FakeXPosition() {
bool Game_Map::Parallax::FakeYPosition() {
return parallax_fake_y;
}

int Game_Map::GetTileID(int x, int y, int layer) {


int tile_index = x + y * GetTilesX();
int tile_raw_id = map->lower_layer[tile_index];
int tile_id = 0;

if (tile_raw_id >= BLOCK_E) {
tile_id = tile_raw_id - BLOCK_E;
tile_id = map_info.lower_tiles[tile_id] + BLOCK_E_INDEX;

}
else if (tile_raw_id >= BLOCK_D) {
/*tile_id = (tile_raw_id - BLOCK_D) / BLOCK_D_STRIDE + BLOCK_D_INDEX;
int autotile_id = (tile_raw_id - BLOCK_D) % BLOCK_D_STRIDE;
Output::Debug(" {} {} {}", tile_id, autotile_id, tile_raw_id);*/
//return tile_id;
/*if (((Passable::Wall) != 0) && (
(autotile_id >= 20 && autotile_id <= 23) ||
(autotile_id >= 33 && autotile_id <= 37) ||
autotile_id == 42 || autotile_id == 43 ||
autotile_id == 45 || autotile_id == 46))
return autotile_id;*/

}
else if (tile_raw_id >= BLOCK_C) {
tile_id = (tile_raw_id - BLOCK_C) / BLOCK_C_STRIDE + BLOCK_C_INDEX;

}
else if (map->lower_layer[tile_index] < BLOCK_C) {
tile_id = tile_raw_id / BLOCK_B_STRIDE;
}

return tile_id;
}
2 changes: 2 additions & 0 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ namespace Game_Map {
void AddEventToSwitchCache(lcf::rpg::Event& ev, int switch_id);
void AddEventToVariableCache(lcf::rpg::Event& ev, int var_id);

int GetTileID(int x, int y, int layer);

namespace Parallax {
struct Params {
std::string name;
Expand Down
52 changes: 38 additions & 14 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,38 +327,62 @@ void Game_Player::UpdateNextMovementAction() {
break;
}

if (move_dir >= 0 && (doomMoveType <= 0 && doomWait <= 0)) {
if (move_dir >= 0 && ((doomMoveType <= 0 || doomMoveType == 2) && doomWait <= 0)) {
SetThrough((Player::debug_flag && Input::IsPressed(Input::DEBUG_THROUGH)) || data()->move_route_through);
if (doomMoveType == 0) {

static const int turn_speed[] = { 64, 32, 24, 16, 12, 8 };
static const int move_speed[] = { 16, 8, 6, 4, 3, 2 };

if (move_dir == Left) {

Turn90DegreeLeft();
SetFacing(GetDirection());
doomWait = turn_speed[GetMoveSpeed() - 1];//1 << (1 + GetMoveSpeed());

if (Input::IsPressed(Input::SHIFT)) {
int d = GetDirection();
Turn90DegreeLeft();
Move(GetDirection());
doomWait = move_speed[GetMoveSpeed() - 1];
SetDirection(d);
}
else {
Turn90DegreeLeft();
SetFacing(GetDirection());
doomWait = turn_speed[GetMoveSpeed() - 1];//1 << (1 + GetMoveSpeed());
}
}
else if (move_dir == Right) {

Turn90DegreeRight();
SetFacing(GetDirection());
doomWait = turn_speed[GetMoveSpeed() - 1];
if (Input::IsPressed(Input::SHIFT)) {
int d = GetDirection();
Turn90DegreeRight();
Move(GetDirection());
doomWait = move_speed[GetMoveSpeed() - 1];
SetDirection(d);
}
else {
Turn90DegreeRight();
SetFacing(GetDirection());
doomWait = turn_speed[GetMoveSpeed() - 1];
}

}
else if (move_dir == Up) {

Move(GetDirection());
static const int move_speed[] = { 16, 8, 6, 4, 3, 2 };
doomWait = move_speed[GetMoveSpeed() - 1];

}
else if (move_dir == Down) {

Turn180Degree();
SetFacing(GetDirection());
doomWait = turn_speed[GetMoveSpeed() - 1];
if (Input::IsPressed(Input::SHIFT)) {
int d = GetDirection();
Turn180Degree();
Move(GetDirection());
doomWait = move_speed[GetMoveSpeed() - 1];
SetDirection(d);
}
else {
Turn180Degree();
SetFacing(GetDirection());
doomWait = turn_speed[GetMoveSpeed() - 1];
}

}

Expand Down
3 changes: 1 addition & 2 deletions src/game_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ class Game_Player : public Game_PlayerBase {
void UpdateSaveCounts(int db_save_count, int map_save_count);

bool canMove = false;
int doomMoveType = 1;
int doomWait = 0;
int doomMoveType = 0;

// Move things here
bool CheckActionEvent();
Expand Down
5 changes: 4 additions & 1 deletion src/scene_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ void Scene_Map::UpdateInn() {

BitmapRef Scene_Map::GetEventSprite(int i) {
auto s = spriteset->GetEventSprite(i);

return s;
}

Expand All @@ -536,3 +535,7 @@ BitmapRef Scene_Map::GetChipset() {
BitmapRef Scene_Map::GetTile(int x, int y, int layer) {
return spriteset->GetTile(x, y, layer);
}

int Scene_Map::GetTileID(int x, int y, int layer) {
return spriteset->GetTileID(x, y, layer);
}
1 change: 1 addition & 0 deletions src/scene_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Scene_Map: public Scene {
BitmapRef GetEventSprite(int i);
BitmapRef GetChipset();
BitmapRef GetTile(int x, int y, int layer);
int GetTileID(int x, int y, int layer);

private:
enum TeleportTransitionRule {
Expand Down
68 changes: 44 additions & 24 deletions src/spriteset_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,36 +332,52 @@ void Spriteset_Map::CalculatePanoramaRenderOffset() {
}

BitmapRef Spriteset_Map::GetEventSprite(int evid) {

for (int i = 0;i< character_sprites.size();i++) {
bool setBmp = false;
if (character_sprites[i]->GetCharacter()->GetType() == Game_Character::Type::Event) {
int id = ((Game_Event*)character_sprites[i]->GetCharacter())->GetId();
if (id == evid) {
BitmapRef bitmap = character_sprites[i]->GetBitmap();
BitmapRef b = Bitmap::Create(24,32, Color(0, 0, 0, 0));
Rect r = character_sprites[i]->GetSrcRect();

// If it's not a tileSprite, and sprite isn't fixed, we need to calc the rotation
if (Main_Data::game_player->GetDirection() > 0 && !character_sprites[i]->GetCharacter()->HasTileSprite()
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_fixed_continuous
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_fixed_graphic
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_fixed_non_continuous
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_spin
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_step_frame_fix) {
int data[3][4] = { {{3}, {-1}, {-1}, {-1}},
{{2}, {2}, {-2}, {-2}},
{{1}, {1}, {1}, {-3}}};

int d = data[Main_Data::game_player->GetDirection() - 1][character_sprites[i]->GetCharacter()->GetDirection()];

r.y += d * 32;
r.y = r.y % (32 * 4);

}

b->Blit(0, 0, *bitmap, r, 255);
return b;
setBmp = true;
}
}
else if (character_sprites[i]->GetCharacter()->GetType() == Game_Character::Type::Player && evid == 0) {
setBmp = true;
}
if (setBmp) {
BitmapRef bitmap = character_sprites[i]->GetBitmap();
BitmapRef b = Bitmap::Create(24,32, Color(0, 0, 0, 0));
Rect r = character_sprites[i]->GetSrcRect();

// If it's not a tileSprite, and sprite isn't fixed, we need to calc the rotation
if (Main_Data::game_player->doomMoveType != 2 && Main_Data::game_player->GetDirection() > 0 && !character_sprites[i]->GetCharacter()->HasTileSprite()
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_fixed_continuous
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_fixed_graphic
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_fixed_non_continuous
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_spin
&& character_sprites[i]->GetCharacter()->GetAnimationType() != Game_Character::AnimType::AnimType_step_frame_fix) {
int data[3][4] = { {{3}, {-1}, {-1}, {-1}},
{{2}, {2}, {-2}, {-2}},
{{1}, {1}, {1}, {-3}}};

int d = data[Main_Data::game_player->GetDirection() - 1][character_sprites[i]->GetCharacter()->GetDirection()];

r.y += d * 32;
r.y = r.y % (32 * 4);

}

if (!character_sprites[i]->GetCharacter()->HasTileSprite()) {
if (character_sprites[i]->GetCharacter()->GetSpriteIndex() > 0)
r.x += (character_sprites[i]->GetCharacter()->GetSpriteIndex() * 72) % 288;
if (character_sprites[i]->GetCharacter()->GetSpriteIndex() >= 4)
r.y += 128;
}

b->Blit(0, 0, *bitmap, r, 255);
return b;
}

}

return nullptr;
Expand All @@ -375,3 +391,7 @@ BitmapRef Spriteset_Map::GetChipset() {
BitmapRef Spriteset_Map::GetTile(int x, int y, int layer) {
return tilemap->GetTile(x, y, layer);
}

int Spriteset_Map::GetTileID(int x, int y, int layer) {
return tilemap->GetTileID(x, y, layer);
}
1 change: 1 addition & 0 deletions src/spriteset_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Spriteset_Map {
BitmapRef GetEventSprite(int i);
BitmapRef GetChipset();
BitmapRef GetTile(int x, int y, int layer);
int GetTileID(int x, int y, int layer);

protected:
std::unique_ptr<Tilemap> tilemap;
Expand Down
Loading

0 comments on commit 8bc7900

Please sign in to comment.