Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2014

    building 2d games in c++ - Creating a Sprite-Based Game - Loading-Packages-In-Game

    i started these videos and now i'm stuck at building 2d games in c++ - Creating a Sprite-Based Game - episode Loading-Packages-In-Game

    before starting this episode , everything worked perfectly ! so i started implanting the codes and at the end i began testing
    my problem :
    when i load a package in evilmonkey project my empty tiles are walls (and wall tiles are empty tiles) and my player tile isn't in the right place ...!
    i watched the video a few times ! and i even wrote every code in this video once again from the very beginning ! and still no luck !

    this is my LoadGame function , where am i going wrong ? is there something im missing ? please i spend days and days debugging and going through codes , im losing hope , please help me

    void AppFrame::loadGame(wxString filename, int startingLevel /*= 1*/)
    	package = new Package();
    	player = new Mage(NULL, &drawArea, 0);
    	FILE *stream;
    	stream = fopen(filename, "r+b");
    	int numLevels;
    	fread(&numLevels, sizeof(int), 1, stream);
    	Level_Info *firstLevel;
    	for (int i = 0; i < numLevels; i++)
    		Level_Info *new_level = new Level_Info;
    		fread(&new_level->grid_x, sizeof(int), 1, stream);
    		fread(&new_level->grid_y, sizeof(int), 1, stream);
    		new_level->grid = new char *[new_level->grid_x];
    		for (int x = 0; x < new_level->grid_x; x++)
    			new_level->grid[x] = new char[new_level->grid_y];
    		for (int x = 0; x < new_level->grid_x; x++)
    			fread(new_level->grid[x], sizeof(char), new_level->grid_y, stream);
    		if (i == startingLevel - 1)
    			currentLevel = startingLevel;
    			firstLevel = new_level;
    	packageLoaded = true;
    	level->addEnemy(0); // its addEnemies in video which i used a different name "addEnemy"
    	currentLevel = 1;
    	gameState = STATE_GAME_IN_PROGRESS;
    i used logging to find what is the problem
    i noticed if (!level->numEnemies()) inside void AppFrame::updateGame(void) is always false !

    for one thing the videos , do NOT SHOW numEnemies Function (and also a few other things like mage class update which i had to come up with something my self), so i wrote one my self and it worked till now , but now its causing the problem
    This is my numEnemies Function

    int Level::numEnemies()
    	Log::log("Inside Level::numEnemies");
    	Log::log("Level::numEnemies Begins");
    	int numE = 0;
    	for (iter = npc.begin(); iter != npc.end();)
    		if ((*iter)->classID == ENEMY_CLASSID)
    			numE ++;
    	Log::log("Level::numEnemies Ends");
    	return numE;
    can someone check theirs and tell me if i wrote this right ?

    i logged everything and every line and finally i solved the problem , of course it was several issue , i changed at least 50 line code to fix everything ..!! for one thing i noticed levelEditor and evilMonkey project used different index for drawing and that caused the wall problem and a few other thing which i m too tired to mention ! .
    Last edited by ahmadi3D_ali; 10-20-2014 at 01:00 PM. Reason: Problem Solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts