Skip to content

Commit

Permalink
Keys implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 2, 2014
1 parent f8f9b93 commit 8b35de4
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ set(SOURCE_FILES
## Items
src/entity/item.cpp
src/entity/item/rupee.cpp
src/entity/item/key.cpp

## Events
src/entity/event.cpp
Expand Down
Binary file added res/item/keys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/entity/item/key.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "key.hpp"
#include "../mob.hpp"
#include "../mob/link.hpp"
#include "../../graphic/effect/bounce.hpp"
#include "../../audio/sound.hpp"

SpriteSheet* Key::SPRITESHEET;
std::vector<Sprite*> Key::KEYS;
sf::SoundBuffer* Key::GET_SOUND;

void Key::Load() {
SPRITESHEET = new SpriteSheet("item/keys.png", 32, 16, 16, 16);
KEYS = SPRITESHEET->GetSprites(0, 3);
GET_SOUND = Sound::Buffer("rupee/get.wav");
}

Key::Key(Key::Type type, float x, float y) :
super(KEYS[type], x, y, vec2f(0, -10)),
key_type_(type)
{
die_sound_ = GET_SOUND;
ChangeEffect(new Bounce(12, 0.25));
}

bool Key::HandleCollisionWith(Mob* mob) {
if(not IsAlive())
return false;

if(key_type_ == SMALL) {
((Link*)mob)->UpdateSmallKeys(1);
} else {
((Link*)mob)->UpdateBossKeys(1);
}

Kill();
return false;
}
25 changes: 25 additions & 0 deletions src/entity/item/key.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "../item.hpp"
#include "../../graphic/spritesheet.hpp"

class Key : public Item {
public:
typedef Item super;
enum Type {
BOSS, SMALL
};

static SpriteSheet* SPRITESHEET;
static std::vector<Sprite*> KEYS;
static sf::SoundBuffer* GET_SOUND;

static void Load();

Key(Key::Type type, float x, float y);

bool HandleCollisionWith(Mob* mob);

private:
Key::Type key_type_;
};
16 changes: 16 additions & 0 deletions src/entity/mob/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ int Link::rupees() const {
return rupees_;
}

int Link::small_keys() const {
return small_keys_;
}

int Link::boss_keys() const {
return boss_keys_;
}

bool Link::CollidesWith(Rectangle const * rectangle) const {
return super::CollidesWith(rectangle) and (
not rectangle->IsEntity() or
Expand All @@ -85,3 +93,11 @@ bool Link::HandleCollisionWith(Mob* mob) {
break;
}
}

void Link::UpdateSmallKeys(int keys) {
small_keys_ += keys;
}

void Link::UpdateBossKeys(int keys) {
boss_keys_ += keys;
}
6 changes: 6 additions & 0 deletions src/entity/mob/link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ class Link : public Mob {
Link();

int rupees() const;
int small_keys() const;
int boss_keys() const;

void UpdateRupees(int rupees);
void UpdateSmallKeys(int keys);
void UpdateBossKeys(int keys);

bool CollidesWith(Rectangle const * rectangle) const;
bool HandleCollisionWith(Mob* mob);

private:
int rupees_;
int small_keys_;
int boss_keys_;
};
5 changes: 2 additions & 3 deletions src/map/events/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ namespace IntroPrivate {
};

void start(Level* level) {
level->Transition("bigger","start");
/*level->ChangeEffect(new Dialog(messages, [level]{
level->ChangeEffect(new Dialog(messages, [level]{
level->Transition("bigger", "start");
}));*/
}));
}
};

Expand Down

0 comments on commit 8b35de4

Please sign in to comment.