Juego de cruzar las calles, el jugador debe llegar hasta el otro punto para ganar

Dependencies:   mbed

Committer:
djinn77
Date:
Wed Nov 14 07:56:55 2018 +0000
Revision:
8:29d258f44024
Parent:
7:73af8e91e691
Child:
9:d17e7acc22a4
cuenta y muestra los puntos acumulados

Who changed what in which revision?

UserRevisionLine numberNew contents of line
djinn77 0:22386e919072 1 #include "mbed.h"
djinn77 0:22386e919072 2 #include "avenidas.h"
djinn77 4:074433a7addc 3
djinn77 0:22386e919072 4 // Definicion de parametros de comunicacion
djinn77 4:074433a7addc 5
djinn77 1:18fff1390131 6 Serial pc(USBTX,USBRX);
djinn77 4:074433a7addc 7 SPI deviceM(PB_5, PB_4, PB_3); //D4(gris), Ninguno, D3(azul)
djinn77 4:074433a7addc 8 DigitalOut ssel (PA_4); //A2(morado)
djinn77 3:ddb6c620cce7 9 Ticker tp;
djinn77 3:ddb6c620cce7 10 int printjugador =1;
djinn77 4:074433a7addc 11
djinn77 1:18fff1390131 12 // Definiendo Botones
djinn77 4:074433a7addc 13
djinn77 4:074433a7addc 14 AnalogIn vry(A3);
djinn77 4:074433a7addc 15 AnalogIn vrx(A4);
djinn77 4:074433a7addc 16 DigitalIn sw(A5);
djinn77 1:18fff1390131 17
djinn77 0:22386e919072 18 // Definicion de Funciones
djinn77 0:22386e919072 19 void sendSPI();
djinn77 0:22386e919072 20 void inicializar_matriz();
djinn77 3:ddb6c620cce7 21 void printstatus();
djinn77 6:fae23f72d7f0 22 void desplazar_der();
djinn77 6:fae23f72d7f0 23 void desplazar_izq();
djinn77 6:fae23f72d7f0 24 void arriba();
djinn77 7:73af8e91e691 25 void pista();
djinn77 7:73af8e91e691 26 void puntaje();
djinn77 7:73af8e91e691 27 void impresion();
djinn77 6:fae23f72d7f0 28
djinn77 0:22386e919072 29 // Definicion de Variables
djinn77 4:074433a7addc 30
djinn77 0:22386e919072 31 uint16_t* nivel;
djinn77 1:18fff1390131 32 uint16_t* jugador;
djinn77 7:73af8e91e691 33 uint16_t* victorias;
djinn77 3:ddb6c620cce7 34 float velocidad = 1.0;
djinn77 6:fae23f72d7f0 35 float meas_vx;
djinn77 6:fae23f72d7f0 36 float meas_vy;
djinn77 7:73af8e91e691 37 uint8_t ubicacion;
djinn77 7:73af8e91e691 38 uint8_t conteo = 2;
djinn77 7:73af8e91e691 39
djinn77 7:73af8e91e691 40 // Inicio del programa
djinn77 0:22386e919072 41 void sendSPI(uint8_t d1, uint8_t d2)
djinn77 0:22386e919072 42 {
djinn77 0:22386e919072 43 deviceM.unlock();
djinn77 0:22386e919072 44 ssel=0;
djinn77 0:22386e919072 45 deviceM.write(d1);
djinn77 0:22386e919072 46 deviceM.write(d2);
djinn77 0:22386e919072 47 ssel=1;
djinn77 0:22386e919072 48 deviceM.lock();
djinn77 0:22386e919072 49 };
djinn77 4:074433a7addc 50
djinn77 4:074433a7addc 51
djinn77 0:22386e919072 52 void inicializar_matriz(){
djinn77 0:22386e919072 53 sendSPI(0x0c,1);
djinn77 0:22386e919072 54 sendSPI(0x0b,7);
djinn77 0:22386e919072 55 sendSPI(0x09,0); //SELECCIONA LA LUMINOSIDAD DE LA MATRIZ
djinn77 0:22386e919072 56 sendSPI(0x0A,0x00); //SELECCIONA LA LUMINOSIDAD DE LA MATRIZ
djinn77 0:22386e919072 57
djinn77 0:22386e919072 58 int i;
djinn77 0:22386e919072 59 for (i=0;i<2;i++){
djinn77 0:22386e919072 60 sendSPI(0x0F,1);
djinn77 0:22386e919072 61 wait (0.5);
djinn77 0:22386e919072 62 sendSPI(0x0F,0);
djinn77 0:22386e919072 63 wait (0.5);
djinn77 0:22386e919072 64 }
djinn77 0:22386e919072 65
djinn77 0:22386e919072 66 }
djinn77 4:074433a7addc 67
djinn77 4:074433a7addc 68
djinn77 0:22386e919072 69 int main() {
djinn77 1:18fff1390131 70 pc.baud(38400);
djinn77 0:22386e919072 71 inicializar_matriz();
djinn77 0:22386e919072 72 nivel= AV_1;
djinn77 7:73af8e91e691 73 victorias=puntos;
djinn77 1:18fff1390131 74 jugador=player;
djinn77 3:ddb6c620cce7 75 tp.attach(&printstatus,0.2);
djinn77 7:73af8e91e691 76 ubicacion=1;
djinn77 6:fae23f72d7f0 77
djinn77 8:29d258f44024 78
djinn77 7:73af8e91e691 79
djinn77 0:22386e919072 80 while(1){
djinn77 6:fae23f72d7f0 81
djinn77 4:074433a7addc 82 meas_vx = vrx.read() * 3300; // Convierte el valor de lectura de la entrada entre 0-3300 eje X
djinn77 4:074433a7addc 83 meas_vy = vry.read() * 3300; // Convierte el valor de lectura de la entrada entre 0-3300 eje Y
djinn77 1:18fff1390131 84
djinn77 6:fae23f72d7f0 85 //------ realiza el corriemiento del vector hacia la izq y der respectivamente.
djinn77 6:fae23f72d7f0 86
djinn77 6:fae23f72d7f0 87 if (meas_vx < 1600) // si se cumple esta condicion el jugador se desplaza a la izq
djinn77 6:fae23f72d7f0 88 desplazar_izq();
djinn77 6:fae23f72d7f0 89 else if (meas_vx > 1700) // si se cumple esta condicion el jugador se desplaza a la der
djinn77 6:fae23f72d7f0 90 desplazar_der();
djinn77 6:fae23f72d7f0 91
djinn77 6:fae23f72d7f0 92 //------ mueve a el jugador hacia arriba en el mapa
djinn77 6:fae23f72d7f0 93
djinn77 7:73af8e91e691 94 if(meas_vy < 1550){
djinn77 6:fae23f72d7f0 95 arriba();
djinn77 7:73af8e91e691 96 ubicacion++;
djinn77 7:73af8e91e691 97 pc.printf("\n ubicacion:\n %i",ubicacion);
djinn77 7:73af8e91e691 98 if(ubicacion==7)
djinn77 7:73af8e91e691 99 puntaje();
djinn77 7:73af8e91e691 100 }
djinn77 7:73af8e91e691 101
djinn77 7:73af8e91e691 102 // ----- El siguiente ciclo realiza el desplazamiento de los vehiculos
djinn77 7:73af8e91e691 103 pista();
djinn77 7:73af8e91e691 104
djinn77 7:73af8e91e691 105 wait(velocidad); // Velocidad del juego
djinn77 7:73af8e91e691 106
djinn77 0:22386e919072 107 }
djinn77 3:ddb6c620cce7 108 }
djinn77 6:fae23f72d7f0 109
djinn77 6:fae23f72d7f0 110 void desplazar_der(){
djinn77 6:fae23f72d7f0 111
djinn77 6:fae23f72d7f0 112 int der = jugador[7];
djinn77 6:fae23f72d7f0 113 for(int i= 7; i>=0;i--){
djinn77 6:fae23f72d7f0 114 jugador[i]=jugador[i-1];
djinn77 6:fae23f72d7f0 115 }
djinn77 6:fae23f72d7f0 116 jugador[0] = der;
djinn77 6:fae23f72d7f0 117
djinn77 6:fae23f72d7f0 118 }
djinn77 6:fae23f72d7f0 119
djinn77 6:fae23f72d7f0 120 void desplazar_izq(){
djinn77 6:fae23f72d7f0 121
djinn77 6:fae23f72d7f0 122 int izq = jugador[0];
djinn77 6:fae23f72d7f0 123 for(int i= 0; i<8;i++){
djinn77 6:fae23f72d7f0 124 jugador[i]=jugador[i+1];
djinn77 6:fae23f72d7f0 125 }
djinn77 6:fae23f72d7f0 126 jugador[7] = izq;
djinn77 6:fae23f72d7f0 127
djinn77 6:fae23f72d7f0 128 }
djinn77 4:074433a7addc 129
djinn77 6:fae23f72d7f0 130 void arriba(){
djinn77 6:fae23f72d7f0 131
djinn77 6:fae23f72d7f0 132 int arb = 1;
djinn77 6:fae23f72d7f0 133 for(int i= 0; i<8;i++){
djinn77 6:fae23f72d7f0 134 jugador[i]= jugador[i] << arb;
djinn77 6:fae23f72d7f0 135 }
djinn77 6:fae23f72d7f0 136 arb++;
djinn77 6:fae23f72d7f0 137
djinn77 6:fae23f72d7f0 138 }
djinn77 7:73af8e91e691 139
djinn77 7:73af8e91e691 140 void pista(){
djinn77 7:73af8e91e691 141
djinn77 7:73af8e91e691 142 int aux = nivel[0];
djinn77 7:73af8e91e691 143 for(int i= 0; i<8;i++){
djinn77 7:73af8e91e691 144 nivel[i]=nivel[i+1];
djinn77 7:73af8e91e691 145 }
djinn77 7:73af8e91e691 146 nivel[7] = aux;
djinn77 7:73af8e91e691 147
djinn77 7:73af8e91e691 148 }
djinn77 7:73af8e91e691 149
djinn77 7:73af8e91e691 150 void puntaje(){
djinn77 7:73af8e91e691 151
djinn77 7:73af8e91e691 152 victorias[conteo]=0x80;
djinn77 8:29d258f44024 153 for(int i= 0; i<8;i++){
djinn77 8:29d258f44024 154 jugador[i]= jugador[i] >> 6;
djinn77 8:29d258f44024 155 }
djinn77 8:29d258f44024 156 ubicacion=1;
djinn77 7:73af8e91e691 157 conteo++;
djinn77 7:73af8e91e691 158 }
djinn77 7:73af8e91e691 159
djinn77 7:73af8e91e691 160
djinn77 7:73af8e91e691 161
djinn77 3:ddb6c620cce7 162 void printstatus()
djinn77 3:ddb6c620cce7 163 {
djinn77 3:ddb6c620cce7 164 for(int j= 1; j<=8;j++)
djinn77 3:ddb6c620cce7 165 if (printjugador)
djinn77 7:73af8e91e691 166 sendSPI(j, nivel[j-1]|jugador[j-1]| victorias[j-1]);
djinn77 3:ddb6c620cce7 167 else
djinn77 7:73af8e91e691 168 sendSPI(j, nivel[j-1]| victorias[j-1]);
djinn77 3:ddb6c620cce7 169 printjugador =!printjugador;
djinn77 0:22386e919072 170 }