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

Username:   Password: 
 RegisterRegister   
 [Tutorial] 2D Tile based games
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
evildaddy911




PostPosted: Fri Jan 06, 2012 4:03 pm   Post subject: Re: [Tutorial] 2D Tile based games

do i need to put spaces between the tiles?


rural.txt
 Description:

Download
 Filename:  rural.txt
 Filesize:  1.2 KB
 Downloaded:  163 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Fri Jan 06, 2012 4:35 pm   Post subject: RE:[Tutorial] 2D Tile based games

hit the space bar? You could write a program to do it, but without experience it would take you longer than just doing it manually.
Dreadnought




PostPosted: Fri Jan 06, 2012 9:41 pm   Post subject: Re: [Tutorial] 2D Tile based games

Alternately you can read in one character at a time and simply convert each one to an integer using ord() - 48 (since ord('0') = 48).
It might look something like this.
Turing:
% Read in a wall of single digit integers
const CharZero := 48
const ColumnsInFile := 20
const RowsInFile := 10
const FileName := "MyImaginaryFile.omg"
var FileNo : int
var NextChar : char
var MyIntegers : array 1 .. RowsInFile, 1 .. ColumnsInFile of int

open : FileNo, FileName, get

for row : 1 .. RowsInFile
    for col : 1 .. ColumnsInFile
        get : FileNo, NextChar
        MyIntegers (row, col) := ord (NextChar) - CharZero
    end for
    get : FileNo, NextChar    % Just to get rid of the newline character
end for

close : FileNo

Note that this does not reverse the rows when writing to the array. Also, if you get weird - integers then you're likely reading in the newline character ('\n' = chr(10)).
evildaddy911




PostPosted: Sat Jan 07, 2012 10:45 am   Post subject: Re: [Tutorial] 2D Tile based games

couldn't you just
Turing:
var mapstr: array 1..20,1..20 of string
var map: array 1..20,1..20 of int

open FileNo, FileName,get
for decreasing y:20..1
     for x:1..20
          get: FileNo, mapstr(x,y)(1)
          map(x,y):=strint (mapstr(x,y))
     end for
end for
close(FileNo)
Dreadnought




PostPosted: Sat Jan 07, 2012 4:53 pm   Post subject: Re: [Tutorial] 2D Tile based games

You could, and it essentially no different from the code I posted, except it seems wasteful. You declare 400 strings and use 1 out of the 255 characters for each. Also, you read the next character into a different string each time, but you never use that string anyways. It's the right idea, but you're declaring 101999 characters that you don't need.
mirhagk




PostPosted: Sat Jan 07, 2012 6:26 pm   Post subject: RE:[Tutorial] 2D Tile based games

How about a comprimise. Read it into a temporary string variable (getting rid of the array of strings) and then use strint.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: