5 Replies - 1356 Views - Last Post: 21 April 2013 - 03:20 PM Rate Topic: -----

#1 TheNewbie1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-April 13

C++ Console maze game help

Posted 21 April 2013 - 11:59 AM

Everything compiles but the problem I'm having is that my blue ascii character is going through walls. I'm probably missing something from my CanPlayerEnterSpace() function in the Map.cpp file. Also, my keys and doors have weird gray backgrounds and I don't know how to get rid of that.

Person.h file:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>
#include <cstdlib>
#include <ctime>

#pragma once
class Person
{
	private:
		int m_X;
		int m_Y;

	public:
		WORD Color;

		Person();
		~Person();

		void DrawASCIICharacter(int x, int y, unsigned char ch, WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);
		void DrawPerson(CHAR_INFO *pScreen,	int ScreenWidth, int ScreenHeight);

		void SetX(int x);
		void SetY(int y);

		int GetX() const {return m_X;}
		int GetY() const {return m_Y;}
};

Person.cpp file:
#include "Person.h"


Person::Person()
{
	m_X = 1;
	m_Y = 1;
	Color = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_INTENSITY;
}


Person::~Person()
{
}

void Person::DrawASCIICharacter(int x, int y, unsigned char ch, WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight)
{
    if (x < 0) return;
    if (y < 0 ) return;
    if (x >= ScreenWidth) return;
    if (y >= ScreenHeight) return;

    pScreen[y*ScreenWidth + x].Char.AsciiChar = ch;
    pScreen[y*ScreenWidth + x].Attributes = CharAttribute;
}

void Person::DrawPerson(CHAR_INFO *pScreen,	int ScreenWidth, int ScreenHeight)
{
	
	DrawASCIICharacter(m_X, m_Y, 2, Color, pScreen, ScreenWidth, ScreenHeight);

}

void Person::SetX(int x)
{
	m_X = x;
	x = 1;
}
void Person::SetY(int y)
{
	m_Y = y;
	y = 1;
}



Map.h file:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>
#include <process.h>
#include <cstdlib>
#include <ctime>
using namespace std;

#pragma once
class Map
{
	private:
	    int m_mazeWidth;
		int m_mazeHeight;
		//int m_mazeArray;

	public:
		WORD mazeColor;
		WORD endColor;
		WORD keyColor;
		WORD doorColor;
		WORD backgroundColor;
		WORD winColor;

		Map();
		//Map(int mazeArray);
		~Map();

		bool CanPlayerEnterSpace(int x, int y);
		void DrawASCIICharacter(int x, int y, unsigned char ch, WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);
		void DrawMaze1234(CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);
		void ClearScreen(WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);
		

		

};



Map.cpp file:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>
#include <cstdlib>
#include <ctime>
#include "Map.h"
#include "Person.h"

Map::Map()
{
	m_mazeWidth;
	m_mazeHeight;
	
    mazeColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_INTENSITY;
	endColor = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_GREEN | BACKGROUND_INTENSITY;
    keyColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | BACKGROUND_INTENSITY;
    doorColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_RED | BACKGROUND_INTENSITY;
	backgroundColor = 0;
	winColor = BACKGROUND_BLUE | BACKGROUND_INTENSITY;

}


Map::~Map()
{
}
void Map::DrawASCIICharacter(int x, int y, unsigned char ch, WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight)
{

    if (x < 0) return;
    if (y < 0 ) return;
    if (x >= ScreenWidth) return;
    if (y >= ScreenHeight) return;

    pScreen[y*ScreenWidth + x].Char.AsciiChar = ch;
    pScreen[y*ScreenWidth + x].Attributes = CharAttribute;}


void Map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0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1,
	1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
	1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
	3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	};
	
	int mazeHeight = 45;
	int mazeWidth = 20;
//	int mazeArray[45*20];
	int r, c;
	for (r = 0; r < mazeHeight; r++)
	{
		for (c=0; c < mazeWidth; c++)
		{
			switch (mazeArray[r*mazeWidth + c])
			{
				case 1: DrawASCIICharacter(c, r, 219, mazeColor, pScreen, 20, 45); break;
				case 2: DrawASCIICharacter(c, r, 212, mazeColor, pScreen, 20, 45); break;
				case 3: DrawASCIICharacter(c, r, '*', endColor, pScreen, 20, 45); break;
				case 4: DrawASCIICharacter(c, r, 'K', keyColor, pScreen, 20, 45); break;
				case 5: DrawASCIICharacter(c, r, 68, doorColor, pScreen, 20, 45); break;
				
			}
				
		}
	}
	

}
bool Map::CanPlayerEnterSpace(int x, int y)
{
	int mazeArray[45*20];
	int mazeWidth = 20;
	int keys = 0;
	if (mazeArray[y*mazeWidth + x] == 1) return false;

	if (mazeArray[y*mazeWidth + x] == 5)
	{
		if (keys == 0) return false;
		else
		{
			keys--;
			mazeArray[y*mazeWidth + x] = 0;
			return true;
		}
	}


	return true;
}
void Map::ClearScreen(WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight)
{
    int r, c;
    for (r = 0; r < ScreenHeight; r++)
    {
        for (c = 0; c < ScreenWidth; c++)
        {
            pScreen[r*ScreenWidth + c].Char.AsciiChar = ' ';
            pScreen[r*ScreenWidth + c].Attributes = CharAttribute;
        }
    }
}

