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()
{
Congratz on trying to learn C++ :D. Just to give you a helping hand there is a button when your writting your messages on here So that when you add code it looks all fancy and neat.
Well, there's no collision detection at all, so not really all that surprising that you're walking through walls. You should check if the position you're moving to is a wall or not before you actually move. Which means that you should simply check if world[x][y+1] == 9 if you're moving up. And like Stormhawk44 said your collision and movement are the same, so just get rid of the collision one for now.
if (command == "w" && world[x][y+1] != 9) y = y + 1;
if (command == "s" && world[x][y-1] != 9) y = y - 1;
if (command == "d" && world[x-1][y] != 9) x = x - 1;
if (command == "a" && world[x+1][y] != 9) x = x + 1;
Thanks!!! this is great just great thanks a million times thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
again TTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHAAAAAAAAAAAAAAANNNNNNNNNNNNNNNNNNKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSS!!!!!!!!!!!!!!!!!!!!!!!!!!
Right then, if you feel like you need to know more of the language you should check out the tutorial on the site, it should put you on the right track http://cplusplus.com/doc/tutorial/
You probably have a decent understanding of the basics and should be able to jump into the control structures and functions