Skip to content

Commit

Permalink
Fixing map and collisions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 2, 2014
1 parent e5bc476 commit 14443f9
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 73 deletions.
144 changes: 72 additions & 72 deletions res/level/overworld.tmx

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/entity/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void Mob::MeleeAttack(Hitbox* hitbox) {
level_->DynamicCollidablesFor(hitbox, candidates);

for(Rectangle* candidate : candidates) {
if(candidate->CanCollideWith(this) && hitbox->CollidesWith(candidate)) {
if(candidate->CanCollideWith(this) and candidate->CanReceiveDamageFrom(this) and hitbox->CollidesWith(candidate)) {
if(candidate->IsEntity() && ((Entity*) candidate)->IsVulnerable()) {
Collision c = hitbox->CollisionType(candidate);

Expand Down Expand Up @@ -308,3 +308,7 @@ sf::SoundBuffer* Mob::attack_sound() const {
float Mob::speed() const {
return speed_;
}

bool Mob::CanCollideWith(Rectangle* rectangle) const {
return not rectangle->IsEntity() or ((Entity*)rectangle)->type() != type_;
}
1 change: 1 addition & 0 deletions src/entity/mob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Mob : public Entity {
Entity* SeekEnemy() const ;
Path* FindPath(Entity* to);
bool FollowPath(Path* path, double delta);
bool CanCollideWith(Rectangle* rectangle) const;
float speed() const;

sf::SoundBuffer* attack_sound() const;
Expand Down
4 changes: 4 additions & 0 deletions src/entity/object/plant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ Plant::Plant(Sprite* sprite, float x, float y) :
type_ = PLANT;
die_sound_ = CUT_SOUND;
}

bool Plant::CanReceiveDamageFrom(Rectangle const* rectangle) const {
return rectangle->IsEntity() and ((Entity*) rectangle)->type() == PLAYER;
}
2 changes: 2 additions & 0 deletions src/entity/object/plant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ class Plant : public Object {
static void Load();

Plant(Sprite* sprite, float x, float y);

bool CanReceiveDamageFrom(Rectangle const * rectangle) const;
};
4 changes: 4 additions & 0 deletions src/math/rectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ void Rectangle::Update(double delta) {
float Rectangle::Distance(const Rectangle* rectangle) const {
return center().dist(rectangle->center());
}

bool Rectangle::CanReceiveDamageFrom(Rectangle const* rectangle) const {
return true;
}
1 change: 1 addition & 0 deletions src/math/rectangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Rectangle : public Drawable {

virtual bool CanCollideWith(Rectangle* rectangle) const;
virtual bool CollidesWith(Rectangle const * rectangle) const;
virtual bool CanReceiveDamageFrom(Rectangle const * rectangle) const;
virtual bool HandleCollisionWith(Mob* mob);
virtual Collision CollisionType(Rectangle* rectangle) const;

Expand Down

0 comments on commit 14443f9

Please sign in to comment.