need help with rouglike game dev walking through walls!!??

Hello I am new to these forums and need help, I walking through walls. I found its the if statements but I cant find the bug. (keep in mind still a huge work in progress.)

walls are nines and to move hit a w a s d key then enter

p.s. I am 12 years old so please don't judge me for my mistakes thanks!

os: windows 8

compiler: Microsoft visual c++ 2010 express

here is my code:

#include <iostream>
#include <string>
using namespace std;
int main()
{

int wc = 9;

//command var.

string command ;

//end

//worldsize

int world[6][4];

//end

//spawn pos.

int x = 3;
int y = 2;

//end

start:

//map

world[0][0] = 9;
world[1][0] = 9;
world[2][0] = 9;
world[3][0] = 9;
world[4][0] = 9;
world[5][0] = 9;
world[6][0] = 9;
world[0][1] = 9;
world[1][1] = 0;
world[2][1] = 0;
world[3][1] = 0;
world[4][1] = 0;
world[5][1] = 0;
world[6][1] = 9;
world[0][2] = 9;
world[1][2] = 0;
world[2][2] = 0;
world[3][2] = 0;
world[4][2] = 0;
world[5][2] = 0;
world[6][2] = 9;
world[0][3] = 9;
world[1][3] = 0;
world[2][3] = 0;
world[3][3] = 0;
world[4][3] = 0;
world[5][3] = 0;
world[6][3] = 9;
world[0][4] = 9;
world[1][4] = 9;
world[2][4] = 9;
world[3][4] = 9;
world[4][4] = 9;
world[5][4] = 9;
world[6][4] = 9;

//end

//wall collide script

if(wc == world[x][y])
{
if( command == "w") y = y - 1;
if( command == "s") y = y + 1;
if( command == "a") x = x + 1;
if( command == "d") x = x - 1;

}

//end

//avatar

world[x][y] = 1;

//end

//graphics script

cout << world[x+2][y+1];
cout << world[x-1][y+1];
cout << world[x][y+1];
cout << world[x-1][y+1];
cout << world[x-2][y+1];
cout << endl;
cout << world[x+2][y];
cout << world[x+1][y];
cout << world[x][y];
cout << world[x-1][y];
cout << world[x-2][y];
cout << endl;
cout << world[x+2][y-1];
cout << world[x+1][y-1];
cout << world[x][y-1];
cout << world[x-1][y-1];
cout << world[x-2][y-1];
cout << endl;

//end

//movement script

cin >> command;
if (command == "w") y = y + 1;
if (command == "s") y = y - 1;
if (command == "d") x = x - 1;
if (command == "a") x = x + 1;

//end

goto start;

return 0;

}
Last edited on
Hey there bro, your project looks a bit confusing to me, but if it works fine, then your issue should be this:

if(wc = world[x][y])

should be
if(wc == world[x][y])

= will change a variable
== checks to see if they are equal
still wont work
if your confusion is the // just comments to help me out
Last edited on
Putting it in code tags will make your code easier to read on forums, and would help us.

Incase you don't know use these tags, no spaces between the '/' and 'code'. Also I think this belons in beginner since it isn't a Win32 program.
[code]CODE[/ code]
If you want you can email me at lukerossie@gmail.com ill show you my old console text rpg and teach you what the code means
Topic archived. No new replies allowed.