tutorial or book in how to implement those librariers and how to start the loop and that stuff......
The loop itself is a simple thing composed of complex steps: from
http://en.wikipedia.org/wiki/Game_programming#Game_structurewhile( user doesn't exit )
check for user input
run AI
move enemies
resolve collisions
draw graphics
play sounds
end while
Look for individual resolutions for all these things, then put them all together. If you are doing Java, I'm sure someone can point you to individual things for everything (or a library and specific instructions for each part). Figure out solutions for each part, get a basic something working, then refine it. Quick, ugly example:
int playerxpos = 10;
int playerypos = 10;
int enemyxpos = 15;
int enemyypos = 15;
struct inputmanager {...} maininput; //holds the keyboard/mouse status from inputs
void refreshinput(inputmanager input); //clears and grabs new input from events
bool handleinput(inputmanager input) //remember, I said it was ugly
{
if (input.RIGHTARROW)
{playerxpos++; return true;}
if (input.LEFTARROW)
{playerxpos--; return true;}
if (input.DOWNARROW)
{playerypos--; return true;}
if (input.UPARROW)
{playerypos++; return true;}
return false; //no input
}
bool checkcollision(int obj1x, int obj1y, int obj2x, int obj2y); //assume its done here: if x == x and y == y, simple
void moveenemy(); //AI for enemy, assume it does this: moves x - 1 at a time till it reaches 0, then turns around and goes x++ till it reaches 20
void drawpixel(int locx, int locy, unsigned int color); //color corresponds to a premade type, however you handle it with your library
void playsound(unsigned int soundtype);
void delay(unsigned int delaytime);
enum GAMESTATE {GAME_RUNNING, GAME_OVER};
enum COLORTYPES {COLOR_RED, COLOR_BLUE};
enum SOUNDTYPES {SOUND_MOVE, SOUND_DIE};
unsigned int gamestate = GAME_RUNNING;
//loop:
bool playermoved = false;
while (gamestate == GAME_RUNNING)
{
refreshinput(maininput); //resets input and grabs fresh input events
playermoved = handleinput(maininput); //moves player
if (playermoved)
moveenemy(); //moves the enemy only when player moves
if (checkcollision(playerxpos, playerypos, enemyxpos, enemyypos)) //handle collisions
gamestate = GAME_OVER; // touch it and you lose
drawpixel(playerxpos, playerypos, COLOR_BLUE);
drawpixel(enemyxpos, enemyypos, COLOR_RED);
if (playermoved)
playsound(SOUND_MOVE);
if (gamestate == GAME_OVER)
playsound(SOUND_DIE);
delay(1000); // delay 1000 milliseconds
}
///game over, do outro code, kill everything used, etc
Using just something like this and console printing and clearing you could make something, like:
printgamescreen()
{
clearscreen(); //clear your console however you do it
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
if (i == playerposx && j == playerposy)
printout('@');
else if (i == enemyposx && j == enemposy)
printout('E');
else
printout(' ');
}
printout('\n'); //newline character, end the block
}
}
and get this:
______________________
@
E
___________________
Anyway, there are good resources out there whatever you try, just remember its all a bunch of individual steps.