Skip to content

Commit

Permalink
Implement screen shaking on the battle screen
Browse files Browse the repository at this point in the history
Moving the background was done my modifying Background directly, and
the sprites were moved by mimicing the method used for moving
characters on the map screen, with similar GetDisplayX functions.

Other objects on the battle screen don't seem to shake.
  • Loading branch information
scurest committed Feb 10, 2017
1 parent 6c0efe1 commit 891631f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
11 changes: 8 additions & 3 deletions src/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "cache.h"
#include "background.h"
#include "bitmap.h"
#include "main_data.h"

Background::Background(const std::string& name) :
visible(true),
Expand Down Expand Up @@ -61,7 +62,7 @@ Background::Background(int terrain_id) :
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain.background_a_name);
request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
request->Start();

bg_hscroll = terrain.background_a_scrollh ? terrain.background_a_scrollh_speed : 0;
bg_vscroll = terrain.background_a_scrollv ? terrain.background_a_scrollv_speed : 0;
}
Expand Down Expand Up @@ -125,10 +126,14 @@ void Background::Draw() {
return;

BitmapRef dst = DisplayUi->GetDisplaySurface();
Rect dst_rect = dst->GetRect();

int shake_pos = Main_Data::game_data.screen.shake_position;
dst_rect.x += shake_pos;

if (bg_bitmap)
dst->TiledBlit(-Scale(bg_x), -Scale(bg_y), bg_bitmap->GetRect(), *bg_bitmap, dst->GetRect(), 255);
dst->TiledBlit(-Scale(bg_x), -Scale(bg_y), bg_bitmap->GetRect(), *bg_bitmap, dst_rect, 255);

if (fg_bitmap)
dst->TiledBlit(-Scale(fg_x), -Scale(fg_y), fg_bitmap->GetRect(), *fg_bitmap, dst->GetRect(), 255);
dst->TiledBlit(-Scale(fg_x), -Scale(fg_y), fg_bitmap->GetRect(), *fg_bitmap, dst_rect, 255);
}
15 changes: 12 additions & 3 deletions src/game_battler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool Game_Battler::IsSkillUsable(int skill_id) const {
if (CalculateSkillCost(skill_id) > GetSp()) {
return false;
}

// > 10 makes any skill usable
int smallest_physical_rate = 11;
int smallest_magical_rate = 11;
Expand Down Expand Up @@ -230,11 +230,11 @@ bool Game_Battler::UseItem(int item_id) {

return was_used;
}

if (item.type == RPG::Item::Type_switch) {
return true;
}

switch (item.type) {
case RPG::Item::Type_weapon:
case RPG::Item::Type_shield:
Expand Down Expand Up @@ -557,6 +557,15 @@ int Game_Battler::GetAgi() const {
return n;
}

int Game_Battler::GetDisplayX() const {
int shake_pos = Main_Data::game_data.screen.shake_position;
return GetBattleX() + shake_pos;
}

int Game_Battler::GetDisplayY() const {
return GetBattleY();
}

int Game_Battler::GetHue() const {
return 0;
}
Expand Down
31 changes: 22 additions & 9 deletions src/game_battler.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Game_Battler {

/**
* Apply effects of Conditions to Battler
*
*
* @return Damage taken to Battler from conditions
*/
int ApplyConditions();
Expand Down Expand Up @@ -93,7 +93,7 @@ class Game_Battler {
/**
* Tests if the battler has a "No Action" condition like sleep.
*
* @return can act
* @return can act
*/
bool CanAct();

Expand Down Expand Up @@ -138,7 +138,7 @@ class Game_Battler {

/**
* Gets probability that a state can be inflicted on this actor.
*
*
* @param state_id State to test
* @return Probability of state infliction
*/
Expand Down Expand Up @@ -410,21 +410,34 @@ class Game_Battler {
* @return Reflect is enabled.
*/
bool HasReflectState() const;

/**
* Gets X position on battlefield
* Gets X position against the battle background.
*
* @return X position in battle scene
*/
virtual int GetBattleX() const = 0;

/**
* Gets Y position on battlefield
* Gets Y position against the battle background.
*
* @return Y position in battle scene
*/
virtual int GetBattleY() const = 0;

/**
* Gets X position on the screen.
*
* This is equal to GetBattleX, plus a displacement for
* any screen shaking.
*/
int GetDisplayX() const;

/**
* Gets Y position on the screen.
*/
int GetDisplayY() const;

virtual int GetHue() const;

virtual int GetBattleAnimationId() const = 0;
Expand All @@ -449,7 +462,7 @@ class Game_Battler {
* @return If battler is defending (next turn, defense is doubled)
*/
bool IsDefending() const;

/**
* @return If battler has strong defense (defense is tripled when defending)
*/
Expand Down Expand Up @@ -480,7 +493,7 @@ class Game_Battler {
* Convenience function to access the party based on the type of this
* battler. This function does not ensure that the battler is in the
* party.
* @return Party this member probably belongs to.
* @return Party this member probably belongs to.
*/
Game_Party_Base& GetParty() const;

Expand Down Expand Up @@ -538,7 +551,7 @@ class Game_Battler {
*/
void SetBattleAlgorithm(const BattleAlgorithmRef battle_algorithm);

/**
/**
* @return Current turn in battle
*/
int GetBattleTurn() const;
Expand Down
8 changes: 6 additions & 2 deletions src/sprite_battler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ void Sprite_Battler::Update() {
}
}
}

SetX(battler->GetDisplayX());
SetY(battler->GetDisplayY());
SetZ(battler->GetBattleY());
}

void Sprite_Battler::SetAnimationState(int state, LoopState loop) {
Expand Down Expand Up @@ -263,8 +267,8 @@ void Sprite_Battler::CreateSprite() {
sprite_name = battler->GetSpriteName();
hue = battler->GetHue();

SetX(battler->GetBattleX());
SetY(battler->GetBattleY());
SetX(battler->GetDisplayX());
SetY(battler->GetDisplayY());
SetZ(battler->GetBattleY()); // Not a typo

// Not animated -> Monster
Expand Down

0 comments on commit 891631f

Please sign in to comment.