iDevGames Forums
2d array trouble - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: 2d array trouble (/thread-4777.html)



2d array trouble - saxplayer13 - Nov 20, 2005 08:23 PM

ok. I'm having a lot of trouble getting my 2d array to work.
here's my array code:
Code:
int badwordarray[3][5] = {
{0,1,1,8,1},
{-1,-1,-1,-1,-1}, //need a clear line between all real badwordarray
{1,2,9,8,-1}};  //map,type,x,y,dir};
This is used in my tile based game to store enemies... but it is not working very well.
My first problem was that accessing the last one in an array (badwordarray[1][5]), and multiplying it by -1 would effectively multiply the first in the next row (badwordarray[2][1]) by -1 as well. This is bad because the first in the array is supposed to be a map number, and so far, I am not using negative numbers for map numbers. I fixed this first problem by inserting the useless line of -1s.

My latest problem is that when trying to access the last integer, badwordarray[3][5], it returns a -4. As that is speed, now my enemies are moving 3 extra tiles, and completely missing all the walls inbetween.

If anyone has some time, help with either of my problems would be appreciated. I am new to Cocoa/Objective-C, so it is probably something simple I overlooked. I could post my whole code if necessary, but I bet it is just a generic array issue.

Thanks -Saxplayer13 Grin


2d array trouble - OneSadCookie - Nov 20, 2005 08:25 PM

int array[5]; means there are 5 positions, numbered 0..4


2d array trouble - saxplayer13 - Nov 20, 2005 08:32 PM

Darn. I knew that too.
Thanks for your quick reply. Grin

--
"Now I can focus on my crippling emotional pain. Oh Daddy, why won't you hug me?" ~Moe from the Simpsons