PACMAN_part_2

Dependencies:   mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI

main.cpp

Committer:
fab2sn
Date:
2017-01-19
Revision:
1:b7df0d9d1d9c
Parent:
0:8515b04f8da2
Child:
2:63af55274d70

File content as of revision 1:b7df0d9d1d9c:

#include "mbed.h"
#include "LCD_DISCO_F469NI.h"
#include "TS_DISCO_F469NI.h"

TS_DISCO_F469NI ts;
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;
    uint16_t x, y;
    uint32_t color;
    TS_StateTypeDef TS_State;

    ts.Init(lcd.GetXSize(), lcd.GetYSize());
    color = LCD_COLOR_YELLOW;

 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 + 10;
    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
    {        
      /* on efface le pacman */
      lcd.SetTextColor(LCD_COLOR_BLACK);
      lcd.FillCircle(pacmanCenter.X - 10, pacmanCenter.Y, pacmanSize);
    
      /* dessine un rond jaune */
      lcd.SetTextColor(color);
      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);

      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 se prepare a deplacer le pacman */
      pacmanCenter.X += 10;   
      
    } while (pacmanCenter.X + pacmanSize < lcd.GetXSize());
    /* 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);
    
    /* Clignotte la LED */
    for (i = 0; i < 10; i++) {
        led1 = !led1;
        wait(0.05);
    }
    
    wait(1);
    
    /* on recommence */
    goto start;
}