Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 2d array, how do I........
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DanShadow




PostPosted: Fri Jan 23, 2004 11:41 am   Post subject: 2d array, how do I........

Im trying to make a 2D array holding x and y positions in a map like so:
code:

var map : array 1 .. 10, 1 .. 10 of int
for i : 1 .. 10
    map (i, i) := i * 25
end for
var aimer : int := Pic.FileNew ("test-pic.bmp")
Pic.Draw (aimer, map (1, 1), map (1, 1), picMerge)

That makes 100 tiles, 10*10. Each tile is 25 pixels away from eachother.
Im trying to make it like th is:
code:

map(3,5)
%in map, 3=3rd tile across, 5=5th tile up...so map(3,5)= map(75,125)
Pic.Draw(monster-guy,map(3,3),picMerge)

Of course this wont work because Pic.Draw requires the x and y co-ordinates seperately...but in my 2D array, map declares both x and y co-ordinates as one variable(array). Is there a way I can declare it so I could use the idea ive got (in the pic.draw command) in placing units? My teacher told me it could when I handed in my ISU..because I did it the other way, with arrays for "mapx,mapy,mapt" (mapt=map tile type).
If you can offer any suggestions, or help, thanks!
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Jan 23, 2004 1:51 pm   Post subject: (No subject)

wouldn't Pic.Draw (airmer, map (i,0), map (0, k), picMerge) work?

dunno haven't tried it

Cheers
DanShadow




PostPosted: Fri Jan 23, 2004 2:09 pm   Post subject: (No subject)

no it wont, because the array is 1..10
if you put a '0' in there, it is out of the subscript range of the array Sad
Cervantes




PostPosted: Fri Jan 23, 2004 2:18 pm   Post subject: (No subject)

then can you create a variable for the x and y that you get from the array? not sure how it would work though, Confused
Tony




PostPosted: Fri Jan 23, 2004 3:27 pm   Post subject: (No subject)

well if you just need an array to hold pixel locations of tiles, I think you can do with a single 1D array to hold your multiples of 25...

Pic.Draw(aimer, multiple(2),multiple(3),picMerge)

which translates into 50,75 coordinats
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DanShadow




PostPosted: Fri Jan 23, 2004 11:28 pm   Post subject: (No subject)

holy crap! Im an idiot, I cant believe i didnt figure that out!! Thanks Tony!!!
Tony




PostPosted: Sat Jan 24, 2004 12:23 am   Post subject: (No subject)

haha Laughing no problem 8)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DanShadow




PostPosted: Sat Jan 24, 2004 7:37 pm   Post subject: (No subject)

aww crap... I forgot to tell you that the game is isometric...so it doesnt quite work.
code:

var map:array 1..10 of int
var x,y:int
for i:1..10
map(i):=i*25
end for
Pic.Draw (tile-grass,map(x),map(y),picMerge)

This draws a regular 10*10, 2D tile grid like in checkers or chess. Thats wh y I need something that wo rks with ""map(x,y)""...because it doesnt draw isometric that wa y...
Delos




PostPosted: Sat Jan 24, 2004 8:51 pm   Post subject: (No subject)

Just a thought...but how about making a type.
eg.
code:

type loc:
record
x: int
y : int
end record


Create your array of loc's and assign the values as necassary...

Question
DanShadow




PostPosted: Sat Jan 24, 2004 9:00 pm   Post subject: (No subject)

yeah...but problem is, I dont know how to save records. Crying or Very sad
[url]http://www.compsci.ca/v2/viewtopic.php?t=3260 [/url]
At t hat link, I asked the question...now how would I go about saving record-arrays??? lol
Delos




PostPosted: Sat Jan 24, 2004 9:48 pm   Post subject: (No subject)

code:

type test:
record
x : int
y : iny
end record

var file : int

var list : array 1..5 of test
for i : 1..upper(list)
list(i).x := Rand.Int(1,3)
list(i).y := Rand.Int (4, 6)
end for
% Random assigment.

open : file, "file.txt", put
for i : 1..upper(list)
put : file, list(i).x
put : file, list(i).y
end for
close : file



Open the file, and there is your array!
Did that help? Perhaps I misunderstood your intentions.

BTW, I did this code in the post...so it may be a tad buggy...hehehe
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: