PACMAN_part_3_0
Dependencies: mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI
main.cpp@2:63af55274d70, 2019-12-06 (annotated)
- Committer:
- fab2sn
- Date:
- Fri Dec 06 14:12:53 2019 +0000
- Revision:
- 2:63af55274d70
- Parent:
- 1:b7df0d9d1d9c
- Child:
- 3:7c9276127150
v1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fab2sn | 0:8515b04f8da2 | 1 | #include "mbed.h" |
fab2sn | 0:8515b04f8da2 | 2 | #include "LCD_DISCO_F469NI.h" |
fab2sn | 1:b7df0d9d1d9c | 3 | #include "TS_DISCO_F469NI.h" |
fab2sn | 0:8515b04f8da2 | 4 | |
fab2sn | 1:b7df0d9d1d9c | 5 | TS_DISCO_F469NI ts; |
fab2sn | 0:8515b04f8da2 | 6 | LCD_DISCO_F469NI lcd; |
fab2sn | 0:8515b04f8da2 | 7 | DigitalOut led1(LED1); |
fab2sn | 0:8515b04f8da2 | 8 | |
fab2sn | 0:8515b04f8da2 | 9 | int main() |
fab2sn | 0:8515b04f8da2 | 10 | { |
fab2sn | 0:8515b04f8da2 | 11 | Point trianglePoint[3]; |
fab2sn | 0:8515b04f8da2 | 12 | Point pacmanCenter; |
fab2sn | 0:8515b04f8da2 | 13 | int16_t pacmanSize = 64; |
fab2sn | 0:8515b04f8da2 | 14 | int16_t pacGumSize = 10; |
fab2sn | 0:8515b04f8da2 | 15 | uint8_t i; |
fab2sn | 1:b7df0d9d1d9c | 16 | uint16_t x, y; |
fab2sn | 1:b7df0d9d1d9c | 17 | uint32_t color; |
fab2sn | 1:b7df0d9d1d9c | 18 | TS_StateTypeDef TS_State; |
fab2sn | 1:b7df0d9d1d9c | 19 | |
fab2sn | 1:b7df0d9d1d9c | 20 | ts.Init(lcd.GetXSize(), lcd.GetYSize()); |
fab2sn | 1:b7df0d9d1d9c | 21 | color = LCD_COLOR_YELLOW; |
fab2sn | 0:8515b04f8da2 | 22 | |
fab2sn | 0:8515b04f8da2 | 23 | start: |
fab2sn | 0:8515b04f8da2 | 24 | |
fab2sn | 0:8515b04f8da2 | 25 | /* Eteint la LED */ |
fab2sn | 0:8515b04f8da2 | 26 | led1 = 1; |
fab2sn | 0:8515b04f8da2 | 27 | |
fab2sn | 0:8515b04f8da2 | 28 | /* Efface ecran */ |
fab2sn | 0:8515b04f8da2 | 29 | lcd.Clear(LCD_COLOR_BLACK); |
fab2sn | 2:63af55274d70 | 30 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"!! PACMAN !!", CENTER_MODE); |
fab2sn | 0:8515b04f8da2 | 31 | |
fab2sn | 0:8515b04f8da2 | 32 | wait(1); |
fab2sn | 0:8515b04f8da2 | 33 | |
fab2sn | 0:8515b04f8da2 | 34 | /* emplacement initial du pacman */ |
fab2sn | 1:b7df0d9d1d9c | 35 | pacmanCenter.X = pacmanSize + 10; |
fab2sn | 0:8515b04f8da2 | 36 | pacmanCenter.Y = lcd.GetYSize() / 2; |
fab2sn | 0:8515b04f8da2 | 37 | |
fab2sn | 0:8515b04f8da2 | 38 | |
fab2sn | 0:8515b04f8da2 | 39 | /* Dessine des pacgum */ |
fab2sn | 0:8515b04f8da2 | 40 | lcd.SetTextColor(LCD_COLOR_RED); |
fab2sn | 0:8515b04f8da2 | 41 | for (i = 0; i < 7; i++) { |
fab2sn | 0:8515b04f8da2 | 42 | lcd.FillCircle(i * 100 + pacGumSize, pacmanCenter.Y, pacGumSize); |
fab2sn | 0:8515b04f8da2 | 43 | } |
fab2sn | 0:8515b04f8da2 | 44 | |
fab2sn | 0:8515b04f8da2 | 45 | /* boucle d'animation */ |
fab2sn | 0:8515b04f8da2 | 46 | do |
fab2sn | 1:b7df0d9d1d9c | 47 | { |
fab2sn | 1:b7df0d9d1d9c | 48 | /* on efface le pacman */ |
fab2sn | 1:b7df0d9d1d9c | 49 | lcd.SetTextColor(LCD_COLOR_BLACK); |
fab2sn | 1:b7df0d9d1d9c | 50 | lcd.FillCircle(pacmanCenter.X - 10, pacmanCenter.Y, pacmanSize); |
fab2sn | 1:b7df0d9d1d9c | 51 | |
fab2sn | 0:8515b04f8da2 | 52 | /* dessine un rond jaune */ |
fab2sn | 1:b7df0d9d1d9c | 53 | lcd.SetTextColor(color); |
fab2sn | 0:8515b04f8da2 | 54 | lcd.FillCircle(pacmanCenter.X, pacmanCenter.Y, pacmanSize); |
fab2sn | 0:8515b04f8da2 | 55 | |
fab2sn | 0:8515b04f8da2 | 56 | /* dessine la bouche (triangle noir) */ |
fab2sn | 0:8515b04f8da2 | 57 | trianglePoint[0].X = pacmanCenter.X; |
fab2sn | 0:8515b04f8da2 | 58 | trianglePoint[0].Y = pacmanCenter.Y; |
fab2sn | 0:8515b04f8da2 | 59 | |
fab2sn | 0:8515b04f8da2 | 60 | trianglePoint[1].X = pacmanCenter.X + pacmanSize; |
fab2sn | 0:8515b04f8da2 | 61 | trianglePoint[1].Y = pacmanCenter.Y - pacmanSize; |
fab2sn | 0:8515b04f8da2 | 62 | |
fab2sn | 0:8515b04f8da2 | 63 | trianglePoint[2].X = pacmanCenter.X + pacmanSize; |
fab2sn | 0:8515b04f8da2 | 64 | trianglePoint[2].Y = pacmanCenter.Y + pacmanSize; |
fab2sn | 0:8515b04f8da2 | 65 | |
fab2sn | 0:8515b04f8da2 | 66 | lcd.SetTextColor(LCD_COLOR_BLACK); |
fab2sn | 0:8515b04f8da2 | 67 | lcd.FillPolygon(trianglePoint, 3); |
fab2sn | 0:8515b04f8da2 | 68 | |
fab2sn | 1:b7df0d9d1d9c | 69 | ts.GetState(&TS_State); |
fab2sn | 1:b7df0d9d1d9c | 70 | if (TS_State.touchDetected) { |
fab2sn | 1:b7df0d9d1d9c | 71 | x = TS_State.touchX[0]; |
fab2sn | 1:b7df0d9d1d9c | 72 | y = TS_State.touchY[0]; |
fab2sn | 1:b7df0d9d1d9c | 73 | if ((abs(x - pacmanCenter.X) < 50) & (abs(y - pacmanCenter.Y) < 50)) { |
fab2sn | 1:b7df0d9d1d9c | 74 | if (color == LCD_COLOR_YELLOW) |
fab2sn | 1:b7df0d9d1d9c | 75 | color = LCD_COLOR_BLUE; |
fab2sn | 1:b7df0d9d1d9c | 76 | else |
fab2sn | 1:b7df0d9d1d9c | 77 | color = LCD_COLOR_YELLOW; |
fab2sn | 1:b7df0d9d1d9c | 78 | } |
fab2sn | 1:b7df0d9d1d9c | 79 | } |
fab2sn | 1:b7df0d9d1d9c | 80 | |
fab2sn | 0:8515b04f8da2 | 81 | /* on attend un peu */ |
fab2sn | 0:8515b04f8da2 | 82 | wait(0.02); |
fab2sn | 0:8515b04f8da2 | 83 | |
fab2sn | 0:8515b04f8da2 | 84 | /* on se prepare a deplacer le pacman */ |
fab2sn | 0:8515b04f8da2 | 85 | pacmanCenter.X += 10; |
fab2sn | 1:b7df0d9d1d9c | 86 | |
fab2sn | 0:8515b04f8da2 | 87 | } while (pacmanCenter.X + pacmanSize < lcd.GetXSize()); |
fab2sn | 1:b7df0d9d1d9c | 88 | /* on continue tant que le pacman n'a pas atteint le bord de l'ecran */ |
fab2sn | 0:8515b04f8da2 | 89 | |
fab2sn | 0:8515b04f8da2 | 90 | /* Affiche le texte */ |
fab2sn | 0:8515b04f8da2 | 91 | lcd.DisplayStringAt(0, LINE(20), (uint8_t *)"THE END", CENTER_MODE); |
fab2sn | 0:8515b04f8da2 | 92 | |
fab2sn | 0:8515b04f8da2 | 93 | /* Clignotte la LED */ |
fab2sn | 0:8515b04f8da2 | 94 | for (i = 0; i < 10; i++) { |
fab2sn | 0:8515b04f8da2 | 95 | led1 = !led1; |
fab2sn | 0:8515b04f8da2 | 96 | wait(0.05); |
fab2sn | 0:8515b04f8da2 | 97 | } |
fab2sn | 0:8515b04f8da2 | 98 | |
fab2sn | 0:8515b04f8da2 | 99 | wait(1); |
fab2sn | 0:8515b04f8da2 | 100 | |
fab2sn | 0:8515b04f8da2 | 101 | /* on recommence */ |
fab2sn | 0:8515b04f8da2 | 102 | goto start; |
fab2sn | 0:8515b04f8da2 | 103 | } |