• Basic ascii graphics in C++?
    14 replies, posted
I really need a snippet for a ASCII graphics engine. As i am making a game in C++. Using nothing but the standard namespace and and the iostream thing. I would really appreciate if it included a collision detection system. Thanks. Ok, now i got the 2d array shit, but what the fuck did i do wrong here? [code] #include <iostream> using namespace std; char lolscr[30][30]; int displayshit(){ system("cls"); cout << lolscreen; } int dispimage(int id){ if(id = 1){ lolscr[1][2] = "T"; lolscr[3][2] = "E"; lolscr[5][2] = "S"; lolscr[7][2] = "T"; displayshit(); } } int main(){ cout << "Hello world, \n i like pie. \n"; system("pause"); cout << "\nWich command to execute? \nCmd command:"; char command[100]; cin >> command; system(command); system("pause"); cout << "\n" << "Enough for the crapcode, time for some GAME!!! \n"; system("pause"); system("cls"); dispimage(1); system("pause"); return 0; } [/code] It said: [code] ------ Build started: Project: Project_Onfive, Configuration: Debug Win32 ------ Compiling... game.cpp c:\documents and settings\david\skrivebord\cppstuff\onfenv\project_onfive\project_onfive\game.cpp(8) : error C2065: 'lolscreen' : undeclared identifier c:\documents and settings\david\skrivebord\cppstuff\onfenv\project_onfive\project_onfive\game.cpp(13) : error C2440: '=' : cannot convert from 'const char [2]' to 'char' There is no context in which this conversion is possible c:\documents and settings\david\skrivebord\cppstuff\onfenv\project_onfive\project_onfive\game.cpp(14) : error C2440: '=' : cannot convert from 'const char [2]' to 'char' There is no context in which this conversion is possible c:\documents and settings\david\skrivebord\cppstuff\onfenv\project_onfive\project_onfive\game.cpp(15) : error C2440: '=' : cannot convert from 'const char [2]' to 'char' There is no context in which this conversion is possible c:\documents and settings\david\skrivebord\cppstuff\onfenv\project_onfive\project_onfive\game.cpp(16) : error C2440: '=' : cannot convert from 'const char [2]' to 'char' There is no context in which this conversion is possible Build log was saved at "file://c:\Documents and Settings\David\Skrivebord\CPPstuff\OnfEnv\Project_Onfive\Project_Onfive\Debug\BuildLog.htm" Project_Onfive - 5 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== [/code]
Why don't you try writing one yourself? It's not a very complicated thing to do and it will give you valuable experience. Think of the screen as a grid, and have a 2 d arrayof ints (or use vectors) to store the character on the specific tile, then have a loop that redraws the screen based on the array. You could also have a look at curses which allows colors and placing characters at specific points, as well as some nice features such as drawing boxes and having isolated 'windows'.
I tryed, but for some reason forgot how to read and write and generally use more than 1D arrays. Then tryed to do some hack with some 1D array, where there was a \n on every 17'th. Didnt work, it thought it where some random undefined function, then it fucked with me on every little attempt i did to fix that. So umm, how do ya do 2d arrays? :buddy:
uhm lol [url]http://www.lmgtfy.com/?q=c%2B%2B+2d+arrays[/url]
Well a 2D array is a VERY basic thing and if you don't even know that or at least try to learn that, how would you handle the rest? I mean, come on, at least start with the arrays. Maybe you don't want to use classes or something, but a simple struct or array should really be standard. [code] char myascii[10][10] [/code]
Well, i havent been coding in two months, so my C++ is a bit rusty, thanks for the reminder.. [editline]04:04PM[/editline] Oh got it now. Now imma going to do my game :fuckyou:
Tip: You may find making this a lot more difficult that you first anticipate.
Chars go in 'a', strings go in "hello" cout <<field[a][b]; has to be used for arrays of characters.
Oh, ok. But the real problem is that it dosent know what i mean with assigment operators, and it thinks my array is a function, a undefined one. [editline]08:12AM[/editline] W/E, found a nice tut!!! [url]http://benryves.com/tutorials/?t=winconsole[/url] :D
[QUOTE=Killuah;17497561]Chars go in 'a', strings go in "hello" cout <<field[a][b]; has to be used for arrays of characters.[/QUOTE] I thought you could have arrays of any data types.
Actually you can, void is one. But you can use scoping or whatever its called too.
[QUOTE=iPope;17496535]Tip: You may find making this a lot more difficult that you first anticipate.[/QUOTE] As everything in programming it's not as easy as you first anticipated not even a Hello World.
[url]http://www.gnu.org/software/ncurses/[/url] Also your code is horrible, not only does it have obvious errors it also has stupid variable names, it is no wonder your getting confused. The windows console is also rather limited in my experience.
Oh I took his wording wrong. I thought he meant it only works with characters, rather than it's what has to be used for characters. I got the emphasis on the wrong bit.
Yeah, but that code was from before i readed that tutorial..
Sorry, you need to Log In to post a reply to this thread.