Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/cZed.cpp@12:7afdbc7465ac, 2016-04-10 (annotated)
- Committer:
- Willheisen
- Date:
- Sun Apr 10 20:51:02 2016 +0000
- Revision:
- 12:7afdbc7465ac
- Parent:
- 8:92d0c4961a16
- Child:
- 29:95469b25e187
Tous les gestions de collisions OK!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Willheisen | 3:493dd1cf30a4 | 1 | // Définition de la classe Carré |
Willheisen | 3:493dd1cf30a4 | 2 | |
Willheisen | 3:493dd1cf30a4 | 3 | #include "cZed.h" |
Willheisen | 3:493dd1cf30a4 | 4 | |
Willheisen | 12:7afdbc7465ac | 5 | cZed::cZed() |
Willheisen | 12:7afdbc7465ac | 6 | { |
Willheisen | 12:7afdbc7465ac | 7 | // variables à 0 |
Willheisen | 12:7afdbc7465ac | 8 | _positionX = 0; |
Willheisen | 12:7afdbc7465ac | 9 | _positionY = 0; |
Willheisen | 12:7afdbc7465ac | 10 | _orientation = 1; |
Willheisen | 12:7afdbc7465ac | 11 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 12 | // |0|1| |
Willheisen | 12:7afdbc7465ac | 13 | // |2|3| |
Willheisen | 12:7afdbc7465ac | 14 | _Leds[0].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 15 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 16 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 17 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 18 | _Leds[2].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 19 | _Leds[2].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 20 | _Leds[3].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 21 | _Leds[3].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 22 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 23 | _Leds[i].setOldPositionX(_Leds[i].getPositionX()); |
Willheisen | 12:7afdbc7465ac | 24 | } |
Willheisen | 12:7afdbc7465ac | 25 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 26 | _Leds[i].setOldPositionY(_Leds[i].getPositionY()); |
Willheisen | 12:7afdbc7465ac | 27 | } |
Willheisen | 12:7afdbc7465ac | 28 | _typeForme = 2; |
Willheisen | 12:7afdbc7465ac | 29 | } |
Willheisen | 3:493dd1cf30a4 | 30 | |
Willheisen | 12:7afdbc7465ac | 31 | cZed::cZed(unsigned char x, unsigned char y) |
Willheisen | 12:7afdbc7465ac | 32 | { |
Willheisen | 12:7afdbc7465ac | 33 | // variables à 0 |
Willheisen | 12:7afdbc7465ac | 34 | _positionX = x; |
Willheisen | 12:7afdbc7465ac | 35 | _positionY = y; |
Willheisen | 12:7afdbc7465ac | 36 | _orientation = 1; |
Willheisen | 12:7afdbc7465ac | 37 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 38 | // |0|1| |
Willheisen | 12:7afdbc7465ac | 39 | // |2|3| |
Willheisen | 12:7afdbc7465ac | 40 | _Leds[0].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 41 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 42 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 43 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 44 | _Leds[2].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 45 | _Leds[2].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 46 | _Leds[3].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 47 | _Leds[3].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 48 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 49 | _Leds[i].setOldPositionX(_Leds[i].getPositionX()); |
Willheisen | 12:7afdbc7465ac | 50 | } |
Willheisen | 12:7afdbc7465ac | 51 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 52 | _Leds[i].setOldPositionY(_Leds[i].getPositionY()); |
Willheisen | 12:7afdbc7465ac | 53 | } |
Willheisen | 12:7afdbc7465ac | 54 | _typeForme = 2; |
Willheisen | 3:493dd1cf30a4 | 55 | } |
Willheisen | 3:493dd1cf30a4 | 56 | |
Willheisen | 12:7afdbc7465ac | 57 | void cZed::rotationHoraire() |
Willheisen | 12:7afdbc7465ac | 58 | { |
Willheisen | 12:7afdbc7465ac | 59 | // Sauvegarde des anciennes positions |
Willheisen | 12:7afdbc7465ac | 60 | for (unsigned char i = 0; i < 4; i++) { |
Willheisen | 12:7afdbc7465ac | 61 | _Leds[i].setOldPositionX(_Leds[i].getPositionX()); |
Willheisen | 12:7afdbc7465ac | 62 | _Leds[i].setOldPositionY(_Leds[i].getPositionY()); |
Willheisen | 12:7afdbc7465ac | 63 | } |
Willheisen | 12:7afdbc7465ac | 64 | |
Willheisen | 12:7afdbc7465ac | 65 | switch (_orientation) { |
Willheisen | 12:7afdbc7465ac | 66 | case 1: |
Willheisen | 12:7afdbc7465ac | 67 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 68 | // |0| |
Willheisen | 12:7afdbc7465ac | 69 | // |2|1| |
Willheisen | 12:7afdbc7465ac | 70 | // |3| |
Willheisen | 12:7afdbc7465ac | 71 | _Leds[0].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 72 | _Leds[0].setPositionY(_positionY - 1); |
Willheisen | 12:7afdbc7465ac | 73 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 74 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 75 | _Leds[2].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 76 | _Leds[2].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 77 | _Leds[3].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 78 | _Leds[3].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 79 | _orientation = 2; |
Willheisen | 12:7afdbc7465ac | 80 | break; |
Willheisen | 12:7afdbc7465ac | 81 | case 2: |
Willheisen | 12:7afdbc7465ac | 82 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 83 | // |3|2| |
Willheisen | 12:7afdbc7465ac | 84 | // |1|0| |
Willheisen | 12:7afdbc7465ac | 85 | _Leds[0].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 86 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 87 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 88 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 89 | _Leds[2].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 90 | _Leds[2].setPositionY(_positionY - 1); |
Willheisen | 12:7afdbc7465ac | 91 | _Leds[3].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 92 | _Leds[3].setPositionY(_positionY - 1); |
Willheisen | 12:7afdbc7465ac | 93 | _orientation = 3; |
Willheisen | 12:7afdbc7465ac | 94 | break; |
Willheisen | 12:7afdbc7465ac | 95 | case 3: |
Willheisen | 12:7afdbc7465ac | 96 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 97 | // |3| |
Willheisen | 12:7afdbc7465ac | 98 | // |1|2| |
Willheisen | 12:7afdbc7465ac | 99 | // |0| |
Willheisen | 12:7afdbc7465ac | 100 | _Leds[0].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 101 | _Leds[0].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 102 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 103 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 104 | _Leds[2].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 105 | _Leds[2].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 106 | _Leds[3].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 107 | _Leds[3].setPositionY(_positionY - 1); |
Willheisen | 12:7afdbc7465ac | 108 | _orientation = 4; |
Willheisen | 12:7afdbc7465ac | 109 | break; |
Willheisen | 12:7afdbc7465ac | 110 | |
Willheisen | 12:7afdbc7465ac | 111 | case 4: |
Willheisen | 12:7afdbc7465ac | 112 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 113 | // |0|1| |
Willheisen | 12:7afdbc7465ac | 114 | // |2|3| |
Willheisen | 12:7afdbc7465ac | 115 | _Leds[0].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 116 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 117 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 118 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 119 | _Leds[2].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 120 | _Leds[2].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 121 | _Leds[3].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 122 | _Leds[3].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 123 | _orientation = 1; |
Willheisen | 12:7afdbc7465ac | 124 | break; |
Willheisen | 12:7afdbc7465ac | 125 | default: |
Willheisen | 12:7afdbc7465ac | 126 | break; |
Willheisen | 12:7afdbc7465ac | 127 | } |
Willheisen | 3:493dd1cf30a4 | 128 | } |