0

I have a game grid represented by an array of 50x50 dimension. I want to draw walls on the grid, so each wall segment will be between 2 sets of (X,Y) coordinates. for example, a wall segment may be in between grid square (25,25) and (25,26). So I want to store those values as a pair of pairs, for each wall segment.

[(25,25),(25,26)] should be one object,

[(26,25),(26,26)] would be another, and so on.

I want to store these, and I want to be able to look up this collection, each time a player is moving to another grid square, to see if there is a wall in between the squares.

another possible issue is that the player may be moving from (26,26) to (26,25) or vice versa, either way there will be a wall segment there... so I may have to check both values, or store 2 values ovjects for each wall segment, like so:

[(26,25),(26,26)] [(26,26),(26,25)]

both representing the same wall segment, but easier to look up?

Anyone got ideas? because it seems there must be a simpler way...

An example of how I'm trying... unsure how to store these segments, and parse them:

@implementation gridSeg
-(id)initWithX:(int)X withY:(int)Y{
self = [super init];
self.Xcoord = X;  
self.Ycoord = Y;  
...

@implementation wallSegPair  
-(id)initWithSeg:(gridSeg)g1 seg2:(int)g2 withVertical:(bool)vertical{  
self = [super init];    
self.gridSeg1 = g1; 
self.gridSeg2 = g2; 
self.vertical = vertical; //maybe not needed
...
sbiefeni
  • 53
  • 1
  • 6
  • This is what classes are for. Create a class for your X,Y pair. Create a class representing a series of these pairs. Then you can add all the appropriate logic to these classes as needed. – rmaddy Jan 28 '15 at 00:12
  • Hi Maddy... Thanks for your answer I was exploring how to do something like you say, but it's gotten a little abstract for me. Can you give me an example of how a class represents a series of these pairs? – sbiefeni Jan 29 '15 at 17:56
  • I edited to show an example of what I'm trying... but unsure how to complete.. – sbiefeni Jan 29 '15 at 20:10

1 Answers1

0

Maybe you can make your own structure (was "use a CGPoint") and NSValue objects as shown in this question :

How to wrap a Struct into NSObject

Community
  • 1
  • 1
ıɾuǝʞ
  • 2,829
  • 26
  • 38