PACMAN_part_3_0
Dependencies: mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI
Diff: main.cpp
- Revision:
- 0:8515b04f8da2
- Child:
- 1:b7df0d9d1d9c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 19 12:31:37 2017 +0000 @@ -0,0 +1,82 @@ +#include "mbed.h" +#include "LCD_DISCO_F469NI.h" + +LCD_DISCO_F469NI lcd; +DigitalOut led1(LED1); + +int main() +{ + Point trianglePoint[3]; + Point pacmanCenter; + int16_t pacmanSize = 64; + int16_t pacGumSize = 10; + uint8_t i; + + start: + + /* Eteint la LED */ + led1 = 1; + + /* Efface ecran */ + lcd.Clear(LCD_COLOR_BLACK); + lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"! PACMAN !", CENTER_MODE); + + wait(1); + + /* emplacement initial du pacman */ + pacmanCenter.X = pacmanSize; + pacmanCenter.Y = lcd.GetYSize() / 2; + + + /* Dessine des pacgum */ + lcd.SetTextColor(LCD_COLOR_RED); + for (i = 0; i < 7; i++) { + lcd.FillCircle(i * 100 + pacGumSize, pacmanCenter.Y, pacGumSize); + } + + /* boucle d'animation */ + do + { + /* dessine un rond jaune */ + lcd.SetTextColor(LCD_COLOR_YELLOW); + lcd.FillCircle(pacmanCenter.X, pacmanCenter.Y, pacmanSize); + + /* dessine la bouche (triangle noir) */ + trianglePoint[0].X = pacmanCenter.X; + trianglePoint[0].Y = pacmanCenter.Y; + + trianglePoint[1].X = pacmanCenter.X + pacmanSize; + trianglePoint[1].Y = pacmanCenter.Y - pacmanSize; + + trianglePoint[2].X = pacmanCenter.X + pacmanSize; + trianglePoint[2].Y = pacmanCenter.Y + pacmanSize; + + lcd.SetTextColor(LCD_COLOR_BLACK); + lcd.FillPolygon(trianglePoint, 3); + + /* 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 */ + + /* Affiche le texte */ + lcd.DisplayStringAt(0, LINE(20), (uint8_t *)"THE END", CENTER_MODE); + + /* Clignotte la LED */ + for (i = 0; i < 10; i++) { + led1 = !led1; + wait(0.05); + } + + wait(1); + + /* on recommence */ + goto start; +}