Page principale | Hiérarchie des classes | Liste des classes | Liste des fichiers | Membres de classe | Membres de fichier

entree_clavier.cpp

Aller à la documentation de ce fichier.
00001 00002 // Shoot(r) 00009 00010 #include "ctrl_fenetre.h" 00011 #include "entree_clavier.h" 00012 00013 CEntreeClavier::CEntreeClavier (unsigned short unPositionX, unsigned short unPositionY) 00014 { 00015 m_unPositionX = unPositionX; 00016 m_unPositionY = unPositionY; 00017 m_bTirer = false; 00018 m_bHaut = false; 00019 m_bBas = false; 00020 m_bGauche = false; 00021 m_bDroit = false; 00022 m_Timer.Init (); 00023 } 00024 00025 void CEntreeClavier::Event (SDL_KeyboardEvent *pEvent) 00026 { 00027 switch (pEvent->type) 00028 { 00029 default: 00030 break; 00031 // Evénement produit quand le joueur relache une touche 00032 case SDL_KEYUP: 00033 if (pEvent->keysym.sym == SDLK_SPACE 00034 || pEvent->keysym.sym == SDLK_KP_ENTER 00035 || pEvent->keysym.sym == SDLK_KP0) 00036 m_bTirer = false; 00037 else if (pEvent->keysym.sym == SDLK_KP8 00038 || pEvent->keysym.sym == SDLK_UP) 00039 m_bHaut = false; 00040 else if (pEvent->keysym.sym == SDLK_KP2 00041 || pEvent->keysym.sym == SDLK_DOWN) 00042 m_bBas = false; 00043 else if (pEvent->keysym.sym == SDLK_KP6 00044 || pEvent->keysym.sym == SDLK_RIGHT) 00045 m_bDroit = false; 00046 else if (pEvent->keysym.sym == SDLK_KP4 00047 || pEvent->keysym.sym == SDLK_LEFT) 00048 m_bGauche = false; 00049 break; 00050 // Evénement produit quand le joueur presse une touche 00051 case SDL_KEYDOWN: 00052 if (pEvent->keysym.sym == SDLK_SPACE 00053 || pEvent->keysym.sym == SDLK_KP_ENTER 00054 || pEvent->keysym.sym == SDLK_KP0) 00055 m_bTirer = true; 00056 else if (pEvent->keysym.sym == SDLK_KP8 00057 || pEvent->keysym.sym == SDLK_UP) 00058 m_bHaut = true; 00059 else if (pEvent->keysym.sym == SDLK_KP2 00060 || pEvent->keysym.sym == SDLK_DOWN) 00061 m_bBas = true; 00062 else if (pEvent->keysym.sym == SDLK_KP6 00063 || pEvent->keysym.sym == SDLK_RIGHT) 00064 m_bDroit = true; 00065 else if (pEvent->keysym.sym == SDLK_KP4 00066 || pEvent->keysym.sym == SDLK_LEFT) 00067 m_bGauche = true; 00068 break; 00069 } 00070 } 00071 00072 // Détermine la position du joueur sur l'écran en s'assurant qu'il ne sorte pas de l'écran 00073 CVecteur CEntreeClavier::GetPosition () 00074 { 00075 if (m_Timer.GetTime () > 0.01f) 00076 { 00077 m_Timer.Init (); 00078 00079 // Déplacement suivant les touches pressés 00080 if (m_bHaut) 00081 m_unPositionY += CLAVIER_VITESSE_DEPLACEMENT; 00082 if (m_bBas) 00083 m_unPositionY -= CLAVIER_VITESSE_DEPLACEMENT; 00084 if (m_bGauche) 00085 m_unPositionX -= CLAVIER_VITESSE_DEPLACEMENT; 00086 if (m_bDroit) 00087 m_unPositionX += CLAVIER_VITESSE_DEPLACEMENT; 00088 00089 // Contrôle la position du joueur sur l'écran 00090 if (m_unPositionY > (FENETRE_HAUTEUR - 32)) 00091 m_unPositionY = FENETRE_HAUTEUR - 32; 00092 if (m_unPositionY < (0 + 32)) 00093 m_unPositionY = 0 + 32; 00094 if (m_unPositionX > (FENETRE_LARGEUR - 32)) 00095 m_unPositionX = FENETRE_LARGEUR - 32; 00096 if (m_unPositionX < (0 + 32)) 00097 m_unPositionX = 0 + 32; 00098 } 00099 00100 return CVecteur (m_unPositionX, m_unPositionY); 00101 } 00102

Généré le Sun Sep 26 11:36:46 2004 pour Shoot(r) par doxygen 1.3.8