
jeu pacman
Dependencies: BSP_DISCO_F746NG
main.cpp
- Committer:
- mickaelul
- Date:
- 2022-07-12
- Revision:
- 6:845cfd545a41
- Parent:
- 5:071136c3eefa
File content as of revision 6:845cfd545a41:
/** * Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-littlevgl/ */ #include "mbed.h" #include "lvgl/lvgl.h" #include "hal_stm_lvgl/tft/tft.h" #include "hal_stm_lvgl/touchpad/touchpad.h" #include "lv_demo.h" /*Comment/uncomment will switch between LVGL demo and Hello word example*/ #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 /* * Callback function for lvgl timing. * Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). * It is required for the internal timing of LittlevGL. */ void lv_ticker_func(){ lv_tick_inc(LVGL_TICK); } #ifndef LV_DEMO_H static void event_handler(lv_event_t* event) { lv_event_code_t code = lv_event_get_code(event); if(code == LV_EVENT_CLICKED) { printf("Clicked\n"); } else if(code == LV_EVENT_VALUE_CHANGED) { printf("Toggled\n"); } } #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 //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_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 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); } }