Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 2, 2014
1 parent 874f7d7 commit bcc182c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
17 changes: 1 addition & 16 deletions src/entity/mob/ai/chase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,8 @@ void Chase::Update(double delta) {
direction_ = (dying)?((diffX>0)?Dir::RIGHT:Dir::LEFT):((diffX>0)?Dir::LEFT:Dir::RIGHT);
else if (!dying && diffXaux < mob_->width())
direction_ = (dying)?((diffX>0)?Dir::LEFT:Dir::RIGHT):((diffY>0)?Dir::UP:Dir::DOWN);
/*if (diffYaux < mob_->height())
direction_ = (diffX>0)?Dir::LEFT:Dir::RIGHT;
else if (diffXaux < mob_->width())
direction_ = (diffY>0)?Dir::UP:Dir::DOWN;*/
--current_duration_;
}
else{
std::cout << "hola" << std::endl;
} else {
if (diffYaux < mob_->height())
direction_ = (dying)?((diffX>0)?Dir::RIGHT:Dir::LEFT):((diffX>0)?Dir::LEFT:Dir::RIGHT);
else if (diffXaux < mob_->width())
Expand All @@ -97,15 +91,6 @@ void Chase::Update(double delta) {
direction_ = (dying)?((diffY>0)?Dir::DOWN:Dir::UP):((diffY>0)?Dir::UP:Dir::DOWN);
else
direction_ = (dying)?((diffX>0)?Dir::RIGHT:Dir::LEFT):((diffX>0)?Dir::LEFT:Dir::RIGHT);
/*if (diffYaux < mob_->height())
direction_ = (diffX>0)?Dir::LEFT:Dir::RIGHT;
else if (diffXaux < mob_->width())
direction_ = (diffY>0)?Dir::UP:Dir::DOWN;
else if (diffYaux > diffXaux/3.0f)
direction_ = (diffY>0)?Dir::UP:Dir::DOWN;
else
direction_ = (diffX>0)?Dir::LEFT:Dir::RIGHT;*/

current_duration_ = period_duration_;
}

Expand Down
18 changes: 18 additions & 0 deletions src/entity/mob/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
#include "action/attack.hpp"
#include "../../audio/sound.hpp"
#include "../../graphic/effect/blink.hpp"
#include "../../map/level.hpp"
#include "../../graphic/effect/fade.hpp"
#include "../../audio/music.hpp"
#include "../../game.hpp"

SpriteSheet* Link::MOVE_SPRITE_SHEET;
std::vector<SpriteSet*> Link::MOVE_ANIMATIONS;
SpriteSheet* Link::ATTACK_SPRITE_SHEET;
std::vector<SpriteSet*> Link::ATTACK_ANIMATIONS;
sf::SoundBuffer* Link::ATTACK_SOUND;
sf::SoundBuffer* Link::HURT_SOUND;
sf::SoundBuffer* Link::DIE_SOUND;

void Link::Load() {
MOVE_SPRITE_SHEET = new SpriteSheet("charset/link/move_shield.png", 147, 108, 21, 27);
Expand Down Expand Up @@ -37,6 +42,7 @@ void Link::Load() {

ATTACK_SOUND = Sound::Buffer("link/sword1.wav");
HURT_SOUND = Sound::Buffer("link/hurt.wav");
DIE_SOUND = Sound::Buffer("link/dies.wav");
}

Link::Link() :
Expand All @@ -49,6 +55,7 @@ Link::Link() :
type_ = PLAYER;
attack_sound_ = ATTACK_SOUND;
hurt_sound_ = HURT_SOUND;
die_sound_ = DIE_SOUND;

AddAction("attack", new Attack(this, ATTACK_ANIMATIONS));
}
Expand All @@ -75,6 +82,7 @@ int Link::boss_keys() const {
bool Link::CollidesWith(Rectangle const * rectangle) const {
return super::CollidesWith(rectangle) and (
(not rectangle->IsEntity()) or
((Entity*)rectangle)->type() != ENEMY or
is_vulnerable_ and (
((Entity*)rectangle)->type() != BOSS or
rectangle->CollidesWith(this)
Expand Down Expand Up @@ -136,3 +144,13 @@ void Link::Damage(Entity* from, int amount) {
}));
}
}

void Link::Die() {
super::Die();

Music::ClearQueue();
Music::FadeOut(1);
level_->ChangeEffect(new Fade(Fade::OUT, 1, [this]{
Game::INSTANCE.Over(level_->name());
}));
}
3 changes: 3 additions & 0 deletions src/entity/mob/link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Link : public Mob {

static sf::SoundBuffer* ATTACK_SOUND;
static sf::SoundBuffer* HURT_SOUND;
static sf::SoundBuffer* DIE_SOUND;

static void Load();

Expand All @@ -40,6 +41,8 @@ class Link : public Mob {

bool CanCollideWith(Rectangle *rectangle) const;

void Die();


private:
std::map<std::string, bool> keys_;
Expand Down
4 changes: 4 additions & 0 deletions src/map/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,7 @@ Entity* Level::main_player() const {
void Level::RemoveCollidable(Rectangle* rectangle) {
dynamic_collidables_->Remove(rectangle);
}

std::string Level::name() const {
return name_;
}
1 change: 1 addition & 0 deletions src/map/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Level : public TileMap {
Level(const char* map, Hud* hud);
~Level();

std::string name() const;
Path* FindPath(Mob* from, Entity* to);
const std::vector<Entity*>& players() const;
Entity* main_player() const;
Expand Down

0 comments on commit bcc182c

Please sign in to comment.