RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic Goto page Previous  1, 2, 3 
View previous topic - View next topic  
Author Message
Gardon
Scholar


Joined: 05 Feb 2006
Posts: 157

PostPosted: Wed Feb 15, 2006 11:56 pm    Post subject: [quote]

but it's not scrolling tile by tile, it's not scrolling at all.

If I click the right arrow, it moves to the other end of the map, and the left arrow, to the end of that map. I can only move it in 4 directions, 1 time.
Back to top  
RuneLancer
Mage


Joined: 17 Jun 2005
Posts: 441

PostPosted: Thu Feb 16, 2006 12:17 am    Post subject: [quote]

Have you considered that your implantation isn't correct? I haven't seen your code and I don't want to place the blame on it without knowing anything about it, but the problem seems to be the scrolling, not the rendering, from your description.

His code handles the rendering part and fully supports scrolling if called with the right parameters. Can you post the bit where his function is called? We'll have a look at that and it'll most likely be easier to figure out what's wrong than by taking guesses. ;)
_________________
Endless Saga
An OpenGL RPG in the making. Now with new hosting!

Back to top  
Gardon
Scholar


Joined: 05 Feb 2006
Posts: 157

PostPosted: Thu Feb 16, 2006 12:28 am    Post subject: [quote]

Here's my entire map class. It's called from Engine.cpp
Look at the first draw function, the other is the one I'm experimenting with.

Code:
#include "Map.h"

Map::Map(Graphics* graphics, string bitmap, string textFileName, int screenWidth, int screenHeight,
         int startingX, int startingY, int currentFps, int movementSpeed, int mapWidthTileCount,
            int mapHeightTileCount, int tileSize, int bitmapTilesWide, int bitmapTilesHigh)
{
   m_graphics = graphics; // graphics handler

   m_tileSize = tileSize; // size of the tile

   m_mapWidthTileCount = mapWidthTileCount; // number of tiles the map is Wide
   m_mapHeightTileCount = mapHeightTileCount; // number of tiles the map is high

   m_mapWidth = m_mapWidthTileCount * m_tileSize; // map dimensions in pixels
   m_mapHeight = m_mapHeightTileCount * m_tileSize;

   m_bitmapTilesWide = bitmapTilesWide; // size of the tileset to use (how many tiles it is in each direction)
   m_bitmapTilesHigh = bitmapTilesHigh;

   m_cameraX = startingX; // camera offset
   m_cameraY = startingY;

   m_currentFps = currentFps; // current Frames per secone

   m_mapIndexes = new int[m_mapWidthTileCount * m_mapHeightTileCount]; // the array of tile representation numbers
   m_tiles = new SDL_Rect[m_bitmapTilesWide * m_bitmapTilesHigh]; // the SDL_Rect locations of the tiles within the tileset

   m_bitmap = m_graphics->LoadBitmap(bitmap);

   LoadMap(textFileName);

   m_screenWidth = screenWidth;
   m_screenHeight = screenHeight;
}

Map::~Map()
{
   delete[] m_tiles;
   delete[] m_mapIndexes;

   m_graphics->CloseBitmap(m_bitmap);

   delete m_graphics;
}

void Map::Update(GameState newState, Direction newDirection, int newFps, int playerPosX, int playerPosY)
{
   m_currentFps = newFps;

   m_currentState = newState;
   m_currentDirection = newDirection;

   HandleState();
}

void Map::LoadMap(string textFileName)
{
   fstream in;

   in.open(textFileName.c_str());

   for (int i = 0; i < (m_mapWidthTileCount * m_mapHeightTileCount); i++)
   {
      in >> m_mapIndexes[i];
   }

   in.close();

   int tempCounter = 0;

   for (int i = 0; i < m_bitmapTilesHigh; i++)
   {
      for (int j = 0; j < m_bitmapTilesWide; j++)
      {
         m_tiles[tempCounter].x = (j * m_tileSize);
         m_tiles[tempCounter].y = (i * m_tileSize);
         m_tiles[tempCounter].w = m_tileSize;
         m_tiles[tempCounter].h = m_tileSize;

         tempCounter++;
      }
   }

}

