Results 1 to 7 of 7
  1. #1
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool

    Drawing something in console by x,y

    Hi all, since tomorrow i have an exam of C++ at school, i'm writing some functions and programms to take practice... I think that this class i'm sharing will be usefull to someone... It's a class with function used to draw something u want in the console by giving the x and y coordinates... It's easy to use i used it in a game created by me to move by keyboard a little character enjoy

    Code:
    class Coords{ public: int x,y;};
    
    class Piano{ public: Coords punto;	//give the x,y coords of the point
    					void DrawPoint(int spazio);//self explanatory xD
    					char* symbol;//the symbol you want to draw
    };
    
    void Piano::DrawPoint(int spazio)
    {
    	
    		for(int j=0; j<punto.y; j++)
    			cout<<"\n";
    		for(int j=0; j<punto.x; j++)
    			cout<<" ";
    		cout<<symbol;
    
    		for(int i=0; i<spazio; i++)
    			cout<<endl;
    }
    
    int main()
    {	
    	Piano a;
    
    	a.punto.x = 110;
    	a.punto.y = 210;
    	a.symbol = "X";
    
    	a.DrawPoint(5);
    
    	
    	system("pause");
    
    	return 0;
    }
    The source has got the main function as test of the classes
    Last edited by Sixx93; 04-05-2011 at 05:56 AM.

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    SetConsoleCursorPosition() is way easier ^^

    And you don't have to write blank spaces.

    Image if you want to draw 2 Dots... You will probably overwrite the other one with a blank space

    https://www.mpgh.net/forum/31-c-c-pro...console-c.html
    ~Example of use on the above one.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. The Following 3 Users Say Thank You to 'Bruno For This Useful Post:

    Hell_Demon (04-05-2011),Stephen (04-05-2011),whit (04-05-2011)

  4. #3
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by Brinuz View Post
    SetConsoleCursorPosition() is way easier ^^

    And you don't have to write blank spaces.

    Image if you want to draw 2 Dots... You will probably overwrite the other one with a blank space

    https://www.mpgh.net/forum/31-c-c-pro...console-c.html
    ~Example of use on the above one.
    i didn't know that function xD anyway, to evade the problem of overwrite, i used system("cls"); in a loop
    Last edited by Sixx93; 04-05-2011 at 09:20 AM.

  5. #4
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by Sixx93 View Post
    i didn't know that function xD anyway, to evade the problem of overwrite, i used system("cls"); in a loop
    But that will clear the whole console
    If you want 2 Dots or 3.. or 4. At the same time. You might have Problems, if you know what i mean.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  6. #5
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by Brinuz View Post
    But that will clear the whole console
    If you want 2 Dots or 3.. or 4. At the same time. You might have Problems, if you know what i mean.
    yes, i understand, but look what i mean

    virus scans:
    1- VirusTotal - Free Online Virus, Malware and URL Scanner

    2- Game.rar MD5:6cde390d90ae178a42b44c3c3e2b95c7 - VirSCAN.org Scanners did not find malware!




  7. #6
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Can't download tho..

    But i guess you are Cleaning the Console Screen, then re-writing all again? right?
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  8. #7
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by Brinuz View Post
    Can't download tho..

    But i guess you are Cleaning the Console Screen, then re-writing all again? right?
    yes, something like that xD