Subversion Repositories shark

Rev

Rev 1392 | Rev 1552 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1162 tavani 1
/*
1349 giacomo 2
 * Project: S.Ha.R.K.
1162 tavani 3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *
6
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
7
 *
8
 * http://www.sssup.it
9
 * http://retis.sssup.it
10
 * http://hartik.sssup.it
11
 */
12
 
13
#include <kernel/func.h>
14
#include <stdlib.h>
15
#include <semaphore.h>
16
#include "modules/sem.h"
17
#include "modules/hartport.h"
18
 
1349 giacomo 19
#include <drivers/shark_keyb26.h>
20
#include <drivers/shark_fb26.h>
21
 
1162 tavani 22
#include <math.h>
23
 
24
#define ASTRO_MOVE/* If defined then astro else defender */
25
 
1349 giacomo 26
#define FRAME_BUFFER_DEVICE 0
27
 
1162 tavani 28
// DA CALCOLARE
29
#define RGB_BLACK     rgb16(  0,  0,  0)
30
#define RGB_GRAY      rgb16(127,127,127)
31
#define RGB_WHITE     rgb16(255,255,255)
32
#define RGB_RED       rgb16(255,  0,  0)
33
#define RGB_GREEN     rgb16(  0,255,  0)
34
#define RGB_BLUE      rgb16(  0,  0,255)
35
#define RGB_YELLOW    rgb16(255,255,  0)
36
#define RGB_MAGENTA   rgb16(255,  0,255)
37
#define RGB_CYAN      rgb16(  0,255,255)
38
#define RGB_D_RED     rgb16(127,  0,  0)
39
#define RGB_D_GREEN   rgb16(  0,127,  0)
40
#define RGB_D_BLUE    rgb16(  0,  0,127)
41
#define RGB_D_YELLOW  rgb16(127,127,  0)
42
#define RGB_D_MAGENTA rgb16(127,  0,127)
43
#define RGB_D_CYAN    rgb16(  0,127,127)
44
 
45
#define LIVE_0 "      "
46
#define LIVE_1 "     *"
47
#define LIVE_2 "    **"
48
#define LIVE_3 "   ***"
49
#define LIVE_4 "  ****"
50
#define LIVE_5 " *****"
51
#define LIVE_6 "******"
52
#define LIVE_X "------"
53
 
54
/* GameBoard constants */
55
#define GB_YMIN             65               /* position of the top */
56
#define GB_YMAX            460               /* position of the bottom */
57
#define GB_XMIN              5               /* min position X of the asteroid */
58
#define GB_XMAX            505               /* max position X of the asteroid */
59
 
60
/* Asteroid constants */
61
#define ASTEROID_RADIUS      4               /* radius of the asteroid */
62
#define ASTEROID_NMAX       60               /* max number of asteroids */
63
 
64
#define ASTEROID_GROUP       2               /* task group of asteroids */
65
 
66
/* Astro constants */
67
#ifdef ASTRO_MOVE
68
#define ASTRO_Y        (GB_YMAX+GB_YMIN)/2   /* Y position of the astro */
69
#else
70
#define ASTRO_Y        GB_YMAX-22            /* Y position of the astro */
71
#endif
72
#define ASTRO_X        (GB_XMAX+GB_XMIN)/2   /* X position of the astro */
73
#define ASTRO_MAX_VEL  ASTRO_VEL_INC*5       /* Max astro velocity */
74
#ifdef ASTRO_MOVE
75
#define ASTRO_MAX_GRAD     180               /* Max astro angle */
76
#else
77
#define ASTRO_MAX_GRAD      80               /* Max astro angle */
78
#endif
79
#define ASTRO_GRAD_INC      10               /* angular variation */
80
#define ASTRO_VEL_INC        3               /* velocity variation */
81
#define ASTRO_RADIUS        16               /* Dimension of the astro */
1535 giacomo 82
#define ASTRO_PERIOD      10000
83
#define ASTRO_MOVE_PERIOD 10000
84
#define ASTRO_WCET         1500
1162 tavani 85
 
86
/* Shot constants */
87
#define SHOT_RADIUS          1               /* radius of the shot */
88
#define SHOT_VEL            35               /* speed of the shot */
89
#define SHOT_NMAX           30               /* max number of shots */
90
 
91
#define SHOT_GROUP           3               /* task group of shots */
92
 
1535 giacomo 93
#define SHOT_PERIOD      30000
94
#define SHOT_WCET         2000
1162 tavani 95
 
96
/* Rock constants */
97
#define ROCK_RADIUS_I        8               /* initial radius of the rock */
98
#define ROCK_RADIUS_S        4               /* radius of the rock after one shot */
99
#define ROCK_VEL             6               /* speed of the rock */
100
#define ROCK_NMAX            8               /* max number of rocks */
101
 
102
#define ROCK_GROUP           4               /* task group of rocks */
103
 
1535 giacomo 104
#define ROCK_PERIOD      30000
105
#define ROCK_WCET         2000
1162 tavani 106
 
107
/* Statistic constants */
108
#define ENERGY_INIT        200
109
#define ENERGY_SHOT          2
110
#define ENERGY_GOT          10
111
#define SCORE_GOT            2
112
#define LIVES_INIT           3
113
 
114
#define STAT_PERIOD     400000
1535 giacomo 115
#define STAT_WCET         2000
1162 tavani 116
 
117
/* Statistic constants */
1535 giacomo 118
#define LOOK_PERIOD      30000
1376 giacomo 119
#define LOOK_WCET         4000
1162 tavani 120
 
121
typedef struct {
122
        PID pid;
123
        int x, y, r;
124
} rock_pos;
125
 
126
typedef struct {
127
        int i;
128
        int x, y, r;
129
} rock_ini;
130
 
131
double dist_xy(int x1, int y1, int x2, int y2);
132
void draw_rock(int x, int y, int r, int c);
133
void rock_create(rock_ini* ri);
134
void frame_astro();
135
void frame_stat();
136
void init_astro();
137
void init_stat();
138
void init_rock();
139
void reset_astro();
140
void reset_rock();
141
void start_astro();
142
void start_rock();
143
void reset_game();
144
 
145
extern sem_t  mx_mat, mx_grf;       /* mutex semaphores */
146
extern sem_t  mx_pos, mx_vel;       /* mutex semaphores */
147
extern sem_t  mx_xy, mx_rk, mx_rn;  /* mutex semaphores */
148
extern sem_t  mx_st_scr, mx_st_nrg; /* mutex semaphores */
149
extern sem_t  mx_st_kil, mx_st_liv; /* mutex semaphores */
150
extern int nshot;                   /* number of shot active */
151
extern int nrock;                   /* number of rock active */
152
extern int astro_x, astro_y;        /* astro position */
153
extern int astro_grad;              /* astro angolar position */
154
extern int astro_vel;               /* astro velocity */
155
extern int score;                   /* current player score */
156
extern int energy;                  /* current player energy */
157
extern int enemy;                   /* current player strikes */
158
extern int lives;                   /* current player lives*/
159
extern int kill_rock;               /* kill active rocks */
160
extern int kill_shot;               /* kill active shots */
161
extern int freez_astro;             /* turn of control pad */
162
extern int crash;                   /* astro vs. rock */
163
extern rock_pos rocks[ROCK_NMAX];   /* rocks position */
164
extern rock_ini rock_new;