Hello,
I am making a 2d shooter game, and I dont knnow how to make the player's ship move left and right
with left and right arrow keys... please help me. I have to finish this project before 6th... please help

What have you got so far? What libraries are you using for I/O (Win32API/SDL/SFML/etc)?

Typically you will use your I/O library to poll for events, then detect the arrow key events and use them to modify a variable that holds the ship's position. How this is done varies by library, so we will need to know more about what you have already tried in order to help you.

Well i havent made the game screen yet, i came here because i have no idea how to do it, i searched and searched but could not find anything.

i am using codeblocks btw.

its graphicless

*if ur going to ask why am i doing it when i dont know?
answer:- OUR computer teacher does not teach us anything, she keeps on giving projects and tells us to find the solution ourselves.

Well, you cannot expect that you are going to learn something by osmosis - you have to experiment and try for yourself. That does not excuse an incompetent teacher, of course.

Otherwise, you still have not mentioned a system. Linux? Windows?

Are you provided any existing code (or libraries)? Suggestions of what would be best to use?

i use windows 7, i have been searching but unable to find anything! if i do find it shows errors.

no code or libs have been provided

alright so i found this but this is showing me many errors.
code:-

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()

{

bool game_running(true);

char key;

do{

}

while(game_running)


     {

       // SECTION: get player input

     if (kbhit())

        {

            // get keyboard data, and filter it

        key = toupper(getch());



        // is player trying to exit, if so exit

        if (key=='Q' || key==27)

           game_running = 0;



        // is player moving left

        if (key=='A')

           player_x--;



        // is player moving right

        if (key=='S')

           player_x++;



        } // end if



     Draw_String(rand()%80, SCROLL_POS,".\n");



     // draw player



     Draw_String(player_x,0,"<-*->");

     Draw_String(0,0,"");



     // SECTION: synchronize to a constant frame rate

     Sleep(40);

return 0;

     } // end while

ATLAST I SOLVED THE PROBLEM. But i need help in one small thing now.
In the code below what i want is that, we are able to press enter when the arrow is next to any of those options, and when we press a new screen is shows.. please help

 do
    {
        ch = getch();

        switch(ch)
        {
            case 'W':
            case 'w':
                system("CLS");
                cout<<"                                                 MOD v1.0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
                cout << "                                                    --> PLAY\n\n";
                cout<<"                                                        HELP\n\n";
                cout<<"                                                        EXIT\n\n";
                break;
            case 'E':
            case 'e':
                system("CLS");
                cout<<"                                                 MOD v1.0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
                cout << "                                                        PLAY\n\n";
                cout<<"                                                    --> HELP\n\n";
                cout<<"                                                        EXIT\n\n";
                break;
            case 'R':
            case 'r':
                system("CLS");
                cout<<"                                                 MOD v1.0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
                cout << "                                                        PLAY\n\n";
                cout<<"                                                        HELP\n\n";
                cout<<"                                                    --> EXIT\n\n";
                break;

        }

    }while (ch != 'Q' && ch!='q');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.