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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
bool CMoteur::Jeu(void)
{
// program main loop
bool done = false;
bool Pressed = false;
while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;
// check for keypresses
case SDL_KEYDOWN:
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
Pressed = true;
break;
case SDL_KEYUP:
Pressed = false;
break;
} // end switch
} // end of message processing
// DRAWING STARTS HERE
if (Pressed)
{
if (event.key.keysym.sym == SDLK_UP)
{
oTux.y -= 3;
if (oTux.collision(oArbre)) {
texte = TTF_RenderText_Solid( font, "Trop forte!!!", textColor );
apply_surface( SCREEN_WIDTH/2-100, SCREEN_HEIGHT/2-75, texte, affichage,NULL );
actualiser();
SDL_Delay( 2000 );
//oArbre.y -= 3;
if(oArbre.detection_bord()){ deplacementArbre();}
}
}
else if (event.key.keysym.sym == SDLK_DOWN)
{
oTux.y += 3;
if (oTux.collision(oArbre)) {
oArbre.y += 3;
if(oArbre.detection_bord()) deplacementArbre();
}
}
else if (event.key.keysym.sym == SDLK_LEFT)
{
oTux.x -= 3;
if (oTux.collision(oArbre)){
oArbre.x -= 3;
if(oArbre.detection_bord()) deplacementArbre();
}
}
else if (event.key.keysym.sym == SDLK_RIGHT)
{
oTux.x += 3;
if (oTux.collision(oArbre)) {
oArbre.x += 3;
if(oArbre.detection_bord()) deplacementArbre();
}
}
/*Mouvement de l'arbre*/
else if (event.key.keysym.sym == SDLK_e)
{
oArbre.y -= 3;
/*if (oTux.collision(oArbre)) {
oArbre.y -= 3;
if(oArbre.detection_bord()) deplacementArbre();
}*/
}
else if (event.key.keysym.sym == SDLK_d)
{
oArbre.y += 3;
/*if (oTux.collision(oArbre)) {
oArbre.y += 3;
if(oArbre.detection_bord()) deplacementArbre();
}*/
}
else if (event.key.keysym.sym == SDLK_s)
{
oArbre.x -= 3;
/*if (oTux.collision(oArbre)){
oArbre.x -= 3;
if(oArbre.detection_bord()) deplacementArbre();
}*/
}
else if (event.key.keysym.sym == SDLK_f)
{
oArbre.x += 3;
/*if (oTux.collision(oArbre)) {
oArbre.x += 3;
if(oArbre.detection_bord()) deplacementArbre();
}*/
}
apply_surface( 0, 0, background, affichage,NULL );
apply_surface( oArbre.x, oArbre.y, arbre, affichage,NULL );
oTux.detection_bord();
apply_surface( oTux.x,oTux.y, Tux, affichage, NULL);
actualiser();
}
} // end main loop*/
return true;
} |
Partager