-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnakePiLib.h
111 lines (93 loc) · 3.6 KB
/
snakePiLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef _SNAKEPILIB_H_
#define _SNAKEPILIB_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ledDisplay.h"
#include "tmr.h"
enum t_direccion {
ARRIBA,
DERECHA,
ABAJO,
IZQUIERDA,
NONE,
};
// La serpiente es una lista encadenada de segmentos
// Cada segmento cuenta con una ubicación (coordenadas x e y)
// y un puntero a la direccion del siguiente segmento
typedef struct s_segmento tipo_segmento;
struct s_segmento {
tipo_segmento *p_next;
int x;
int y;
};
// La serpiente siempre tiene al menos un segmento que es la cabeza
// Para dicho segmento es el unico para el que tiene sentido hablar de direccion
// El resto de segmentos irán uno tras otro ocupando sucesivamente
// posiciones de sus predecesores en la cadena
typedef struct {
tipo_segmento cabeza;
tipo_segmento *p_cola;
enum t_direccion direccion;
} tipo_serpiente;
typedef struct {
int x;
int y;
} tipo_manzana;
typedef struct {
tipo_pantalla *p_pantalla; // Esta es nuestra pantalla de juego (matriz 7x8 de labo)
tipo_serpiente serpiente;
tipo_manzana manzana;
tmr_t* tmr_serpiente;
} tipo_snakePi;
extern int flags; // Flags generales de sistema (necesario para comunicacion inter-FMs)
extern int numero_manzanas;
//------------------------------------------------------
// PROCEDIMIENTOS DE INICIALIZACION DE LOS OBJETOS ESPECIFICOS
//------------------------------------------------------
void InicializaManzana(tipo_manzana *p_manzana);
void InicializaSerpiente(tipo_serpiente *p_serpiente);
void InicializaSnakePi(tipo_snakePi *p_snakePi);
void ResetSnakePi(tipo_snakePi *p_snakePi);
//------------------------------------------------------
// PROCEDIMIENTOS PARA LA GESTION DEL JUEGO
//------------------------------------------------------
void ActualizaColaSerpiente(tipo_serpiente *p_serpiente);
int ActualizaLongitudSerpiente(tipo_serpiente *p_serpiente);
int ActualizaSnakePi(tipo_snakePi *p_snakePi);
void CambiarDireccionSerpiente(tipo_serpiente *serpiente, unsigned int direccion);
int CompruebaColision(tipo_serpiente *serpiente, tipo_manzana *manzana, int chequea_manzana);
void LiberaMemoriaCola(tipo_serpiente *p_serpiente);
//------------------------------------------------------
// PROCEDIMIENTOS PARA LA VISUALIZACION DEL JUEGO
//------------------------------------------------------
void PintaManzana(tipo_snakePi *p_snakePi);
void PintaSerpiente(tipo_snakePi *p_snakePi);
void ActualizaPantallaSnakePi(tipo_snakePi *p_snakePi);
void ReseteaPantallaSnakePi(tipo_pantalla *p_pantalla);
//void ActualizaPantallaSnakePiDespuesColision(tipo_snakePi *p_snakePi);
//------------------------------------------------------
// FUNCIONES DE TRANSICION DE LA MAQUINA DE ESTADOS
//------------------------------------------------------
int CompruebaBotonPulsado (fsm_t* this);
int CompruebaMovimientoArriba (fsm_t* this);
int CompruebaMovimientoAbajo (fsm_t* this);
int CompruebaMovimientoIzquierda (fsm_t* this);
int CompruebaMovimientoDerecha (fsm_t* this);
int CompruebaPausaJuego(fsm_t *this);
int CompruebaTimeoutActualizacionJuego (fsm_t* this);
int CompruebaFinalJuego (fsm_t* this);
//------------------------------------------------------
// FUNCIONES DE ACCION DE LA MAQUINA DE ESTADOS
//------------------------------------------------------
void InicializaJuego (fsm_t* this);
void MueveSerpienteIzquierda (fsm_t* this);
void MueveSerpienteDerecha (fsm_t* this);
void MueveSerpienteArriba (fsm_t* this);
void MueveSerpienteAbajo (fsm_t* this);
void ActualizarJuego (fsm_t* this);
void FinalJuego (fsm_t* this);
void PausaJuego(fsm_t *this);
void ReseteaJuego (fsm_t* this);
void ReanudarJuego(fsm_t* this);
#endif /* _SNAKEPILIB_H_ */