Solved

Game Programming Output

Posted on 2000-04-12
14
204 Views
Last Modified: 2010-04-02
How can i ouput stuff with out refreshing the screen and reouput... (SPACE INVADERS) No Graphics, all text based!!!
0
Comment
Question by:cdc_sickle
  • 8
  • 6
14 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
Comment Utility
Standard C++ doesn't provide any mechanism for doing this.  Standard C++ doesn't even assume you are outputing to a display.  All it assumes is that standard output is some sort of text-based device, but that device could be a teletype, a text file, a brail reader etc.  

So there is no way in standard C++ to "refresh" the screen.

However there are likely to be ways to do this that are dependant on your hardware or you Operating System.  

For example, in Windows you can use the WriteConsoleOutout() function (and other functions) to do this sort of thing.   In UNIX you can use the curses library to do this.  I DOS you can use the DOS video services to do this etc...

So we need to know what OS and possibly what hardware you are using.
0
 

Author Comment

by:cdc_sickle
Comment Utility
Ok, this operating system im working on is Windows 95. its a 486 (yuk) No graphics card, well, no good one... So no support for like directx and stuff... It has dos prompt and stuff. And im working in Turbo C++ 4.5

The other system(s) i can use are my home systems! p3 450 voodoo3
all the good stuff, but im not that good at programming. I want to keep it simple as possible...
0
 

Author Comment

by:cdc_sickle
Comment Utility
By the way, my home system has borland builder 1.0, win98
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Turbo C++ produces DOS programs, so you can write directly to the video adapter's memory.  Or you can use the non-statnd function GotoXY() which Borland usually supplies with its products.

for Builder you have to create windows console program (not DOS) and use WriteOuput().  

These are two very different techniques, you probably should for decide which platform you want to work with, then we can go from there.  (It is possible to do both platforms, but that is a lot more work.)
0
 

Author Comment

by:cdc_sickle
Comment Utility
Turbo C++ Since that is what im supposed to work in :(
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Then look for a function called gotoxy().  It moves the cursor to the specified x/y coordinates on the display.  Then you can simply use printf() or cout to output the new information at the location (overwritting the old information)

You can refresh the entire screen by moving to (0,0) and then writting out an entire screenful of information.
0
 

Author Comment

by:cdc_sickle
Comment Utility
And this wont work in borland?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
Turbo C++ is borland, right?  

Anyways this should work for Turbo C++ (if the function is provided for you, I'm not sure that it is.)

This would also work in Builder, if the function was provided, but I don't think it is.   However, in Builder there are other ways to do it (that don't use this function.)

Can you find the function?   check your docs.  Scan your .h files.
0
 

Author Comment

by:cdc_sickle
Comment Utility
Ill look, what else for builder?
0
 

Author Comment

by:cdc_sickle
Comment Utility
What do you know, gotoxy exists and works like a charm... But i have to wait to see if it works right in turbo...
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
So where did you find it?  In Builder?  Its really not needed in builder since there are (better) alternatives in win32
0
 

Author Comment

by:cdc_sickle
Comment Utility
Yeah, i dont have turbo at home... What are the better alternatives in builder?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Windows has a a large selection of console functions.  These allow you to position the cursor (like Gotoxy() does (although it is called SetConsoleCursorPosition()), but also to do MANY more things.  There are functions for scrolling the display, functions for ouputing text in various colors, or for change the colors of existing text.  There are functions for controlling the size of the cursor, hiding the cursor.  There are functions for outputing text in various ways, and functions for getting input in various ways.  There are even functions for resizing the consoel so it has a different number of rows or columns.  Basically there is just a wealth of functions to do fance things in Win32.  Many of these things can also be done in DOS, but it is often harder.

Builder probalby has help on these functions, if you look up "consoles" in the help.  (VC does.)

You can also look up some of the functions:

SetConsoleCursorPosition()
SetConsoleCursorInfo()
SetConsoleTitle()
WriteConsole()
WriteConsoleOutput()
WriteConsoleOutputAttribute()
SetConsoleMode()  (Important for games)
SetConsoleTextAttribute()

And about 30 or 40 more....

0
 

Author Comment

by:cdc_sickle
Comment Utility
Works perfectly
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now