Damn tiles......hepp mee!

This is a discussion on Damn tiles......hepp mee! within the C++ Programming forums, part of the General Programming Boards category; I'm trying out tile engine making but it isn't working!?!?!?! Why o why.... (i know the code is sloppy i ...

  1. #1
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408

    Damn tiles......hepp mee!

    I'm trying out tile engine making but it isn't working!?!?!?!
    Why o why....


    (i know the code is sloppy i just wanted it to work)
    Code:
    #include <fstream.h>
    #include <stdlib.h>
    #include <dos.h>
    #include <stdio.h>
    #include <string.h>
    #include <conio.c>
    
    
    int tiles[16][26];
    int tile = 1;
    int row = 1;
    char filename[50];
    int px,py;
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    
    int main() {
    cout << "Filename: ";
    cin >> filename;
    ifstream in(filename);
    char temp[200];
    
    while(row!=17){
       cout << in.tellg();
       for(int tnr = 1;tnr!=25;tnr++){
          in >> tiles[row][tnr];
       }
       row++;
    }
    
    tile = 1;
    row = 1;
    clrscr();
    
    while(row != 16 || tile != 25){
       switch(tiles[row][tile]){
          case 1:
          SetConsoleTextAttribute(hStdout,  BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN);
          cout << " ";
          break;
          case 2:
          SetConsoleTextAttribute(hStdout, BACKGROUND_GREEN);
          cout << " ";
          break;
          case 3:
          SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY | BACKGROUND_GREEN);
          cout << "$";
          break;
       }
    
       if(tile!=25) {
          tile++;
       }
       else
       {
          if(row!=16) {
             tile = 1;
          }
       row++;
       textbackground( BLACK );
       textcolor(LIGHTGRAY);
       }
    }
    
    char ch[20];
    px = 5;
    py = 5;
    while(strcmp(ch,"exit")!=0) {
       gotoxy(px,py);
       SetConsoleTextAttribute(hStdout, FOREGROUND_RED|BACKGROUND_GREEN);
       cout << "X";
       gotoxy(5,22);
       SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|BLACK);
       cout << "                                                       ";
       gotoxy(5,22);
       cout << "Go <n>orth, <s>out, <w>est, <e>ast or <exit>: ";
       cin.clear();
       ch = getch();
       gotoxy(px,py);
       SetConsoleTextAttribute(hStdout, FOREGROUND_RED|BACKGROUND_GREEN);
       cout << " ";
       if(strcmp(ch,"n")==0) {
          py-=1;
       } else if(strcmp(ch,"s")==0) {
          py+=1;
       } else if(strcmp(ch,"w")==0) {
          px-=1;
       } else if(strcmp(ch,"e")==0) {
          px+=1;
       }
    
    }
    
    }

    EDIT:: i do not know why i have included dos.h...
    Last edited by ErionD; 04-10-2002 at 11:00 PM.

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Oooh, boy. Try using code tags? [ c o d e ] and end with [ / c o d e ], 'cept without spacing. Makes things much nicer to read. (You can edit your post and add them.)

    Then; What is the problem? Whats going wrong? I'm not going to read all that code without knowing what i'm looking for. I could try to run it but i'm only here to take a break from debugging my own app.

    >>Damn tiles......hepp mee!

    Always here to hepp.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    ...and please use a hiearchical layout like this:
    Code:
    if(tile != 25)
    {
       tile++;
    }
    else
    {
       if(row != 16) 
       {
          tile = 1;
       }
    }
    instead of this:
    Code:
    if(tile!=25) {
    tile++;
    }
    else
    {
    if(row!=16) {
    tile = 1;
    }
    }
    It makes it much easier to read ...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    I'm, sorry i didn't post my errors i wasn't in a very good mood =)
    And there ARE code tags. Where did you look for them?

    I don't get any compiler errors but when i run it and it comes to the Go north blablabla...... the screen goes into an eternal loop, always printing out the go north thing.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    22
    LoL hmm ur first post was "Last edited by ErionD on 04-11-2002 at 06:00 AM"

    and the post u just made was at 05:54 AM on 4-11-2002.

    So six minutes after you made this post about how u did include code tags, you edited something in your first post.

    Wonder what it was?

    :>
    - Visual C++, Adobe Photoshop -

  6. #6
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    It was

    EDIT:: i do not know why i have included dos.h...

    Read the next time =P

  7. #7
    Unregistered
    Guest
    you are overwriting the array during the following loop:

    while(row!=17){
    cout << in.tellg();
    for(int tnr = 1;tnr!=25;tnr++){
    in >> tiles[row][tnr];
    }
    row++;
    }


    since tiles is declared as thus:

    int tiles[16][26];

    meaning tiles[17][] does not exist,

    row should range from 0 to 16 and tnr from 0 to 25. Unless you intend to keep all row 0 andall column tnr 0 open for some reason (if you never call on those indices before you initialize them that should be okay, as long as you know you are doing it.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Damn ATI!
    By AloneInTheDark in forum Tech Board
    Replies: 48
    Last Post: 02-16-2008, 08:34 PM
  2. Hexagonal vs square tiles
    By OnionKnight in forum Game Programming
    Replies: 2
    Last Post: 04-26-2007, 08:46 PM
  3. text on 2d tiles in DirectX?
    By Quantum1024 in forum Game Programming
    Replies: 4
    Last Post: 04-26-2006, 11:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21