-
Making control...
Now, this is my problem, and I was wondering, is there a way that the following can be done???
1) My plan is to make a small console program, where you have a space craft moving about the screen, but the problem is the control. My idea was to do this to make up movement (the other directions I haven't programmed in yet)...
My idea was that I could make a basic space craft using ASCII letters (space craft not the finished product), now, the way I was going to do the control bit was to make it so that it printed an empty new line above the picture, therefore making it drop a line, also, for moving up, I was thinking of making it so that it printed a line above itself so that the space craft looked like it was moving down. This idea would then be expanded on horizontal directions, and so give control, but the problem is making it do that...
Code:
system ("cls");
cout << "" << endl;
cout << " | A |" << endl;
cout << " | A A |" << endl;
cout << " AAAAAA" << endl;
cin >> a;
if(a == 1)
{
cout << "" << endl; \\This line of code needs to be
\\shown above the space craft
}
else if(a == 2)
{
}
I no, this is a tall order, but r there any ideas
-
I make no guarantees as to whether this will work for you, I made two big assumptions about your system and compiler. :)
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;
void gotoxy ( short x, short y )
{
COORD coord = {x, y};
SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}
void draw_ship ( short x, short y )
{
gotoxy ( x, y );
cout<<"| |";
gotoxy ( x, ++y );
cout<<"|=[@]=|";
gotoxy ( x, ++y );
cout<<" ^ ";
}
void redraw ( short x, short y )
{
system ( "cls" );
draw_ship ( x, y );
}
int main()
{
short x = 10, y = 10;
while ( y > 0 && y < 17 && x > 0 && x < 20 ) {
redraw ( x, y );
switch ( getch() ) {
case 'w': --y; break;
case 's': ++y; break;
case 'a': --x; break;
case 'd': ++x; break;
}
}
}
-
sorry, but I having a bit of difficulty making it so that you can shoot on the game... I need tips/helpful advice/example code/hyperlinks etc...
:)