void Map::Draw(int x_offset, int y_offset)
{
  int min_x = max(0, x_offset / m_tileSize);
  int max_x = min(m_mapWidthTileCount,
     (x_offset + m_screenWidth + m_tileSize - 1) / m_tileSize);
  int min_y = max(0, y_offset / m_tileSize);
  int max_y = min(m_mapHeightTileCount,
     (y_offset + m_screenHeight + m_tileSize - 1) / m_tileSize);

  for (int y = min_y; y < max_y; ++y) {
    for (int x = min_x; x < max_x; ++x) {
       int tile = m_mapIndexes[x * m_mapHeightTileCount + y];
       m_source = m_tiles[tile];

       m_destination.x = x * m_tileSize - x_offset;
       m_destination.y = y * m_tileSize - y_offset;
       m_destination.w = m_tileSize;
       m_destination.h = m_tileSize;

       m_graphics->DrawBitmap(m_bitmap, m_source, m_destination);
    }
  }
}

void Map::Draw()
{
  Draw(m_cameraX, m_cameraY);
}

/*void Map::Draw()
{
   //m_currentTile = (int)((m_cameraX / m_tileSize) + (m_cameraY / m_tileSize * 100));

   for (int i = 0; i < 1; i++) // draw y tile,  using +2 as partial tile add-ons
   {
      for (int j = 0; j < 1; j++) //(int)(m_screenWidth / m_tileSize + 0.5) + 2; i++) // same as above, but draw x tile
      {   
         m_source.x = m_tiles[m_mapIndexes[(j) + (i * 100)]].x;
         m_source.y = m_tiles[m_mapIndexes[(j) + (i * 100)]].y;
         m_source.w = m_tileSize; // width to blit is the tile size - the m_offset
         m_source.h = m_tileSize;

         m_destination.x = (j * m_tileSize) - m_cameraX; // the destination of the tile, which is used with m_offsets/sources
         m_destination.y = (i * m_tileSize) - m_cameraY;
         m_destination.w = m_source.w; // m_source.w updates every time m_currentTile is incremented, so it'll
                                // always change each call
         m_destination.h = m_source.h;

         m_graphics->DrawBitmap(m_bitmap, m_source, m_destination);

         m_currentTile += 1;
      }

      m_currentTile += 100;
   }

}*/

void Map::HandleState()
{
   switch (m_currentState)
   {
   case Walk:
      HandleWalkState();
      break;
   default:
      HandlePauseState();
      break;
   }

   Draw();
}

void Map::HandlePauseState()
{

}

void Map::HandleWalkState()
{
   switch (m_currentDirection)
   {
   case South:
      m_amountToMove = m_movementSpeed / m_currentFps;
      m_cameraY += m_amountToMove;

      if (m_cameraY > m_mapHeight - m_screenHeight)
         m_cameraY = m_mapHeight - m_screenHeight;

      break;
   case East:
      m_amountToMove = m_movementSpeed / m_currentFps;
      m_cameraX += m_amountToMove;

      if (m_cameraX > m_mapWidth - m_screenWidth)
         m_cameraX = m_mapWidth - m_screenWidth;
      
      break;
   case North:
      m_amountToMove = m_movementSpeed / m_currentFps;
      m_cameraY -= m_amountToMove;

      if (m_cameraY < 0)
         m_cameraY = 0;

      break;
   case West:
      m_amountToMove = m_movementSpeed / m_currentFps;
      m_cameraX -= m_amountToMove;

      if (m_cameraX < 0)
         m_cameraX = 0;

      break;
   default:
      break;
   }

}
Back to top  
Gardon
Scholar


Joined: 05 Feb 2006
Posts: 157

PostPosted: Thu Feb 16, 2006 12:51 am    Post subject: [quote]

aye.... nevermind. It turns out I never initialized m_movementSpeed.

I know I did though. I guess it was a "reverting back to an old file you thought was up to date" kind of position.

now I just have to figure out hwo to move him continuously

(or the map, rather)

Jason
Back to top  
Post new topic Reply to topic Page 3 of 3 All times are GMT
Goto page Previous  1, 2, 3 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum