Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
I'm blitting each individual tile directly to the screen, but when I get the x coordinates of the tiles in the first 2 rows, they're huge, here's the readout of the first 27 tiles:
3515728 3515792
3516752 3516816
3517776 3517840
3518800 3518864
3519824 3519888
3520848 3520912
3521872 3521936
3522896 3522960
3523920 3523984
3524944 3525008
3525968 3526032
3526992 3527056
3528016 3528080
3529040 3529104
3530064 3530128
3531088 3531152
3532112 3532176
3533136 3533200
3534160 3534224
3535184 3535248
3536208 3536272
3537232 3537296
3538256 3538320
3539280 3539344
3540304 3540368
3541328 3541392
3542352 3542416
3543376 3543440
64 32
96 32
I'm not sure if this is a memory error or what, but each tile has an SDL_Rect which stores where the x location is at and all that. When I call the function for the first 27, its all normal, they're all just as they should be 0, 0 - 32, 0 - 64, 0. Here's some code clips:
Code:
[cLevel.h]
//Shawn Barnes
//June 3rd, 2006
#ifndef __CLEVEL_H_
#define __CLEVEL_H_

#include <iostream>
#include <fstream.h>
#include "cTile.h"

class cLevel {

private:
	SDL_Surface* m_Bitmap;
	SDL_Surface* m_Window;
	cTile *m_Tiles[];

public:
	cLevel(SDL_Surface* window, SDL_Surface* lBitmap) : m_Window(window), m_Bitmap(lBitmap)
	{
		Load("data/test.txt");
	}

	~cLevel() { }

	void Load(char* level)
	{
		int x = 0;
		int y = 0;
		ifstream input_stream(level);
		int dummy;
		int input_tile_type;
		input_stream >> wtile_width;
		input_stream >> wtile_height;
		area_width = wtile_width*TILE_WIDTH;
		area_height = wtile_height*TILE_HEIGHT;
		input_stream >> dummy;
		
		int tiletotal = wtile_width*wtile_height;
		for(int t = 0; t < tiletotal; t++)
		{
			input_stream >> input_tile_type;
			m_Tiles[t] = new cTile(m_Bitmap, x, y, (int)input_tile_type);
			x += TILE_WIDTH;
			if(x >= area_width)
			{
				x = 0;
				y += TILE_HEIGHT;
			}
		}
		input_stream.close();
	}
		
	void Draw()
	{
		int tiletotal = wtile_width*wtile_height;
		//leveltemp = SDL_DisplayFormat(m_Window);
		for(int t = 0; t < tiletotal; t++)
		{
			m_Tiles[t]->Draw(m_Window);
		}
		//SDL_UpdateRect(leveltemp, 0, 0, 0, 0);
		//SDL_BlitSurface(m_Temp, &camera, m_Window, &dest);
	}
	
	bool TestCollision(SDL_Rect obj, cPlayer* player,  Direction p_dir)
	{
		SDL_Rect temp;
		int tiletotal = wtile_width*wtile_height;
		for(int t = 0; t < tiletotal; t++)
		{
			temp = m_Tiles[t]->GetRect();
			if(m_Tiles[t]->GetType() == 2) {
				if(RectOnRectCollision(obj, temp))
				{
					return true;
				}
			}
		}
		if((obj.x < 0))
			return false;
		if((obj.x+obj.w > WINDOW_WIDTH))
			return false;
		if((obj.y < 0))
			return false;
		if((obj.y+obj.h > WINDOW_HEIGHT))
			return false;
		return false;
	}

};

#endif

Code:
[cTile.h]
//cTile by Shawn Barnes
//Date: June 3rd, 2006
//Thanks for Aaron Cox for the help

#ifndef __CTILE_H_
#define __CTILE_H_

class cTile {

private:
	int m_ImageX;
	int m_ImageY;
	int m_Width;
	int m_Height;
	int m_Type;
	int dstX;
	int dstY;
	SDL_Rect box;
	SDL_Rect tile;
	SDL_Surface* m_Tile;
	
public:
	cTile(SDL_Surface* bitmap, int dx, int dy, int type)
	{
		m_Tile = bitmap;
		dstX = dx;
		dstY = dy;
		m_Type = type;
		tile = TileTypeRect(m_Type);
		box.x = 0;
		box.y = 0;
		box.x = dx;
		box.y = dy;
		m_ImageX = tile.x;
		m_ImageY = tile.y;
		m_Width = tile.w;
		m_Height = tile.h;
		box.w = m_Width;
		box.h = m_Height;
	}
	cTile() {}
	~cTile() {  }
	
	SDL_Rect TileTypeRect(int type)
	{
		SDL_Rect tile_rect;
		
		switch(type)
		{
			case 1:
				tile_rect.x = 0;
				tile_rect.y = 0;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			case 2:
				tile_rect.x = 32;
				tile_rect.y = 0;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			case 3:
				tile_rect.x = 0;
				tile_rect.y = 32;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			case 4:
				tile_rect.x = 32;
				tile_rect.y = 32;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			default:
			break;
		}
		
		return tile_rect;
	}
	
	int GetType()
	{
		return m_Type;
	}
	
	void SetImageLocation(int x, int y)
	{
		m_ImageX = x;
		m_ImageY = y;
	}
	
	void Draw(SDL_Surface* window)
	{
		static int x = -1;
		x++;

		if(x <= 35){
			std::cout << dstX << " " << dstY << " " << std::endl;
			}
		if(RectOnRectCollision(camera, box))
		{
			HandleUpdate(box.x-camera.x, box.y-camera.y, m_Tile, window, &tile);
		}
	}
	
	SDL_Rect GetRect()
	{
		return box;
	}
	
	bool collision;
	
};

#endif

Do you see any errors or that?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.