console.h file:
#include <Windows.h>
#include <process.h>
#include "screen.h"

//Constant Global Variables
;const int PERIMETER= 0;
const int HEIGHT = 30;
const int WIDTH = 45;
const WORD BACKGROUND_COLOR = 0;
const WORD BACKGROUND_COLOR_WIN = BACKGROUND_BLUE | BACKGROUND_INTENSITY;
const WORD PERSON_COLOR = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_COLOR;
const WORD END_COLOR = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_GREEN | BACKGROUND_COLOR;
const WORD KEY_COLOR = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | BACKGROUND_COLOR;
const WORD DOOR_COLOR = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_RED | BACKGROUND_COLOR;
const WORD WALL_COLOR = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
const WORD MAZE_COLOR = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_COLOR;

CHAR_INFO SCREEN_BUFFER[HEIGHT * WIDTH];
COORD BUFFER_SIZE = {WIDTH, HEIGHT};
COORD CHARACTER_POSITION = {0,0};
SMALL_RECT WINDOW_SIZE = {0, 0, WIDTH-1, HEIGHT-1};

//Function Prototypes
unsigned int __stdcall UpdateScreenThread(void *pThreadData);

//Global Variables
HANDLE g_hWin;   // Handle to the Standard Output
HANDLE g_hInput; // Handle to the Standard Input
bool g_ISRUNNING = true; 


main.cpp file:
//-------------------------------------------------------------------------------
// Shawn Philip
// swp5372@psu.edu
// CMPSC 122 Section 102
// Final Project
// 04/22/13
//-------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>
#include <cstdlib>
#include <ctime>
#include "Person.h"
#include "Map.h"
#include "console.h"
using namespace std;

bool isGameDone = false;
int keys = 0;

Map maze;
Person person;

