Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[Tutorial] 2D Tile based games
Author Message

Posted: 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:
Filename:  rural.txt
Filesize:  1.2 KB

mirhagk

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.

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 : 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)).

Posted: 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)

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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: