c++ game project

hello, im trying to make a simple 2d game and i have some questions, first how can i make that the person who plays the game doesnt hit enter, another question, how can make that i the game plays normally i mean that i dont have to output the screen more then once... also how to first output the text then color it?
first how can i make that the person who plays the game doesnt hit enter,

Eh... ask the user nicely?

how can make that i the game plays normally i mean that i dont have to output the screen more then once..

What's that supposed to mean?

also how to first output the text then color it?

Print the text again, this time with the right color. Either that or change the color of the pixels afterwards.
Begginer wrote:
how can make that i the game plays normally i mean that i dont have to output the screen more then once..
Athar wrote:
What's that supposed to mean?


I guess he is having a misconception that a game's screen (Board, map, whatever you want to call it) is only output only once and every time else it is just changed!

You do that by clearing the whole screen (I assume you are using the console?), make the changes on the map, and the output it again
first how can i make that the person who plays the game doesnt hit enter,
Eh... ask the user nicely?

lolz, i mean to how to get input without the user hitting enter
Begginer wrote:
how can make that i the game plays normally i mean that i dont have to output the screen more then once..
Athar wrote:
What's that supposed to mean?


I guess he is having a misconception that a game's screen (Board, map, whatever you want to call it) is only output only once and every time else it is just changed!

You do that by clearing the whole screen (I assume you are using the console?), make the changes on the map, and the output it again

well thats what i am asking, example: pacman, they dont clean the whole screen and edit and print it again.... also in pacman user doesnt hit enter after every,w,a,s,d move. i want that too...
also how to first output the text then color it?

Print the text again, this time with the right color. Either that or change the color of the pixels afterwards.

what im asking,how to make a change in the already existing text, i dont want to print it more then once...
Last edited on
You'll have to use a graphics package that allows an event loop to be running and provides for blitting sprites onto the screen to do what you want. If you don't know what those things are, you'll need to learn it all (and more) before you can code a 2-D game like you described. There are near infinite websites that teach all this stuff. Start googling and reading because there are no easy answers to the questions you asked. You have to learn it from the bottom up...
You may be interested in SFML (http://www.sfml-dev.org/). It has everything cnoeval described, and more. It is very easy to install, learn and use. The documentation and tutorials on the website have everything you will need to know:)
Begginer wrote:
pacman, they dont clean the whole screen and edit and print it again

They do. It just doesn't seen so because it happens at such an extreme speed!
i dont want sprites i will use something like this " O- " a man with a gun or something so if u could just tell me some command i said i am a beginner....
----
also i know that it is possible because my friend that is better then me made a game, he made a menu and using w,a,s,d you could choose start, help, quit....
in menu he made that he first couts letters then colors it, i want to know how, he wont tell me...
also in the game, he doesnt couts the whole screen more then once... he makes changes within the screen, i think he is using some coords...
Last edited on
If you are programming in the console, then there is no way to do so.
You need SFML, or any other graphics library.
There is no direct function to add a sprite and make it move and so on.

About changing the Colour:
http://www.cplusplus.com/forum/general/50955/#msg276917

This is windows specific though...

Taking input without pressing Enter is also OS specific, so here is another thread about it:
http://www.cplusplus.com/forum/general/47820/
Last edited on
i just found a GetAsyncKeyState, can u explain that to me?
I suggest you use the function Douas told me in the above linked thread:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int readkey()
  {
  HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );
  DWORD  mode;
  GetConsoleMode( hstdin, &mode );
  SetConsoleMode( hstdin, 0 );

  INPUT_RECORD inrec;
  DWORD        count;

  do ReadConsoleInput( hstdin, &inrec, 1, &count );
  while ((inrec.EventType != KEY_EVENT) || inrec.Event.KeyEvent.bKeyDown);

  SetConsoleMode( hstdin, mode );

  return inrec.Event.KeyEvent.wVirtualKeyCode;
  }


Using GetAsyncKeyState is definitely more complex than you think.
It works by checking if any key is pressed down on the keyboard.
To use it you will have to use call it four times and check for the four character codes.

You can use the above function as:
1
2
char x;
x = readkey();

This will that input of any key you press and return its ASCII code, which will be converted into a character for x.

Then you can check for whether x is "w" or "s" or "a" or "d".

Here's the MSDN documentation on the GetAsyncKeyState:
http://msdn.microsoft.com/en-us/library/ms929204.aspx
thanks for that :D and yes i know its complex i tried to find it several times, maybe in the future i will understand it
---
can u just give me some includes about that?
Last edited on
includes about that ??? What does that mean.

Also, I know you've been told it a million times already, but using a multimedia/graphics package really is a lot easier than Windows (or any other OS) programming, not to mention the fact that it means it isn't platform specific.
Do you mean <windows.h>?
i have a problem about this, can you help?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <windows.h>
int readkey();
using namespace std;

int main()
{
    char c;
    c= readkey();
    if (c=='a')
    cout << ":D";
    if (c=='b')
    cout << ":P";
    cin.get();
    return 0;
}
int readkey()
  {
  HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );
  DWORD  mode;
  GetConsoleMode( hstdin, &mode );
  SetConsoleMode( hstdin, 0 );

  INPUT_RECORD inrec;
  DWORD        count;

  do ReadConsoleInput( hstdin, &inrec, 1, &count );
  while ((inrec.EventType != KEY_EVENT) || inrec.Event.KeyEvent.bKeyDown);

  SetConsoleMode( hstdin, mode );

  return inrec.Event.KeyEvent.wVirtualKeyCode;
  }
And what's the problem?
Really, beginner, you're doing things the hard way and making things more difficult for yourself than they have to be.

Seriously.

Get a graphics lib. Making games in the console is retarded.

Obligatory link:
http://cplusplus.com/forum/articles/28558/
Topic archived. No new replies allowed.