-5

I am building a part of a tower defense game in a strictly console environment and i am stuck at the moving of a creature lets say "c", i would like the letter "c" to start on the left and move a space at a time to the right on the same line basically:

c (one second later)

c (one second later)
c and so on....

i thought that this could be implimented with an array but am lost, i want to be able to use simple code, not weird libraries and weird methods, just simple as possible. Thank you

Zak
  • 934
  • 1
  • 9
  • 12
  • Using [string streams with padding](http://stackoverflow.com/questions/667183/padding-stl-strings-in-c) should do the trick, unless that counts as "weird libraries and weird methods". – Cory Kramer Oct 16 '14 at 19:03
  • Updating the terminal output is a non-trivial task that depends on the terminal you are using. I am fairly certain the simplest way to do this is using a "weird" library such as [curses](https://en.wikipedia.org/wiki/Curses_%28programming_library%29) – clcto Oct 16 '14 at 19:05
  • yes that would work but is there a way to loop it so it continuously moves? what i mean is say i have 10 creatures so 10 "c"s i need them to appear one after another and then go off the screen – Zak Oct 16 '14 at 19:06
  • If you're not on Windows, you can make your own weird library with weird methods that implement [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code) to move the cursor around. If you are on Windows, you can make your own weird library with weird methods that use the [console API](http://msdn.microsoft.com/en-us/library/ms682087.aspx). – indiv Oct 16 '14 at 19:34

1 Answers1

0

One method is display all the characters, then a carriage return ('\r') and then reprint the line.
This allows you to "walk" characters across. This will only work on video terminals that do not advance a line upon receiving a CR.

Another method would be to print 10 backspace characters, a space, then your 10 'c'. This may not be as fast as the carriage return method above, but worth looking at.

As others have said, you may want to look into a terminal library such as ncurses. The library allows you to position the cursor on the screen, based on the terminal type. This may require setting up the console window to emulate a terminal.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154