int main()
{
	
	//person.DrawPerson(SCREEN_BUFFER, WIDTH, HEIGHT);
	//maze.DrawMaze1234(SCREEN_BUFFER, WIDTH, HEIGHT);

	DWORD numEvents, numEventsRead = 0;  // number of Events that have happened
    INPUT_RECORD inputEvent;             // Event from the input (or windows)
    
    //------------------------------------------
    // Setup the windows console
    //------------------------------------------
	unsigned int seed = time(0);
    srand(seed);
    // get the handles to the standard windows
    g_hWin = GetStdHandle(STD_OUTPUT_HANDLE);
    g_hInput = GetStdHandle(STD_INPUT_HANDLE);

    // Set the title of the window
    SetConsoleTitle(TEXT("The Labyrinth"));

    // Set the console window size
    SetConsoleWindowInfo(g_hWin, TRUE, &WINDOW_SIZE);

    // Set the buffer size
    SetConsoleScreenBufferSize(g_hWin, BUFFER_SIZE);

    maze.ClearScreen(BACKGROUND_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
    

    //------------------------------------------
    // This starts a thread that draws the screen
    //  ever 50 milliseconds
    //------------------------------------------
    unsigned int threadID = 0;
    _beginthreadex(NULL, 0, UpdateScreenThread, NULL, 0, &threadID);


    //------------------------------------------
    // This is the main Loop
    //------------------------------------------
    while (g_ISRUNNING)
    {
        // Check the events
        GetNumberOfConsoleInputEvents(g_hInput, &numEvents);

        if (numEvents)
        {
            ReadConsoleInputA(g_hInput, &inputEvent, 1, &numEventsRead);
            
            if (numEventsRead)
            {
                // An event has been read in

                // Check the event type: was it a key?
                switch (inputEvent.EventType)
                {
                    case KEY_EVENT:
						
				   if (inputEvent.Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
                    {
                        if (maze.CanPlayerEnterSpace(person.GetX(), person.GetY() + 1))
                            person.SetY(person.GetY() + 1);
                    }
                    if (inputEvent.Event.KeyEvent.wVirtualKeyCode == VK_UP)
                    {
                        if (maze.CanPlayerEnterSpace(person.GetX(), person.GetY() - 1))
                            person.SetY(person.GetY() - 1);
                    }
                    if (inputEvent.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
                    {
                        if (maze.CanPlayerEnterSpace(person.GetX() - 1, person.GetY()))
                            person.SetX(person.GetX() - 1);
                    }
                    if (inputEvent.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
                    {
                        if (maze.CanPlayerEnterSpace(person.GetX() + 1, person.GetY()))
                            person.SetX(person.GetX() + 1);
                    }
                    break;

                }
            } 
        } 

        //------------------------------------------
        // You Game code that you want to run "fast" goes here
        //------------------------------------------
	/*if(maze.DrawMaze1234(SCREEN_BUFFER, WIDTH, HEIGHT)
	{
	    if (person.DrawPerson(SCREEN_BUFFER, WIDTH, HEIGHT) == 3)
		{
			isGameDone = true;
		}
		
		
		if(person.DrawPerson(SCREEN_BUFFER, WIDTH, HEIGHT) == 4)
		{
			keys++;
			mazeArray[g_personY*mazeWidth + g_personX] = 0;
		}
	}*/
		
    } //while


	return 0;
}

unsigned int __stdcall UpdateScreenThread(void *pThreadData)
{
	
    while(g_ISRUNNING)
    {
        // call out timer update function
      //  TimerUpdate();
		if (isGameDone)
		{
			// Update the Screen
			maze.ClearScreen(BACKGROUND_BLUE | BACKGROUND_INTENSITY, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(17, 9, 'Y', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(18, 9, 'o', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(19, 9, 'u', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(20, 9, ' ', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(21, 9, 'W', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(22, 9, 'i', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(23, 9, 'n', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(24, 9, '!', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
		}
		else
		{
			// Update the Screen
			maze.ClearScreen(BACKGROUND_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawMaze1234(SCREEN_BUFFER, WIDTH, HEIGHT);
			person.DrawPerson(SCREEN_BUFFER, WIDTH, HEIGHT);
//			
			
			//DrawBorder();
			//DrawMaze();
			//DrawBox();
			
			maze.DrawASCIICharacter(9, 21, 'K', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(10, 21, ' ', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(11, 21, '=', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(12, 21, ' ', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(13, 21, 'K', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(14, 21, 'e', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(15, 21, 'y', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);

			maze.DrawASCIICharacter(11, 22, '=', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(12, 22, ' ', KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(13, 22, 48 + keys, KEY_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);

			maze.DrawASCIICharacter(9, 23, 'D', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(10, 23, ' ', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(11, 23, '=', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(12, 23, ' ', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(13, 23, 'D', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(14, 23, 'o', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(15, 23, 'o', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(16, 23, 'r', DOOR_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);

			maze.DrawASCIICharacter(19, 21, 2, PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(21, 21, ' ', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(21, 21, '=', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(22, 21, ' ', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(23, 21, 'Y', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(24, 21, 'o', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(25, 21, 'u', PERSON_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);

			maze.DrawASCIICharacter(19, 23, '*', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(21, 23, ' ', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(21, 23, '=', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(22, 23, ' ', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(23, 23, 'G', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(24, 23, 'o', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(25, 23, 'a', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
			maze.DrawASCIICharacter(26, 23, 'l', END_COLOR, SCREEN_BUFFER, WIDTH, HEIGHT);
		}
		
        // WriteConsoleOutputA is WriteConsoleOutput ASCII
        WriteConsoleOutputA(g_hWin, SCREEN_BUFFER, BUFFER_SIZE, CHARACTER_POSITION, &WINDOW_SIZE);
		
        // Wait 50 milli-seconds
        Sleep(50);
    }

    return 0;
}



Heres what it looks like:
Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Console maze game help

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,008
  • Joined: 05-May 12

Re: C++ Console maze game help

Posted 21 April 2013 - 01:13 PM

You are using 2 foreground colors and OR'ing them together:
015    mazeColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_INTENSITY;
016    endColor = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_GREEN | BACKGROUND_INTENSITY;
017    keyColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | BACKGROUND_INTENSITY;
018    doorColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_RED | BACKGROUND_INTENSITY;



Perhaps you meant BACKGROUND_* instead?
Was This Post Helpful? 0
  • +
  • -

#3 TheNewbie1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-April 13

Re: C++ Console maze game help

Posted 21 April 2013 - 01:20 PM

I didn't notice that! Thank you, the gray background behind them is gone. I'm still having trouble with preventing my person from going through the walls though.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4019
  • View blog
  • Posts: 12,406
  • Joined: 25-December 09

Re: C++ Console maze game help

Posted 21 April 2013 - 02:30 PM

Note, not your actual problem, but you shouldn't be including both the C standard headers and the C++ versions of the C standard headers.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>
#include <process.h>
#include <cstdlib>
#include <ctime>
using namespace std;

#pragma once


Since this is a C++ program you should only include the C++ versions <cstdlib> not <stdlib.h>.

Also you should only include the headers you actually need. For example the above code is from your Map.h and you shouldn't really need any of those headers except maybe the <window.h> (for the definition of "WORD"). Also your pragma statement should probably be the first line. And lastly using the "using namespace std;" clause in header files is a very bad practice and should be avoided, I also don't think you are using anything that requires this statement in this header.

Jim

This post has been edited by jimblumberg: 21 April 2013 - 02:30 PM

Was This Post Helpful? 0
  • +
  • -

#5 TheNewbie1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-April 13

Re: C++ Console maze game help

Posted 21 April 2013 - 02:46 PM

Thank you for the advice, I was being careless on my part.
Was This Post Helpful? 0
  • +
  • -

#6 TheNewbie1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-April 13

Re: C++ Console maze game help

Posted 21 April 2013 - 03:20 PM

Alright so I got the backgrounds of each of my ASCIIs fixed, but my person still goes through walls. My CanPlayerEnterSpace() function in the Map.cpp doesn't seem to work because of this. If I put my drawn out array into my CanPlayerEnterSpace() function, then my character/person stops moving.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1