summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-05 14:57:35 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-05 14:57:35 +0000
commitde61b658590630cfc59960c012c8e533b361a8b0 (patch)
treeb89a6f23a385ea4a7d32e3abc6ce4a82114c5d67 /src/engine.cpp
parentdbca3013575b766a681d1cea946e249a386e2144 (diff)
parent482f0ddb85487bd5a4beaf2706cca9f690aa9304 (diff)
downloadmana-client-de61b658590630cfc59960c012c8e533b361a8b0.tar.gz
mana-client-de61b658590630cfc59960c012c8e533b361a8b0.tar.bz2
mana-client-de61b658590630cfc59960c012c8e533b361a8b0.tar.xz
mana-client-de61b658590630cfc59960c012c8e533b361a8b0.zip
Moved 0.1.0 branch to trunk. A new beginning.
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp81
1 files changed, 36 insertions, 45 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 868454d4..231313c4 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -34,16 +34,12 @@
#include "main.h"
#include "localplayer.h"
#include "log.h"
-#include "main.h"
#include "map.h"
#include "sound.h"
#include "gui/gui.h"
#include "gui/minimap.h"
-#include "net/messageout.h"
-#include "net/protocol.h"
-
#include "resources/itemmanager.h"
#include "resources/mapreader.h"
#include "resources/resourcemanager.h"
@@ -63,10 +59,9 @@ Spriteset *emotionset;
Spriteset *npcset;
std::vector<Spriteset *> weaponset;
-Engine::Engine(Network *network):
+Engine::Engine():
mShowDebugPath(false),
- mCurrentMap(NULL),
- mNetwork(network)
+ mCurrentMap(NULL)
{
// Load the sprite sets
ResourceManager *resman = ResourceManager::getInstance();
@@ -113,7 +108,7 @@ void Engine::changeMap(const std::string &mapPath)
beingManager->clear();
// Store full map path in global var
- map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz";
+ map_path = "maps/" + mapPath;
// Attempt to load the new map
Map *newMap = MapReader::readMap(map_path);
@@ -147,10 +142,6 @@ void Engine::changeMap(const std::string &mapPath)
}
mCurrentMap = newMap;
-
- // Send "map loaded"
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_MAP_LOADED);
}
void Engine::logic()
@@ -161,20 +152,12 @@ void Engine::logic()
void Engine::draw(Graphics *graphics)
{
+ int midTileX = graphics->getWidth() / 2;
+ int midTileY = graphics->getHeight() / 2;
static int lastTick = tick_time;
- // Avoid freaking out when tick_time overflows
- if (tick_time < lastTick)
- {
- lastTick = tick_time;
- }
-
- // calculate viewpoint
- int midTileX = graphics->getWidth() / 32 / 2;
- int midTileY = graphics->getHeight() / 32 / 2;
-
- int player_x = (player_node->mX - midTileX) * 32 + player_node->getXOffset();
- int player_y = (player_node->mY - midTileY) * 32 + player_node->getYOffset();
+ int player_x = player_node->mX - midTileX + player_node->getXOffset();
+ int player_y = player_node->mY - midTileY + player_node->getYOffset();
scrollLaziness = (int)config.getValue("ScrollLaziness", 32);
scrollRadius = (int)config.getValue("ScrollRadius", 32);
@@ -183,7 +166,9 @@ void Engine::draw(Graphics *graphics)
scrollLaziness = 1; //avoids division by zero
//apply lazy scrolling
- while (lastTick < tick_time)
+ int nbTicks = get_elapsed_time(lastTick) / 10;
+ lastTick += nbTicks;
+ for (; nbTicks > 0; --nbTicks)
{
if (player_x > view_x + scrollRadius)
{
@@ -201,7 +186,6 @@ void Engine::draw(Graphics *graphics)
{
view_y += (player_y - view_y + scrollRadius) / scrollLaziness;
}
- lastTick++;
}
//auto center when player is off screen
@@ -222,29 +206,36 @@ void Engine::draw(Graphics *graphics)
if (view_y < 0) {
view_y = 0;
}
- if (view_x > (mCurrentMap->getWidth() - midTileX) * 32) {
- view_x = (mCurrentMap->getWidth() - midTileX) * 32;
+ if (view_x > mCurrentMap->getWidth() * 32 - midTileX) {
+ view_x = mCurrentMap->getWidth() * 32 - midTileX;
}
- if (view_y > (mCurrentMap->getHeight() - midTileY) * 32) {
- view_y = (mCurrentMap->getHeight() - midTileY) * 32;
+ if (view_y > mCurrentMap->getHeight() * 32 - midTileY) {
+ view_y = mCurrentMap->getHeight() * 32 - midTileY;
}
}
- camera_x = int(view_x + 16) / 32;
- camera_y = int(view_y + 16) / 32;
+ camera_x = (int)view_x;
+ camera_y = (int)view_y;
// Draw tiles and sprites
if (mCurrentMap != NULL)
{
- mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 0);
- mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 1);
- mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 2);
+ mCurrentMap->draw(graphics, camera_x, camera_y, 0);
+ mCurrentMap->draw(graphics, camera_x, camera_y, 1);
+ mCurrentMap->draw(graphics, camera_x, camera_y, 2);
mCurrentMap->drawOverlay( graphics,
view_x,
view_y,
(int)config.getValue("OverlayDetail", 2)
);
}
+ else
+ {
+ // When no map is loaded, draw a replacement background
+ graphics->setColor(gcn::Color(128, 128, 128));
+ graphics->fillRectangle(gcn::Rectangle(0, 0,
+ graphics->getWidth(), graphics->getHeight()));
+ }
// Find a path from the player to the mouse, and draw it. This is for debug
// purposes.
@@ -254,18 +245,18 @@ void Engine::draw(Graphics *graphics)
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
- int mouseTileX = mouseX / 32 + camera_x;
- int mouseTileY = mouseY / 32 + camera_y;
+ int mouseTileX = (mouseX + camera_x) / 32;
+ int mouseTileY = (mouseY + camera_y) / 32;
Path debugPath = mCurrentMap->findPath(
- player_node->mX, player_node->mY,
+ player_node->mX / 32, player_node->mY / 32,
mouseTileX, mouseTileY);
graphics->setColor(gcn::Color(255, 0, 0));
for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++)
{
- int squareX = i->x * 32 - int(view_x) + 12;
- int squareY = i->y * 32 - int(view_y) + 12;
+ int squareX = i->x * 32 - camera_x + 12;
+ int squareY = i->y * 32 - camera_y + 12;
graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8));
graphics->drawText(
@@ -278,9 +269,9 @@ void Engine::draw(Graphics *graphics)
Beings &beings = beingManager->getAll();
for (BeingIterator i = beings.begin(); i != beings.end(); i++)
{
- (*i)->drawSpeech(graphics, -(int)view_x, -(int)view_y);
- (*i)->drawName(graphics, -(int)view_x, -(int)view_y);
- (*i)->drawEmotion(graphics, -(int)view_x, -(int)view_y);
+ (*i)->drawSpeech(graphics, -camera_x, -camera_y);
+ (*i)->drawName(graphics, -camera_x, -camera_y);
+ (*i)->drawEmotion(graphics, -camera_x, -camera_y);
}
// Draw target marker if needed
@@ -291,8 +282,8 @@ void Engine::draw(Graphics *graphics)
graphics->setColor(gcn::Color(255, 255, 255));
int dy = (target->getType() == Being::PLAYER) ? 90 : 52;
- graphics->drawText("[TARGET]", target->getPixelX() - (int)view_x + 15,
- target->getPixelY() - (int)view_y - dy, gcn::Graphics::CENTER);
+ graphics->drawText("[TARGET]", target->getPixelX() - camera_x + 15,
+ target->getPixelY() - camera_y - dy, gcn::Graphics::CENTER);
}
gui->draw();