PACMAN_part_3_0
Dependencies: mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI
Diff: main.cpp
- Revision:
- 1:b7df0d9d1d9c
- Parent:
- 0:8515b04f8da2
- Child:
- 2:63af55274d70
--- a/main.cpp Thu Jan 19 12:31:37 2017 +0000 +++ b/main.cpp Thu Jan 19 13:47:01 2017 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "LCD_DISCO_F469NI.h" +#include "TS_DISCO_F469NI.h" +TS_DISCO_F469NI ts; LCD_DISCO_F469NI lcd; DigitalOut led1(LED1); @@ -11,6 +13,12 @@ int16_t pacmanSize = 64; int16_t pacGumSize = 10; uint8_t i; + uint16_t x, y; + uint32_t color; + TS_StateTypeDef TS_State; + + ts.Init(lcd.GetXSize(), lcd.GetYSize()); + color = LCD_COLOR_YELLOW; start: @@ -24,7 +32,7 @@ wait(1); /* emplacement initial du pacman */ - pacmanCenter.X = pacmanSize; + pacmanCenter.X = pacmanSize + 10; pacmanCenter.Y = lcd.GetYSize() / 2; @@ -36,9 +44,13 @@ /* boucle d'animation */ do - { + { + /* on efface le pacman */ + lcd.SetTextColor(LCD_COLOR_BLACK); + lcd.FillCircle(pacmanCenter.X - 10, pacmanCenter.Y, pacmanSize); + /* dessine un rond jaune */ - lcd.SetTextColor(LCD_COLOR_YELLOW); + lcd.SetTextColor(color); lcd.FillCircle(pacmanCenter.X, pacmanCenter.Y, pacmanSize); /* dessine la bouche (triangle noir) */ @@ -54,17 +66,26 @@ lcd.SetTextColor(LCD_COLOR_BLACK); lcd.FillPolygon(trianglePoint, 3); + ts.GetState(&TS_State); + if (TS_State.touchDetected) { + x = TS_State.touchX[0]; + y = TS_State.touchY[0]; + if ((abs(x - pacmanCenter.X) < 50) & (abs(y - pacmanCenter.Y) < 50)) { + if (color == LCD_COLOR_YELLOW) + color = LCD_COLOR_BLUE; + else + color = LCD_COLOR_YELLOW; + } + } + /* on attend un peu */ wait(0.02); - /* on efface le pacman */ - lcd.SetTextColor(LCD_COLOR_BLACK); - lcd.FillCircle(pacmanCenter.X, pacmanCenter.Y, pacmanSize); - /* on se prepare a deplacer le pacman */ pacmanCenter.X += 10; + } while (pacmanCenter.X + pacmanSize < lcd.GetXSize()); - /* on arrete l'animation quand le pacman atteint le bord de l'ecran */ + /* on continue tant que le pacman n'a pas atteint le bord de l'ecran */ /* Affiche le texte */ lcd.DisplayStringAt(0, LINE(20), (uint8_t *)"THE END", CENTER_MODE);