jeu pacman

Dependencies:   BSP_DISCO_F746NG

Revision:
6:845cfd545a41
Parent:
5:071136c3eefa
--- a/main.cpp	Tue Jun 15 19:35:57 2021 +0000
+++ b/main.cpp	Tue Jul 12 14:11:18 2022 +0000
@@ -11,6 +11,16 @@
 #define LVGL_TICK   10                               //Time tick value for lvgl in ms (1-10msa)
 #define TICKER_TIME 10ms                             //modified to miliseconds
 
+
+//declaration des entrés analogiques qui correspondent aux mouvements du joystick
+
+    DigitalIn portD13(D13);
+    DigitalIn portD12(D12);
+    DigitalIn portD11(D11);
+    DigitalIn portD10(D10);
+
+
+
 Ticker ticker;                                       //Ticker for lvgl                    
  
 /*
@@ -34,49 +44,131 @@
     }
 }
 #endif
+
+
+
+
+
+
+
+
+
 // main() runs in its own thread in the OS
 int main()
 {
+    
+    //initialisation des variables
+    int mur[480][272];
+    int i,j;
+    int xpacman=20;
+    int ypacman=40;
+    int xfantom=80;
+    int yfantom=80;
+    
+    
+    
     printf("LVGL-"); 
     lv_init();                                              //Initialize the LVGL
     tft_init();                                             //Initialize diplay 
     touchpad_init();                                        //Initialize touchpad
     ticker.attach(callback(&lv_ticker_func),TICKER_TIME);   //Attach callback to ticker
-
-#ifdef LV_DEMO_H
-    printf("Demo\n"); 
-    lv_demo_widgets();
-#else
-    printf("Hello world\n");
-    lv_obj_t * label1 = lv_label_create(lv_scr_act());
-    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP);     /*Break the long lines*/
-    lv_label_set_recolor(label1, true);                      /*Enable re-coloring by commands in the text*/
-    lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#");
-    lv_obj_set_width(label1, 150);
-    lv_obj_align(label1, LV_ALIGN_TOP_MID, 0, 20);
+    
+    //déclaration de l'image de la carte du jeu
+    
+    LV_IMG_DECLARE(mappac3);
+    lv_obj_t * img3 = lv_img_create(lv_scr_act());
+    lv_img_set_src(img3, &mappac3);
+    lv_obj_align(img3, LV_ALIGN_CENTER, 0, 0);
+    lv_obj_set_size(img3, 480, 272);
+    
+    
+    // declaration de l'image de pacman
 
-    lv_obj_t * label2 = lv_label_create(lv_scr_act());
-    lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR);     /*Circular scroll*/
-    lv_obj_set_width(label2, 150);
-    lv_label_set_text(label2, "It is a circularly scrolling text. ");
-    lv_obj_align(label2, LV_ALIGN_BOTTOM_MID, 0, 0);
+    LV_IMG_DECLARE(pacpacpac);
+    lv_obj_t * img1 = lv_img_create(lv_scr_act());
+    lv_img_set_src(img1, &pacpacpac);
+    lv_obj_align(img1, LV_ALIGN_CENTER, xpacman, ypacman);
+    lv_obj_set_size(img1, 20, 20);
+    
+    // declaration de l'image du fantome
+    
+    LV_IMG_DECLARE(fantom2);
+    lv_obj_t * img2 = lv_img_create(lv_scr_act());
+    lv_img_set_src(img2, &fantom2);
+    lv_obj_align(img2, LV_ALIGN_CENTER, 80, 10);
+    lv_obj_set_size(img2, 30, 30);
+    
+    
+    // mise en place d'un pull up interne pour recevoir un signal quand l'interrupteur est ouvert
     
-    lv_obj_t * label;
-    lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
-    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
-    lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -25);
-    label = lv_label_create(btn1);
-    lv_label_set_text(label, "Button");
-    lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
-    lv_obj_add_event_cb(btn2, event_handler,LV_EVENT_ALL, NULL);
-    lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 25);
-    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
-    label = lv_label_create(btn2);
-    lv_label_set_text(label, "Toggled");
-#endif
+    portD13.mode(PullUp);
+    portD12.mode(PullUp);
+    portD11.mode(PullUp);
+    portD10.mode(PullUp);
+    
+    // mise en place des limites de la carte a jouer
+    
+    for(i=0;i<480;i++)
+    {
+        for(j=0;j<480;j++)
+            {
+                if((i==479)||(i==0)||(j==271)||(j==0))
+                {
+                    mur[i][j]=1;
+                }
+                else
+                {
+                    mur[i][j]=0;
+                }
+            }
+    }
+    
+
 
     while (true){
+
+        
+    
+        
+        
+        //on fait changer le sens de l'image pour la faire bouger sauf si elle touche un mur
+        if((portD13== 1)&&(mur[xpacman][ypacman]==0))
+        {
+           xpacman= xpacman +1;
+            
+            lv_obj_align(img1, LV_ALIGN_CENTER, xpacman, ypacman);
+            wait_us(10000);
+        }
+            
+        if((portD11== 1)&&(mur[xpacman][ypacman]==0))
+        {
+           xpacman= xpacman -1;
+            
+            lv_obj_align(img1, LV_ALIGN_CENTER, xpacman, ypacman);
+            wait_us(10000);
+        }
+            
+        if((portD12== 1)&&(mur[xpacman][ypacman]==0))
+        {
+           ypacman= ypacman +1;
+            
+            lv_obj_align(img1, LV_ALIGN_CENTER, xpacman, ypacman);
+            wait_us(10000);
+        }
+            
+        if((portD10 == 1)&&(mur[xpacman][ypacman]==0))
+        {
+           ypacman= ypacman +1;
+            
+            lv_obj_align(img1, LV_ALIGN_CENTER, xpacman, ypacman);
+            wait_us(10000);
+        }
+        
+            
+            
         lv_task_handler(); 
+        
+        
         //Call lv_task_handler() periodically every few milliseconds. 
         //It will redraw the screen if required, handle input devices etc.
         thread_sleep_for(LVGL_TICK);