2d array trouble
ok. I'm having a lot of trouble getting my 2d array to work.
here's my array code:
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
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};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
int array[5]; means there are 5 positions, numbered 0..4
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| memcpy(stuct array pointer struct array point) | unknown | 22 | 8,831 |
Sep 29, 2005 03:16 PM Last Post: unknown |
|
| Newbie array trouble | that sound again | 6 | 2,884 |
Mar 26, 2005 04:25 AM Last Post: that sound again |
|

