![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Projet interfaçage en licence professionnelle MECSE à l'iut de Cachan. Réalisé sur une carte STM32F746G-DISCO. Capteur utilisé: l'accéléromètre MMA8451Q piloté en i2c via les PIN PB_9 et PB_8 de la carte. Les Pin d'interruption I1 et I2 de la carte ne sont pas utilisé. Lien du capteur: https://www.gotronic.fr/art-accelerometre-3-axes-mma8451-22164.htm Datasheet du capteur : https://www.gotronic.fr/pj-1230.pdf
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG MMA8451Q
Réalisé sur une carte STM32F746G-DISCO. Capteur utilisé: l'accéléromètre MMA8451Q piloté en i2c via les PIN PB_9 et PB_8 de la carte. Les Pin d'interruption I1 et I2 de la carte ne sont pas utilisé.
Lien du capteur: https://www.gotronic.fr/art-accelerometre-3-axes-mma8451-22164.htm Datasheet du capteur : https://www.gotronic.fr/pj-1230.pdf
draw.cpp@0:88b1d5275ad7, 2019-06-04 (annotated)
- Committer:
- jgaltier98
- Date:
- Tue Jun 04 12:53:19 2019 +0000
- Revision:
- 0:88b1d5275ad7
projet interfacage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jgaltier98 | 0:88b1d5275ad7 | 1 | #include "draw.h" |
jgaltier98 | 0:88b1d5275ad7 | 2 | |
jgaltier98 | 0:88b1d5275ad7 | 3 | void draw_hitbox_ship(short posX, short posY){ |
jgaltier98 | 0:88b1d5275ad7 | 4 | lcd.SetTextColor(LCD_COLOR_RED); |
jgaltier98 | 0:88b1d5275ad7 | 5 | lcd.DrawRect(posX,posY-height_wing,lenght_X_hitbox,lenght_Y_hitbox); |
jgaltier98 | 0:88b1d5275ad7 | 6 | lcd.SetTextColor(LCD_COLOR_GREEN); |
jgaltier98 | 0:88b1d5275ad7 | 7 | } |
jgaltier98 | 0:88b1d5275ad7 | 8 | |
jgaltier98 | 0:88b1d5275ad7 | 9 | void draw_star(short X, short Y){ |
jgaltier98 | 0:88b1d5275ad7 | 10 | char star[5][5]={{1,0,1,0,1}, |
jgaltier98 | 0:88b1d5275ad7 | 11 | {0,0,1,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 12 | {1,1,0,1,1}, |
jgaltier98 | 0:88b1d5275ad7 | 13 | {0,0,1,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 14 | {1,0,1,0,1}} ; |
jgaltier98 | 0:88b1d5275ad7 | 15 | short i,j; |
jgaltier98 | 0:88b1d5275ad7 | 16 | for(i=0;i<5;i++){ |
jgaltier98 | 0:88b1d5275ad7 | 17 | for(j=0;j<5;j++){ |
jgaltier98 | 0:88b1d5275ad7 | 18 | if(star[j][i]==0){ |
jgaltier98 | 0:88b1d5275ad7 | 19 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 20 | } |
jgaltier98 | 0:88b1d5275ad7 | 21 | else{ |
jgaltier98 | 0:88b1d5275ad7 | 22 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW); |
jgaltier98 | 0:88b1d5275ad7 | 23 | } |
jgaltier98 | 0:88b1d5275ad7 | 24 | } |
jgaltier98 | 0:88b1d5275ad7 | 25 | } |
jgaltier98 | 0:88b1d5275ad7 | 26 | } |
jgaltier98 | 0:88b1d5275ad7 | 27 | |
jgaltier98 | 0:88b1d5275ad7 | 28 | void draw_fire(short X,short Y, short fire){ |
jgaltier98 | 0:88b1d5275ad7 | 29 | char fire1[10][10]={{1,1,0,0,0,1,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 30 | {0,0,1,1,0,0,1,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 31 | {0,0,0,0,1,1,2,1,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 32 | {0,0,1,1,2,2,2,2,1,0}, |
jgaltier98 | 0:88b1d5275ad7 | 33 | {1,1,2,2,2,2,2,2,2,1}, |
jgaltier98 | 0:88b1d5275ad7 | 34 | {1,1,2,2,2,2,2,2,2,1}, |
jgaltier98 | 0:88b1d5275ad7 | 35 | {0,0,1,1,2,2,2,2,1,0}, |
jgaltier98 | 0:88b1d5275ad7 | 36 | {0,0,0,0,1,1,2,1,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 37 | {0,0,1,1,0,0,1,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 38 | {1,1,0,0,0,1,0,0,0,0}}; |
jgaltier98 | 0:88b1d5275ad7 | 39 | |
jgaltier98 | 0:88b1d5275ad7 | 40 | char fire2[10][10]={{0,0,0,0,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 41 | {0,0,0,0,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 42 | {0,0,0,0,0,0,1,1,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 43 | {0,0,0,0,0,1,2,2,1,0}, |
jgaltier98 | 0:88b1d5275ad7 | 44 | {0,0,0,0,1,2,2,2,2,1}, |
jgaltier98 | 0:88b1d5275ad7 | 45 | {0,0,0,0,1,2,2,2,2,1}, |
jgaltier98 | 0:88b1d5275ad7 | 46 | {0,0,0,0,0,1,2,2,1,0}, |
jgaltier98 | 0:88b1d5275ad7 | 47 | {0,0,0,0,0,0,1,1,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 48 | {0,0,0,0,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 49 | {0,0,0,0,0,0,0,0,0,0}}; |
jgaltier98 | 0:88b1d5275ad7 | 50 | short i,j; |
jgaltier98 | 0:88b1d5275ad7 | 51 | X=X-10; |
jgaltier98 | 0:88b1d5275ad7 | 52 | |
jgaltier98 | 0:88b1d5275ad7 | 53 | for(i=0;i<10;i++){ |
jgaltier98 | 0:88b1d5275ad7 | 54 | for(j=0;j<10;j++){ |
jgaltier98 | 0:88b1d5275ad7 | 55 | if(fire == 0){ |
jgaltier98 | 0:88b1d5275ad7 | 56 | if(fire1[j][i]==0){ |
jgaltier98 | 0:88b1d5275ad7 | 57 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 58 | } |
jgaltier98 | 0:88b1d5275ad7 | 59 | else if(fire1[j][i]==1){ |
jgaltier98 | 0:88b1d5275ad7 | 60 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW); |
jgaltier98 | 0:88b1d5275ad7 | 61 | } |
jgaltier98 | 0:88b1d5275ad7 | 62 | else if(fire1[j][i]==2){ |
jgaltier98 | 0:88b1d5275ad7 | 63 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_RED); |
jgaltier98 | 0:88b1d5275ad7 | 64 | } |
jgaltier98 | 0:88b1d5275ad7 | 65 | } |
jgaltier98 | 0:88b1d5275ad7 | 66 | else{ |
jgaltier98 | 0:88b1d5275ad7 | 67 | if(fire2[j][i]==0){ |
jgaltier98 | 0:88b1d5275ad7 | 68 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 69 | } |
jgaltier98 | 0:88b1d5275ad7 | 70 | else if(fire2[j][i]==1){ |
jgaltier98 | 0:88b1d5275ad7 | 71 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW); |
jgaltier98 | 0:88b1d5275ad7 | 72 | } |
jgaltier98 | 0:88b1d5275ad7 | 73 | else if(fire2[j][i]==2){ |
jgaltier98 | 0:88b1d5275ad7 | 74 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_RED); |
jgaltier98 | 0:88b1d5275ad7 | 75 | } |
jgaltier98 | 0:88b1d5275ad7 | 76 | } |
jgaltier98 | 0:88b1d5275ad7 | 77 | } |
jgaltier98 | 0:88b1d5275ad7 | 78 | } |
jgaltier98 | 0:88b1d5275ad7 | 79 | } |
jgaltier98 | 0:88b1d5275ad7 | 80 | |
jgaltier98 | 0:88b1d5275ad7 | 81 | void draw_planet(short X,short Y){ |
jgaltier98 | 0:88b1d5275ad7 | 82 | char planet[14][20]={ |
jgaltier98 | 0:88b1d5275ad7 | 83 | {0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 84 | {0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 85 | {0,0,0,0,0,0,3,4,4,4,3,4,4,3,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 86 | {0,0,5,5,5,3,3,3,4,4,3,3,4,4,3,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 87 | {5,5,5,5,3,4,4,3,3,4,4,3,3,4,4,3,5,5,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 88 | {5,5,0,0,3,4,4,4,3,3,3,4,3,3,4,3,5,5,5,5}, |
jgaltier98 | 0:88b1d5275ad7 | 89 | {5,5,0,3,3,4,4,4,4,3,3,3,4,3,3,3,3,0,5,5}, |
jgaltier98 | 0:88b1d5275ad7 | 90 | {0,5,5,3,3,4,4,4,4,4,4,3,3,4,4,3,3,5,5,0}, |
jgaltier98 | 0:88b1d5275ad7 | 91 | {0,5,5,5,3,4,4,4,4,4,4,4,3,3,3,5,5,5,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 92 | {0,0,5,5,5,5,5,4,4,4,4,4,5,5,5,5,5,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 93 | {0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 94 | {0,0,0,0,0,0,3,5,5,5,5,5,4,3,0,0,0,0,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 95 | {0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0},// |
jgaltier98 | 0:88b1d5275ad7 | 96 | {0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0} |
jgaltier98 | 0:88b1d5275ad7 | 97 | }; |
jgaltier98 | 0:88b1d5275ad7 | 98 | short i,j; |
jgaltier98 | 0:88b1d5275ad7 | 99 | |
jgaltier98 | 0:88b1d5275ad7 | 100 | for(i=0;i<20;i++){ |
jgaltier98 | 0:88b1d5275ad7 | 101 | for(j=0;j<14;j++){ |
jgaltier98 | 0:88b1d5275ad7 | 102 | if(planet[j][i]==0){ |
jgaltier98 | 0:88b1d5275ad7 | 103 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 104 | } |
jgaltier98 | 0:88b1d5275ad7 | 105 | else if (planet[j][i]==3){ |
jgaltier98 | 0:88b1d5275ad7 | 106 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_MAGENTA); |
jgaltier98 | 0:88b1d5275ad7 | 107 | } |
jgaltier98 | 0:88b1d5275ad7 | 108 | else if (planet[j][i]==4){ |
jgaltier98 | 0:88b1d5275ad7 | 109 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_CYAN); |
jgaltier98 | 0:88b1d5275ad7 | 110 | } |
jgaltier98 | 0:88b1d5275ad7 | 111 | else if (planet[j][i]==5){ |
jgaltier98 | 0:88b1d5275ad7 | 112 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_ORANGE); |
jgaltier98 | 0:88b1d5275ad7 | 113 | } |
jgaltier98 | 0:88b1d5275ad7 | 114 | } |
jgaltier98 | 0:88b1d5275ad7 | 115 | } |
jgaltier98 | 0:88b1d5275ad7 | 116 | } |
jgaltier98 | 0:88b1d5275ad7 | 117 | |
jgaltier98 | 0:88b1d5275ad7 | 118 | void draw_load(short X, short Y){ |
jgaltier98 | 0:88b1d5275ad7 | 119 | short i,j,progress; |
jgaltier98 | 0:88b1d5275ad7 | 120 | char convert_progress[5]={0}; |
jgaltier98 | 0:88b1d5275ad7 | 121 | Y=Y+4; |
jgaltier98 | 0:88b1d5275ad7 | 122 | |
jgaltier98 | 0:88b1d5275ad7 | 123 | for(progress=0;progress<100;progress++){ |
jgaltier98 | 0:88b1d5275ad7 | 124 | for(i=0;i<progress;i++){ |
jgaltier98 | 0:88b1d5275ad7 | 125 | for(j=0;j<10;j++){ |
jgaltier98 | 0:88b1d5275ad7 | 126 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_GREEN); |
jgaltier98 | 0:88b1d5275ad7 | 127 | } |
jgaltier98 | 0:88b1d5275ad7 | 128 | } |
jgaltier98 | 0:88b1d5275ad7 | 129 | sprintf(convert_progress,"%hd%%",progress); |
jgaltier98 | 0:88b1d5275ad7 | 130 | lcd.DisplayStringAt(300, LINE(7), (uint8_t *)convert_progress,LEFT_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 131 | wait(0.1); |
jgaltier98 | 0:88b1d5275ad7 | 132 | } |
jgaltier98 | 0:88b1d5275ad7 | 133 | } |
jgaltier98 | 0:88b1d5275ad7 | 134 | |
jgaltier98 | 0:88b1d5275ad7 | 135 | void draw_hit(short X,short Y){ |
jgaltier98 | 0:88b1d5275ad7 | 136 | char explosion[10][10]={ |
jgaltier98 | 0:88b1d5275ad7 | 137 | {2,0,0,0,1,1,0,0,0,2}, |
jgaltier98 | 0:88b1d5275ad7 | 138 | {0,2,2,0,1,1,0,2,2,0}, |
jgaltier98 | 0:88b1d5275ad7 | 139 | {0,2,0,2,1,1,2,0,2,0}, |
jgaltier98 | 0:88b1d5275ad7 | 140 | {0,0,2,2,1,1,2,2,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 141 | {1,1,1,1,2,2,1,1,1,1}, |
jgaltier98 | 0:88b1d5275ad7 | 142 | {1,1,1,1,2,2,1,1,1,1}, |
jgaltier98 | 0:88b1d5275ad7 | 143 | {0,0,2,2,1,1,2,2,0,0}, |
jgaltier98 | 0:88b1d5275ad7 | 144 | {0,2,0,2,1,1,2,0,2,0}, |
jgaltier98 | 0:88b1d5275ad7 | 145 | {0,2,2,0,1,1,0,2,2,0}, |
jgaltier98 | 0:88b1d5275ad7 | 146 | {2,0,0,0,1,1,0,0,0,2}}; |
jgaltier98 | 0:88b1d5275ad7 | 147 | short i,j; |
jgaltier98 | 0:88b1d5275ad7 | 148 | |
jgaltier98 | 0:88b1d5275ad7 | 149 | for(i=0;i<10;i++){ |
jgaltier98 | 0:88b1d5275ad7 | 150 | for(j=0;j<10;j++){ |
jgaltier98 | 0:88b1d5275ad7 | 151 | if(explosion[j][i]==0){ |
jgaltier98 | 0:88b1d5275ad7 | 152 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 153 | } |
jgaltier98 | 0:88b1d5275ad7 | 154 | else if (explosion[j][i]==1){ |
jgaltier98 | 0:88b1d5275ad7 | 155 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW); |
jgaltier98 | 0:88b1d5275ad7 | 156 | } |
jgaltier98 | 0:88b1d5275ad7 | 157 | else if (explosion[j][i]==2){ |
jgaltier98 | 0:88b1d5275ad7 | 158 | lcd.DrawPixel(X+i,Y+j,LCD_COLOR_RED); |
jgaltier98 | 0:88b1d5275ad7 | 159 | } |
jgaltier98 | 0:88b1d5275ad7 | 160 | } |
jgaltier98 | 0:88b1d5275ad7 | 161 | } |
jgaltier98 | 0:88b1d5275ad7 | 162 | } |
jgaltier98 | 0:88b1d5275ad7 | 163 | |
jgaltier98 | 0:88b1d5275ad7 | 164 | void draw_ship(short posX, short posY, bool hitbox, short fire){ |
jgaltier98 | 0:88b1d5275ad7 | 165 | //body |
jgaltier98 | 0:88b1d5275ad7 | 166 | lcd.DrawRect(posX,posY,bodyX,bodyY); |
jgaltier98 | 0:88b1d5275ad7 | 167 | //nose |
jgaltier98 | 0:88b1d5275ad7 | 168 | lcd.DrawLine(posX+bodyX,posY,posX+bodyX+lenght_nose,posY+height_nose ); |
jgaltier98 | 0:88b1d5275ad7 | 169 | lcd.DrawLine(posX+bodyX,posY+bodyY,posX+bodyX+lenght_nose,posY+height_nose ); |
jgaltier98 | 0:88b1d5275ad7 | 170 | //up wing |
jgaltier98 | 0:88b1d5275ad7 | 171 | lcd.DrawLine(posX,posY,posX,posY-height_wing); |
jgaltier98 | 0:88b1d5275ad7 | 172 | lcd.DrawLine(posX+lenght_wing,posY,posX,posY-height_wing); |
jgaltier98 | 0:88b1d5275ad7 | 173 | //down wing |
jgaltier98 | 0:88b1d5275ad7 | 174 | lcd.DrawLine(posX,posY+bodyY,posX,posY+bodyY+height_wing); |
jgaltier98 | 0:88b1d5275ad7 | 175 | lcd.DrawLine(posX+lenght_wing,posY+bodyY,posX,posY+bodyY+height_wing); |
jgaltier98 | 0:88b1d5275ad7 | 176 | |
jgaltier98 | 0:88b1d5275ad7 | 177 | draw_fire(posX,posY,fire); |
jgaltier98 | 0:88b1d5275ad7 | 178 | //hitbox |
jgaltier98 | 0:88b1d5275ad7 | 179 | if (hitbox){ |
jgaltier98 | 0:88b1d5275ad7 | 180 | draw_hitbox_ship(posX,posY); |
jgaltier98 | 0:88b1d5275ad7 | 181 | } |
jgaltier98 | 0:88b1d5275ad7 | 182 | } |
jgaltier98 | 0:88b1d5275ad7 | 183 | bool draw_line(short posX, short posY, short lenght,short posX_ship, short posY_ship){ |
jgaltier98 | 0:88b1d5275ad7 | 184 | short coord_slide_line; |
jgaltier98 | 0:88b1d5275ad7 | 185 | bool hit = false; |
jgaltier98 | 0:88b1d5275ad7 | 186 | bool flag_hit = false; |
jgaltier98 | 0:88b1d5275ad7 | 187 | |
jgaltier98 | 0:88b1d5275ad7 | 188 | posY_ship = posY_ship - height_wing; |
jgaltier98 | 0:88b1d5275ad7 | 189 | lcd.DrawLine(posX,posY,posX,posY+lenght); |
jgaltier98 | 0:88b1d5275ad7 | 190 | |
jgaltier98 | 0:88b1d5275ad7 | 191 | if(posX>posX_ship and posX<posX_ship+lenght_X_hitbox){ |
jgaltier98 | 0:88b1d5275ad7 | 192 | for(coord_slide_line=posY;coord_slide_line<=posY+lenght;coord_slide_line++){ |
jgaltier98 | 0:88b1d5275ad7 | 193 | |
jgaltier98 | 0:88b1d5275ad7 | 194 | if(coord_slide_line>posY_ship and coord_slide_line<posY_ship+lenght_Y_hitbox){ |
jgaltier98 | 0:88b1d5275ad7 | 195 | hit = true; |
jgaltier98 | 0:88b1d5275ad7 | 196 | if(flag_hit == false){ |
jgaltier98 | 0:88b1d5275ad7 | 197 | draw_hit(posX,coord_slide_line); |
jgaltier98 | 0:88b1d5275ad7 | 198 | flag_hit = true; |
jgaltier98 | 0:88b1d5275ad7 | 199 | } |
jgaltier98 | 0:88b1d5275ad7 | 200 | } |
jgaltier98 | 0:88b1d5275ad7 | 201 | } |
jgaltier98 | 0:88b1d5275ad7 | 202 | } |
jgaltier98 | 0:88b1d5275ad7 | 203 | return hit; |
jgaltier98 | 0:88b1d5275ad7 | 204 | } |