Page 1 of 1

Reading an array through a pointer...

Posted: Sun Jan 04, 2009 6:56 pm
by kadajett
Ok I have the problem that I need to use an array inside of a class pointer but I want to pass the whole array and make it into a temp array to render.

so here is what i have for main...

Code: Select all

#include <iostream>
#include "SDL.h"
#include "level.h"

//game loop stuff 
//rendering tiles and player
void render();

//handle controller 
void handleEvents();
//handle moving tiles and characters
void update();
//switch current level with new level
void changeLevel(level* newLevel);
//initialization
void init();

// is game running 
bool isRunning = 0;
//current playing level
level* currentLevel;

int main( int argc, char* args[] )
{
	isRunning = true;
	//main game loop
	while (isRunning)
	{
		handleEvents();
		update();
		render();
	}

	return 0;
}

 
//rendering tiles and player
void render()
{
	currentLevel->
}

//handle controller 
void handleEvents()
{

}

//handle moving tiles and characters
void update()
{

}

void changeLevel(level* newLevel)
{
	currentLevel = newLevel;
}

void init()
{
	level firstLevel;
	changeLevel(&firstLevel);
}
this is my level class

Code: Select all

#pragma once
#include <string>

class level
{
public:
	level(void);
	virtual ~level(void);
	void loadmap(std::string filname);
private:
	int map[10][10];
};
I hope you guys understand what I'm doing lol if not i will try to explain more :P

Re: Reading an array through a pointer...

Posted: Sun Jan 04, 2009 10:11 pm
by DMan
//rendering tiles and player
void render()
{
currentLevel->
}

...

class level
{
public:
level(void);
virtual ~level(void);
void loadmap(std::string filname);
private:
int map[10][10];
};

Are you trying to access the map array inside the "currentLevel" instance of the level class?
In that case you might want to add an accessor function to the level class so that you can retrieve elements from the private 2d map array.

If that isn't what you are trying to do, could you provide more detail in your question?

-DMan

Re: Reading an array through a pointer...

Posted: Sun Jan 04, 2009 10:51 pm
by kadajett
I just fixed it thank you anyways... I was going about it wrong lol I was trying to send all of my info into a render function when instead I should have had an individual render method for each level instance. That in turn made passing that array unnecessary... :P

Re: Reading an array through a pointer...

Posted: Sun Jan 04, 2009 10:55 pm
by MarauderIIC
Eh? I'm all for having a single 'renderer' class... Levels shouldn't render themselves, I think.

Re: Reading an array through a pointer...

Posted: Mon Jan 05, 2009 10:44 am
by ismetteren
MarauderIIC wrote:Eh? I'm all for having a single 'renderer' class... Levels shouldn't render themselves, I think.
I think too...