diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2006-03-05 22:33:09 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2006-03-05 22:33:09 +0000 |
commit | 5f9bbd205fec7d66643861a5204c6cc7dec639ba (patch) | |
tree | ad21b3432c3cafb10a9e4a7d32b600cebe74d92c /src | |
parent | a74208583e806fcfdc485428fb4f9e694e962455 (diff) | |
download | mana-5f9bbd205fec7d66643861a5204c6cc7dec639ba.tar.gz mana-5f9bbd205fec7d66643861a5204c6cc7dec639ba.tar.bz2 mana-5f9bbd205fec7d66643861a5204c6cc7dec639ba.tar.xz mana-5f9bbd205fec7d66643861a5204c6cc7dec639ba.zip |
Merged new_playerset branch into trunk.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 2 | ||||
-rw-r--r-- | src/being.h | 18 | ||||
-rw-r--r-- | src/engine.cpp | 27 | ||||
-rw-r--r-- | src/gui/playerbox.cpp | 11 | ||||
-rw-r--r-- | src/localplayer.cpp | 13 | ||||
-rw-r--r-- | src/main.cpp | 33 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 9 | ||||
-rw-r--r-- | src/player.cpp | 95 | ||||
-rw-r--r-- | src/resources/image.cpp | 4 |
9 files changed, 144 insertions, 68 deletions
diff --git a/src/being.cpp b/src/being.cpp index 880263af..fa28a61b 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -188,7 +188,7 @@ Being::logic() showSpeech = false; } - // Determine whether damange should still be displayed + // Determine whether damage should still be displayed if (get_elapsed_time(damage_time) > 3000) { showDamage = false; diff --git a/src/being.h b/src/being.h index 6f8e578c..a3884056 100644 --- a/src/being.h +++ b/src/being.h @@ -31,7 +31,7 @@ #include "sprite.h" #include "map.h" -#define NR_HAIR_STYLES 5 +#define NR_HAIR_STYLES 6 #define NR_HAIR_COLORS 10 class Map; @@ -63,14 +63,14 @@ class Being : public Sprite }; enum Action { - STAND = 0, - WALK = 1, - ATTACK = 5, - BOW_ATTACK = 9, - MONSTER_DEAD = 9, - SIT = 13, - HIT = 14, - DEAD = 15 + STAND = 0, + WALK = 1, + MONSTER_ATTACK = 5, + SIT = 7, + DEAD = 8, + ATTACK = 9, + MONSTER_DEAD = 9, + HIT = 17 }; /** diff --git a/src/engine.cpp b/src/engine.cpp index 9ee9c09c..2de3c282 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -31,6 +31,7 @@ #include "flooritemmanager.h" #include "game.h" #include "graphics.h" +#include "main.h" #include "localplayer.h" #include "log.h" #include "main.h" @@ -61,7 +62,7 @@ ItemManager *itemDb; /**< Item database object */ Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; -Spriteset *weaponset; +std::vector<Spriteset *> weaponset; Engine::Engine(Network *network): @@ -75,13 +76,24 @@ Engine::Engine(Network *network): npcset = resman->createSpriteset("graphics/sprites/npcs.png", 50, 80); emotionset = resman->createSpriteset("graphics/sprites/emotions.png", 30, 32); - weaponset = resman->createSpriteset("graphics/sprites/weapons.png", - 160, 120); + for (int i = 0; i < 2; i++) + { + std::stringstream filename; + filename << "graphics/sprites/weapon" << i << ".png"; + printf("hairstyle: %s\n", filename.str().c_str()); + Spriteset *tmp = ResourceManager::getInstance()->createSpriteset( + filename.str(), 64, 64); + if (!tmp) { + logger->error("Unable to load weaponset"); + } else { + weaponset.push_back(tmp); + } + } itemset = resman->createSpriteset("graphics/sprites/items.png", 32, 32); if (!npcset) logger->error("Unable to load NPC spriteset!"); if (!emotionset) logger->error("Unable to load emotions spriteset!"); - if (!weaponset) logger->error("Unable to load weapon spriteset!"); + //if (!weaponset) logger->error("Unable to load weapon spriteset!"); if (!itemset) logger->error("Unable to load item spriteset!"); // Initialize item manager @@ -100,7 +112,12 @@ Engine::~Engine() delete npcset; delete emotionset; - delete weaponset; + //delete weaponset; + for (unsigned int i = 0; i < weaponset.size(); i++) + { + delete weaponset[i]; + } + weaponset.clear(); delete itemset; delete itemDb; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index b1414ef8..6423b8c4 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -32,7 +32,8 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -extern Spriteset *hairset, *playerset; +extern std::vector<Spriteset *> hairset; +extern Spriteset *playerset; int PlayerBox::instances = 0; ImageRect PlayerBox::background; @@ -89,16 +90,16 @@ void PlayerBox::draw(gcn::Graphics *graphics) // Draw character dynamic_cast<Graphics*>(graphics)->drawImage( - playerset->spriteset[0], 23, 23); + playerset->spriteset[0], 23, 12); // Draw his hair if (hairColor >= 0 && hairStyle >= 0 && hairColor < NR_HAIR_COLORS && hairStyle < NR_HAIR_STYLES) { - int hf = hairColor + 40 * (hairStyle); - if (hf >= 0 && hf < (int)hairset->spriteset.size()) { + int hf = 9 * hairColor; + if (hf >= 0 && hf < (int)hairset[hairStyle]->spriteset.size()) { dynamic_cast<Graphics*>(graphics)->drawImage( - hairset->spriteset[hf], 37, 5); + hairset[hairStyle]->spriteset[hf], 35, 7); } } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 43cf0069..e10fd3d6 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -54,15 +54,20 @@ void LocalPlayer::logic() { switch (action) { case WALK: - mFrame = (get_elapsed_time(walk_time) * 4) / mWalkSpeed; - if (mFrame >= 4) { + mFrame = (get_elapsed_time(walk_time) * 6) / mWalkSpeed; + if (mFrame >= 6) { nextStep(); } break; case ATTACK: - mFrame = (get_elapsed_time(walk_time) * 4) / aspd; - if (mFrame >= 4) { + int frames = 4; + if (getWeapon() == 2) + { + frames = 5; + } + mFrame = (get_elapsed_time(walk_time) * frames) / aspd; + if (mFrame >= frames) { nextStep(); attack(); } diff --git a/src/main.cpp b/src/main.cpp index af6d21e3..27bd5373 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,9 @@ #include <getopt.h> #include <iostream> #include <physfs.h> +#include <sstream> #include <unistd.h> +#include <vector> #include <SDL_image.h> #include <guichan/actionlistener.hpp> @@ -78,7 +80,8 @@ // Account infos char n_server, n_character; -Spriteset *hairset = NULL, *playerset = NULL; +std::vector<Spriteset *> hairset; +Spriteset *playerset = NULL; Graphics *graphics; // TODO Anyone knows a good location for this? Or a way to make it non-global? @@ -265,11 +268,24 @@ void init_engine() playerset = resman->createSpriteset( "graphics/sprites/player_male_base.png", 64, 64); - hairset = resman->createSpriteset( - "graphics/sprites/player_male_hair.png", 40, 40); - if (!playerset) logger->error("Couldn't load player spriteset!"); - if (!hairset) logger->error("Couldn't load hair spriteset!"); + + for (int i=0; i < NR_HAIR_STYLES; i++) + { + std::stringstream filename; + filename << "graphics/sprites/hairstyle" << (i + 1) << ".png"; + printf("hairstyle: %s\n", filename.str().c_str()); + Spriteset *tmp = ResourceManager::getInstance()->createSpriteset( + filename.str(), 40, 40); + if (!tmp) { + logger->error("Unable to load hairstyle"); + } else { + hairset.push_back(tmp); + } + } + /*hairset = resman->createSpriteset( + "graphics/sprites/player_male_hair.png", 29, 29); + if (!hairset) logger->error("Couldn't load hair spriteset!");*/ gui = new Gui(graphics); state = UPDATE_STATE; /**< Initial game state */ @@ -304,7 +320,12 @@ void exit_engine() config.write(); delete gui; delete graphics; - delete hairset; + //delete hairset; + for (unsigned int i = 0; i < hairset.size(); i++) + { + delete hairset[i]; + } + hairset.clear(); delete playerset; // Shutdown libxml diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 9578f5c1..a01122d1 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -203,7 +203,14 @@ void BeingHandler::handleMessage(MessageIn *msg) srcBeing != player_node) { // buggy - srcBeing->action = Being::ATTACK; + if (srcBeing->getType() == Being::MONSTER) + { + srcBeing->action = Being::MONSTER_ATTACK; + } + else + { + srcBeing->action = Being::ATTACK; + } srcBeing->mFrame = 0; srcBeing->walk_time = tick_time; } diff --git a/src/player.cpp b/src/player.cpp index d6363242..8afd92a8 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -30,28 +30,38 @@ #include "gui/gui.h" -extern Spriteset *hairset; +extern std::vector<Spriteset *> hairset; extern Spriteset *playerset; -extern Spriteset *weaponset; +extern std::vector<Spriteset *> weaponset; -signed char hairtable[16][4][2] = { +signed char hairtable[19][4][2] = { // S(x,y) W(x,y) N(x,y) E(x,y) - { { 0, 0}, {-1, 2}, {-1, 2}, { 0, 2} }, // STAND - { { 0, 2}, {-2, 3}, {-1, 2}, { 1, 3} }, // WALK 1st frame - { { 0, 3}, {-2, 4}, {-1, 3}, { 1, 4} }, // WALK 2nd frame - { { 0, 1}, {-2, 2}, {-1, 2}, { 1, 2} }, // WALK 3rd frame - { { 0, 2}, {-2, 3}, {-1, 2}, { 1, 3} }, // WALK 4th frame - { { 0, 1}, { 1, 2}, {-1, 3}, {-2, 2} }, // ATTACK 1st frame - { { 0, 1}, {-1, 2}, {-1, 3}, { 0, 2} }, // ATTACK 2nd frame - { { 0, 2}, {-4, 3}, { 0, 4}, { 3, 3} }, // ATTACK 3rd frame - { { 0, 2}, {-4, 3}, { 0, 4}, { 3, 3} }, // ATTACK 4th frame - { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 1st frame - { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 2nd frame - { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 3rd frame - { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 4th frame - { { 0, 4}, {-1, 6}, {-1, 6}, { 0, 6} }, // SIT - { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, // ?? HIT - { { 0, 16}, {-1, 6}, {-1, 6}, { 0, 6} } // DEAD + { {-5, -4}, {-6, -4}, {-6, 0}, {-4, -4} }, // STAND + { {-5, -3}, {-6, -4}, {-6, 0}, {-4, -4} }, // WALK 1st frame + { {-5, -4}, {-6, -3}, {-6, -1}, {-4, -3} }, // WALK 2nd frame + { {-5, -4}, {-6, -4}, {-6, -1}, {-4, -4} }, // WALK 3rd frame + { {-5, -3}, {-6, -4}, {-6, 0}, {-4, -4} }, // WALK 4th frame + { {-5, -4}, {-6, -3}, {-6, -1}, {-4, -3} }, // WALK 5th frame + { {-5, -4}, {-6, -4}, {-6, -1}, {-4, -4} }, // WALK 6th frame + { {-5, 8}, {-1, 5}, {-6, 8}, {-9, 5} }, // SIT + { {16, 21}, {16, 21}, {16, 21}, {16, 21} }, // DEAD + { {-5, -2}, {-2, -5}, {-6, 0}, {-7, -5} }, // ATTACK 1st frame + { {-5, -3}, {-2, -6}, {-6, 0}, {-7, -6} }, // ATTACK 2nd frame + { {-5, 0}, {-6, -3}, {-6, 0}, {-4, -3} }, // ATTACK 3rd frame + { {-5, 1}, {-7, -2}, {-6, 2}, {-3, -2} }, // ATTACK 4th frame + { {-5, -3}, {-3, -4}, {-6, 0}, {-7, -4} }, // BOW_ATTACK 1st frame + { {-5, -3}, {-3, -4}, {-6, 0}, {-7, -4} }, // BOW_ATTACK 2nd frame + { {-5, -3}, {-3, -4}, {-7, 0}, {-7, -4} }, // BOW_ATTACK 3rd frame + { {-5, -2}, {-1, -5}, {-7, 1}, {-9, -5} }, // BOW_ATTACK 4th frame + { {-5, -3}, {-1, -5}, {-7, 0}, {-9, -5} }, // BOW_ATTACK 5th frame + { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} } // ?? HIT +}; + +unsigned char hairframe[4][20] = { + { 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 3, 3, 3, 3, 3, 3, 3, 3, 8, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, + { 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, + { 5, 5, 5, 5, 5, 5, 5, 5, 8, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 } }; Player::Player(Uint32 id, Uint16 job, Map *map): @@ -63,17 +73,26 @@ void Player::logic() { switch (action) { case WALK: - mFrame = (get_elapsed_time(walk_time) * 4) / mWalkSpeed; + mFrame = (get_elapsed_time(walk_time) * 6) / mWalkSpeed; + if (mFrame >= 6) { + nextStep(); + } break; case ATTACK: - mFrame = (get_elapsed_time(walk_time) * 4) / aspd; + int frames = 4; + if (getWeapon() == 2) + { + frames = 5; + } + mFrame = (get_elapsed_time(walk_time) * frames) / aspd; + if (mFrame >= frames) { + nextStep(); + } break; } - if (mFrame >= 4) { - nextStep(); - } + Being::logic(); } @@ -98,31 +117,37 @@ void Player::draw(Graphics *graphics, int offsetX, int offsetY) if (action == ATTACK && getWeapon() > 0) { - frame += 4 * (getWeapon() - 1); + if (getWeapon() == 2) + { + frame += 4; + } } unsigned char dir = 0; while (!(direction & (1 << dir))) dir++; - graphics->drawImage(playerset->spriteset[frame + 16 * dir], + graphics->drawImage(playerset->spriteset[frame + 18 * dir], px - 16, py - 32); if (getWeapon() != 0 && action == ATTACK) { - Image *image = weaponset->spriteset[ - 16 * (getWeapon() - 1) + 4 * mFrame + dir]; - - graphics->drawImage(image, px - 64, py - 80); + int frames = 4; + if (getWeapon() == 2) + { + frames = 5; + } + Image *image = weaponset[getWeapon() - 1]->spriteset[ + mFrame + frames * dir]; + graphics->drawImage(image, px - 16, py - 32); } if (getHairColor() <= NR_HAIR_COLORS) { - int hf = getHairColor() - 1 + 10 * (dir + 4 * - (getHairStyle() - 1)); + int hf = 9 * (getHairColor() - 1) + hairframe[dir][frame]; - graphics->drawImage(hairset->spriteset[hf], - px - 2 + 2 * hairtable[frame][dir][0], - py - 50 + 2 * hairtable[frame][dir][1]); + graphics->drawImage(hairset[getHairStyle() - 1]->spriteset[hf], + px + 1 + hairtable[frame][dir][0], + py - 33 + hairtable[frame][dir][1]); } } diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 52b6f447..3b860c01 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -157,11 +157,11 @@ Image* Image::load(void *buffer, unsigned int bufferSize, int height = tmpImage->h; int realWidth = 1, realHeight = 1; - while (realWidth < width && realWidth < 1024) { + while (realWidth < width && realWidth < 2048) { realWidth *= 2; } - while (realHeight < height && realHeight < 1024) { + while (realHeight < height && realHeight < 2048) { realHeight *= 2; } |