diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-11 08:08:21 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-11 08:08:21 +0000 |
commit | 222f8a034707e8f57dc0e4795462af610a911d75 (patch) | |
tree | b3d326477ff6da6718110c0becafb51bd8c0430f /src | |
parent | ac6ed9c03198156e7ebeefc18f2ba04073d5acb8 (diff) | |
download | mana-222f8a034707e8f57dc0e4795462af610a911d75.tar.gz mana-222f8a034707e8f57dc0e4795462af610a911d75.tar.bz2 mana-222f8a034707e8f57dc0e4795462af610a911d75.tar.xz mana-222f8a034707e8f57dc0e4795462af610a911d75.zip |
Now damage and speech times are fps independent
and if they're displayed is checked in logic
I also centered the speech above the player
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 32 | ||||
-rw-r--r-- | src/being.h | 13 | ||||
-rw-r--r-- | src/engine.cpp | 8 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/game.h | 2 |
5 files changed, 22 insertions, 35 deletions
diff --git a/src/being.cpp b/src/being.cpp index c4ca63b6..d2bf85d5 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -122,7 +122,7 @@ void sort() { Being::Being(): speech_time(0), - damage(""), damage_time(0), damage_y(0.0), + damage(""), damage_time(0), id(0), job(0), x(0), y(0), destX(0), destY(0), direction(0), type(0), action(0), frame(0), @@ -132,7 +132,8 @@ Being::Being(): emotion(0), emotion_time(0), text_x(0), text_y(0), hair_style(1), hair_color(1), - weapon(0) + weapon(0), + showSpeech(false), showDamage(false) { strcpy(name, ""); } @@ -165,14 +166,15 @@ void Being::setHairStyle(int style) void Being::setSpeech(const std::string &text, int time) { speech = text; - speech_time = time; + speech_time = tick_time; + showSpeech = true; } void Being::setDamage(const std::string &text, int time) { damage = text; - damage_time = time; - damage_y = 0; + damage_time = tick_time; + showDamage = true; } void Being::setName(char *text) @@ -224,7 +226,7 @@ void Being::nextStep() void Being::drawSpeech(Graphics *graphics) { // Draw speech above this being - if (speech_time > 0) { + if (showSpeech) { //if (being->speech_color == makecol(255, 255, 255)) { // guiGraphics->drawText(being->speech, // being->text_x + 16, being->text_y - 60, @@ -232,24 +234,14 @@ void Being::drawSpeech(Graphics *graphics) //} //else { graphics->drawText(speech, - text_x + 60, text_y - 60, + text_x + 20, text_y - 60, gcn::Graphics::CENTER); //} } - if (damage_time > 0.0) { + if (showDamage) { graphics->drawText(damage, - text_x + 60, text_y - 60 - (int)damage_y, + text_x + 60, + text_y - 60 - get_elapsed_time(damage_time) / 100, gcn::Graphics::CENTER); - damage_y += 0.5; - } -} - -void Being::tick() -{ - if (speech_time > 0) { - speech_time--; - } - if (damage_time > 0) { - damage_time--; } } diff --git a/src/being.h b/src/being.h index 16cedb3b..6748732e 100644 --- a/src/being.h +++ b/src/being.h @@ -41,10 +41,7 @@ class Being { private: std::list<PATH_NODE> path; std::string speech; - unsigned char speech_time; std::string damage; - unsigned char damage_time; - float damage_y; // y coord of damage text public: unsigned int id; @@ -64,6 +61,9 @@ class Being { unsigned short hair_style, hair_color; unsigned short weapon; char name[24]; + unsigned int speech_time; + unsigned int damage_time; + bool showSpeech, showDamage; /** * Constructor. @@ -129,13 +129,6 @@ class Being { * Draws the speech text above the being. */ void drawSpeech(Graphics *graphics); - - /** - * Tick gives the being a sense of time. It should be called either a - * specific amount of times per second, or be modified to be passed a - * number that tells it the time since the last call. - */ - void tick(); }; /** Add a Being to the list */ diff --git a/src/engine.cpp b/src/engine.cpp index 563247df..940bac79 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -275,6 +275,11 @@ void Engine::logic() } } } + + if (get_elapsed_time(being->speech_time) > 5000) + being->showSpeech = false; + if (get_elapsed_time(being->damage_time) > 3000) + being->showDamage = false; if (being->action == MONSTER_DEAD && being->frame >= 20) { delete being; @@ -471,9 +476,6 @@ void Engine::draw() while (beingIterator != beings.end()) { Being *being = (*beingIterator); - // Tick the beings (gives them a sense of time) - being->tick(); - being->drawSpeech(guiGraphics); beingIterator++; diff --git a/src/game.cpp b/src/game.cpp index 8ce8f547..fdd8899e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -97,7 +97,7 @@ Uint32 second(Uint32 interval, void *param) return interval; } -short get_elapsed_time(short start_time) +int get_elapsed_time(int start_time) { if (start_time <= tick_time) { return (tick_time - start_time) * 10; @@ -98,6 +98,6 @@ int get_packet_length(short); * Returns elapsed time. (Warning: very unsafe function, it supposes the delay * is always < 10 seconds) */ -short get_elapsed_time(short start_time); +int get_elapsed_time(int start_time); #endif |