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

Albeleon's Battle Fixes 7 of 7 #1452

Merged
merged 2 commits into from Dec 13, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/game_battlealgorithm.cpp
Expand Up @@ -1781,7 +1781,7 @@ std::string Game_BattleAlgorithm::SelfDestruct::GetStartMessage() const {
}

int Game_BattleAlgorithm::SelfDestruct::GetSourceAnimationState() const {
return Sprite_Battler::AnimationState_Dead;
return Sprite_Battler::AnimationState_SelfDestruct;
}

const RPG::Sound* Game_BattleAlgorithm::SelfDestruct::GetStartSe() const {
Expand Down
4 changes: 4 additions & 0 deletions src/game_enemy.cpp
Expand Up @@ -338,3 +338,7 @@ const RPG::EnemyAction* Game_Enemy::ChooseRandomAction() {

return nullptr;
}

bool Game_Enemy::IsTransparent() const {
return enemy->transparent;
fmatthew5876 marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions src/game_enemy.h
Expand Up @@ -169,6 +169,8 @@ class Game_Enemy : public Game_Battler

void UpdateBattle() override;

bool IsTransparent() const;

/**
* Get's the ID of the item the enemy drops when defeated.
*
Expand Down
19 changes: 16 additions & 3 deletions src/scene_battle_rpg2k.cpp
Expand Up @@ -435,9 +435,6 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase
source_sprite = Game_Battle::GetSpriteset().FindBattler(action->GetSource());
if (source_sprite) {
source_sprite->Flash(Color(255, 255, 255, 100), 15);
source_sprite->SetAnimationState(
action->GetSourceAnimationState(),
Sprite_Battler::LoopState_DefaultAnimationAfterFinish);
}

auto* src = action->GetSource();
Expand Down Expand Up @@ -542,6 +539,22 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase
action->Apply();
battle_action_state = BattleActionState_ResultPop;

if (action->GetSource()->GetType() == Game_Battler::Type_Enemy) {
if (action->GetType() == Game_BattleAlgorithm::Type::Escape) {
source_sprite = Game_Battle::GetSpriteset().FindBattler(action->GetSource());
source_sprite->SetAnimationState(
Sprite_Battler::AnimationState_Dead,
Sprite_Battler::LoopState_DefaultAnimationAfterFinish);
}

if (action->GetType() == Game_BattleAlgorithm::Type::SelfDestruct) {
source_sprite = Game_Battle::GetSpriteset().FindBattler(action->GetSource());
source_sprite->SetAnimationState(
Sprite_Battler::AnimationState_SelfDestruct,
Sprite_Battler::LoopState_DefaultAnimationAfterFinish);
}
}

if (!action->IsFirstAttack()) {
battle_action_wait = 0;
return ProcessBattleAction(action);
Expand Down
36 changes: 30 additions & 6 deletions src/sprite_battler.cpp
Expand Up @@ -17,6 +17,7 @@

// Headers
#include "battle_animation.h"
#include "game_enemy.h"
#include "sprite_battler.h"
#include "bitmap.h"
#include "cache.h"
Expand Down Expand Up @@ -49,7 +50,9 @@ void Sprite_Battler::Update() {
}

if (!battler->IsHidden() && old_hidden != battler->IsHidden()) {
SetOpacity(255);
SetZoomX(1.0);
SetZoomY(1.0);
SetOpacity(GetMaxOpacity());
SetVisible(true);
DoIdleAnimation();
}
Expand All @@ -62,25 +65,39 @@ void Sprite_Battler::Update() {

if (battler->GetBattleAnimationId() <= 0) {
// Animations for monster
if (anim_state != AnimationState_Dead) {
fade_out = 255;
if (anim_state != AnimationState_Dead && anim_state != AnimationState_SelfDestruct) {
fade_out = GetMaxOpacity();
fade_out_incr = GetMaxOpacity() * (Player::IsRPG2k() ? 6 : 15) / 255;
zoom = 1.0;
}

if (anim_state == AnimationState_Idle) {
SetOpacity(255);
SetOpacity(GetMaxOpacity());
idling = true;
}
else if (anim_state == AnimationState_Dead) {
if (fade_out > 0) {
fade_out -= 15;
fade_out -= fade_out_incr;
SetOpacity(std::max(0, fade_out));
} else {
idling = true;
}
}
else if (anim_state == AnimationState_SelfDestruct) {
if (fade_out > 0) {
fade_out -= fade_out_incr;
zoom += 0.07;
SetOpacity(std::max(0, fade_out));
SetZoomX(zoom);
SetZoomY(zoom);
}
else {
idling = true;
}
}
else if (anim_state == AnimationState_Damage) {
flash_counter = (flash_counter + 1) % 10;
SetOpacity(flash_counter > 5 ? 50 : 255);
SetOpacity(flash_counter > 5 ? 50 : GetMaxOpacity());
if (cycle == 30) {
DoIdleAnimation();
cycle = 0;
Expand Down Expand Up @@ -363,3 +380,10 @@ void Sprite_Battler::OnBattlercharsetReady(FileRequestResult* result, int32_t ba
SetBitmap(Cache::Battlecharset(result->file));
SetSrcRect(Rect(0, battler_index * 48, 48, 48));
}

int Sprite_Battler::GetMaxOpacity() const {
if (battler->GetType() == Game_Battler::Type_Enemy) {
return static_cast<Game_Enemy*>(battler)->IsTransparent()? 255 - 96 : 255;
}
return 255;
}
9 changes: 7 additions & 2 deletions src/sprite_battler.h
Expand Up @@ -31,7 +31,8 @@ class BattleAnimation;
class Sprite_Battler : public Sprite {
public:
enum AnimationState {
AnimationState_Idle = 1,
AnimationState_Null,
AnimationState_Idle,
AnimationState_RightHand,
AnimationState_LeftHand,
AnimationState_SkillUse,
Expand All @@ -42,7 +43,8 @@ class Sprite_Battler : public Sprite {
AnimationState_WalkingLeft,
AnimationState_WalkingRight,
AnimationState_Victory,
AnimationState_Item
AnimationState_Item,
AnimationState_SelfDestruct = 255
};

enum LoopState {
Expand Down Expand Up @@ -99,6 +101,7 @@ class Sprite_Battler : public Sprite {
void DoIdleAnimation();
void OnMonsterSpriteReady(FileRequestResult* result);
void OnBattlercharsetReady(FileRequestResult* result, int32_t battler_index);
int GetMaxOpacity() const;

std::string sprite_name;
int hue = 0;
Expand All @@ -109,12 +112,14 @@ class Sprite_Battler : public Sprite {
std::string sprite_file;
int sprite_frame = -1;
int fade_out = 255;
int fade_out_incr = 15;
int flash_counter = 0;
LoopState loop_state = LoopState_DefaultAnimationAfterFinish;
bool old_hidden = false;
std::unique_ptr<BattleAnimation> animation;
// false when a newly set animation didn't loop once
bool idling = true;
float zoom = 1.0;

FileRequestBinding request_id;
};
Expand Down