Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Alex Rodriguez Navas, David Marin Gutierrez, Carlos Sanson Martinez
- /* Main.c file generated by New Project wizard
- *
- * Created: weed dec 11 2019
- * Processor: PIC18F45K22
- * Compiler: MPLAB XC8
- */
- #include <xc.h>
- #define _XTAL_FREQ 8000000
- #include <string.h>
- #include <stdio.h>
- #include "config.h"
- #include "GLCD.h"
- // ESTRELLA: e
- // TROFEO: t
- // PLAYER ABAJO: s
- // PLAYER ARRIBA: w
- // PLAYER IZQ: a
- // PLAYER DHCA: d
- // BARRA IZQ LLENA: g
- // BARRA INTER VACIA: h
- // BARRA INTER LLENA: i
- // BARRA DCHA VACIA: j
- // BARRA DCHA LLENA: k
- #define ROWS 7
- #define COLS 25
- char mapa[ROWS][COLS];
- // . <-> nada
- // e <-> estrella
- // wasd <-> player arriba, izq, abajo, dcha
- int dificultad;
- int puntuacion;
- int modo_super;
- int recibido;
- struct pos {
- int x;
- int y;
- };
- pos jugador;
- char* atoi(int num) {
- char buffer[4];
- sprintf(buffer, "%02d", num);
- return buffer;
- }
- void imprimir_texto(byte page, byte y, char* s) {
- for(int i=0; *s!='\n' && *s!='\0'; ++i) putchGLCD(page, y+i, *(s++));
- }
- void imprimir_hud() {
- if(dificultad == 1) imprimir_texto(0, 0, "ghhj");
- else if(dificultad == 2) imprimir_texto(0, 0, "gihj");
- else if(dificultad == 2) imprimir_texto(0, 0, "giij");
- else imprimir_texto(0, 0, "giik");
- if(modo_super) imprimir_texto(0, 4, "!");
- imprimir_texto(0, 22, "t");
- imprimir_texto(0, 23, atoi(puntuacion));
- }
- void renderizar_mapa() {
- for(int x=0; x<ROWS; ++x) {
- for(int y=0; y<COLS; ++y) {
- if(mapa[x][y] != '.') putchGLCD(x, y, mapa[x][y]);
- }
- }
- }
- int pos_ok(pos p) {
- if(p.x > 0 && p.x <= >ROWS && p.y >= 0 && p.y <= 25) return 1;
- return 0;
- }
- void mover_jugador(char dir) {
- if(dir == 'w') {
- if(jugador.x > 0 && jugador.x <= ROWS )
- }
- else if(dir == 'a') {
- }
- else if(dir == 's') {
- }
- else if(dir == 'd') {
- }
- }
- void setup(void) {
- // Pins Botones
- TRISA = 0xFF; // Todos los pins del Puerto A a Input
- ANSELA = 0x00;
- // Linea Serie
- TXSTA1bits.BRGH = 1; // 115200 bauds
- BAUDCON1bits.BRG16 = 1;
- SPBRG1 = 16;
- TXSTA1bits.SYNC = 0; // comunicacion asincrona
- IPEN = 1;
- PEIE = 1;
- GIE = 1;
- RC1IF = 0; // limpiar interrupt flag receiver
- RC1IE = 1; // habilitar interrupt receiver
- ANSELC = 0x00; // PORTC a digital
- TRISCbits.RC7 = 1; // RC7 a input
- RCSTA1bits.RX9 = 0; // 8 bit communication
- RCSTA1bits.CREN = 1; // enable reception
- RCSTA1bits.SPEN = 1; //start serial line
- GLCDinit(); //Inicialitzem la pantalla
- clearGLCD(0,7,0,127); //Esborrem pantalla
- setStartLine(0); //Definim linia d'inici
- puntuacion = 0;
- dificultad = 4;
- modo_super = 0;
- imprimir_hud();
- for(int x=0; x<ROWS; ++x) {
- for(int y=0; y<COLS; ++y) mapa[x][y] = '.';
- }
- mapa[15][15] = 'e';
- mapa[16][15] = 'w';
- renderizar_mapa();
- }
- void interrupt rutina_AP(void) {
- if (RC1IF && RC1IE) {
- recibido = RCREG1; // Leer lo recibido
- RC1IF = 0; // Clear receiver interrupt flag
- }
- }
- int A1P = 0;
- int A2P = 0;
- int A3P = 0;
- int A4P = 0;
- void loop(void) {
- recibido = RCREG1;
- if(A1 && !A1P) {
- __delay_ms(10);
- if(A1) {
- openChannel(FreqToCCPRx(CS));
- }
- }
- else if(A2 && !A2P) {
- __delay_ms(10);
- if(A2) {
- openChannel(FreqToCCPRx(D));
- }
- }
- else if(A3 && !A3P) {
- __delay_ms(10);
- if(A3) {
- openChannel(FreqToCCPRx(DS));
- }
- }
- else if(A4 && !A4P) {
- __delay_ms(10);
- if(A4) {
- openChannel(FreqToCCPRx(E));
- }
- }
- }
- void main(void) {
- setup();
- while(1) loop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement