Defining walls?

Is it possible to define a wall, by reading a character that's on a certain location? Or do I have to go the long way round and define all the walls that there's going to be, giving all the specific locations... Because I'm loading 'maps' from a txt file and using '#' for 'walls' so I was just wondering if there was a way to do that? If anyone needs any more information on what it is that I'm exactly trying to do, feel free to reply.
Many Thanks.
~Dan

Comments

  • : Is it possible to define a wall, by reading a character that's on a
    : certain location? Or do I have to go the long way round and define
    : all the walls that there's going to be, giving all the specific
    : locations... Because I'm loading 'maps' from a txt file and using
    : '#' for 'walls' so I was just wondering if there was a way to do
    : that? If anyone needs any more information on what it is that I'm
    : exactly trying to do, feel free to reply.
    : Many Thanks.
    : ~Dan
    :

    There's no need to define each "#" character position since you loading it from a file, so you could look up that character in the map directly to check for a certain position. For example if you have a 80x25 text screen, then a corresponding text map would be 82x25=2050 byte long. (including the CR+LF character pair at the end of each line). Open this text file as a typed file not a text (i.e. [b]var f:file of char;[/b]), to be able to read from any position, something impossible if you handling it as plain text. Let's say you want to find out if there is a wall element ("#") at screen position (x,y), use the following formula:[code](Assuming a plain text file: 80 character wide, 25 lines, CR+LF line terminators)

    position_in_file:=(y-1)*(x_size+2)+x-1

    y = y position on screen --> [1..25]
    x = x position on screen --> [1..80]
    x_size = 80 <-- screen width in characters

    So the code would be:

    function check_wall(x,y:byte):boolean;
    begin
    seek(f,(y-1)*82+x-1);
    read(f,ch);
    check_wall:=(ch='#');
    end;[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion