Posted: 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
Posted: 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 :array1.. RowsInFile, 1.. ColumnsInFile ofint
open: FileNo, FileName, get
for row :1.. RowsInFile
for col :1.. ColumnsInFile
get: FileNo, NextChar
MyIntegers (row, col):=ord(NextChar) - CharZero
endfor get: FileNo, NextChar % Just to get rid of the newline character endfor
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
Posted: Sat Jan 07, 2012 10:45 am Post subject: Re: [Tutorial] 2D Tile based games
couldn't you just
Turing:
var mapstr: array1..20,1..20ofstring var map: array1..20,1..20ofint
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)) endfor endfor close(FileNo)
Dreadnought
Posted: 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
Posted: 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.