Subversion Repositories shark

Rev

Rev 1567 | 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
 
1606 tullio 13
/*
14
 * This program is free software; you can redistribute it and/or modify
15
 * it under the terms of the GNU General Public License as published by
16
 * the Free Software Foundation; either version 2 of the License, or
17
 * (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
 *
28
 */
29
 
1162 tavani 30
#include <kernel/func.h>
31
#include <stdlib.h>
32
#include <semaphore.h>
1552 pj 33
#include "sem/sem/sem.h"
34
#include "hartport/hartport/hartport.h"
1162 tavani 35
 
1349 giacomo 36
#include <drivers/shark_keyb26.h>
37
#include <drivers/shark_fb26.h>
38
 
1162 tavani 39
#include <math.h>
40
 
41
#define ASTRO_MOVE/* If defined then astro else defender */
42
 
1349 giacomo 43
#define FRAME_BUFFER_DEVICE 0
44
 
1162 tavani 45
// DA CALCOLARE
46
#define RGB_BLACK     rgb16(  0,  0,  0)
47
#define RGB_GRAY      rgb16(127,127,127)
48
#define RGB_WHITE     rgb16(255,255,255)
49
#define RGB_RED       rgb16(255,  0,  0)
50
#define RGB_GREEN     rgb16(  0,255,  0)
51
#define RGB_BLUE      rgb16(  0,  0,255)
52
#define RGB_YELLOW    rgb16(255,255,  0)
53
#define RGB_MAGENTA   rgb16(255,  0,255)
54
#define RGB_CYAN      rgb16(  0,255,255)
55
#define RGB_D_RED     rgb16(127,  0,  0)
56
#define RGB_D_GREEN   rgb16(  0,127,  0)
57
#define RGB_D_BLUE    rgb16(  0,  0,127)
58
#define RGB_D_YELLOW  rgb16(127,127,  0)
59
#define RGB_D_MAGENTA rgb16(127,  0,127)
60
#define RGB_D_CYAN    rgb16(  0,127,127)
61
 
62
#define LIVE_0 "      "
63
#define LIVE_1 "     *"
64
#define LIVE_2 "    **"
65
#define LIVE_3 "   ***"
66
#define LIVE_4 "  ****"
67
#define LIVE_5 " *****"
68
#define LIVE_6 "******"
69
#define LIVE_X "------"
70
 
71
/* GameBoard constants */
72
#define GB_YMIN             65               /* position of the top */
73
#define GB_YMAX            460               /* position of the bottom */
74
#define GB_XMIN              5               /* min position X of the asteroid */
75
#define GB_XMAX            505               /* max position X of the asteroid */
76
 
77
/* Asteroid constants */
78
#define ASTEROID_RADIUS      4               /* radius of the asteroid */
79
#define ASTEROID_NMAX       60               /* max number of asteroids */
80
 
81
#define ASTEROID_GROUP       2               /* task group of asteroids */
82
 
83
/* Astro constants */
84
#ifdef ASTRO_MOVE
85
#define ASTRO_Y        (GB_YMAX+GB_YMIN)/2   /* Y position of the astro */
86
#else
87
#define ASTRO_Y        GB_YMAX-22            /* Y position of the astro */
88
#endif
89
#define ASTRO_X        (GB_XMAX+GB_XMIN)/2   /* X position of the astro */
90
#define ASTRO_MAX_VEL  ASTRO_VEL_INC*5       /* Max astro velocity */
91
#ifdef ASTRO_MOVE
92
#define ASTRO_MAX_GRAD     180               /* Max astro angle */
93
#else
94
#define ASTRO_MAX_GRAD      80               /* Max astro angle */
95
#endif
96
#define ASTRO_GRAD_INC      10               /* angular variation */
97
#define ASTRO_VEL_INC        3               /* velocity variation */
98
#define ASTRO_RADIUS        16               /* Dimension of the astro */
1535 giacomo 99
#define ASTRO_PERIOD      10000
100
#define ASTRO_MOVE_PERIOD 10000
101
#define ASTRO_WCET         1500
1162 tavani 102
 
103
/* Shot constants */
104
#define SHOT_RADIUS          1               /* radius of the shot */
105
#define SHOT_VEL            35               /* speed of the shot */
106
#define SHOT_NMAX           30               /* max number of shots */
107
 
108
#define SHOT_GROUP           3               /* task group of shots */
109
 
1535 giacomo 110
#define SHOT_PERIOD      30000
111
#define SHOT_WCET         2000
1162 tavani 112
 
113
/* Rock constants */
114
#define ROCK_RADIUS_I        8               /* initial radius of the rock */
115
#define ROCK_RADIUS_S        4               /* radius of the rock after one shot */
116
#define ROCK_VEL             6               /* speed of the rock */
117
#define ROCK_NMAX            8               /* max number of rocks */
118
 
119
#define ROCK_GROUP           4               /* task group of rocks */
120
 
1535 giacomo 121
#define ROCK_PERIOD      30000
122
#define ROCK_WCET         2000
1162 tavani 123
 
124
/* Statistic constants */
125
#define ENERGY_INIT        200
126
#define ENERGY_SHOT          2
127
#define ENERGY_GOT          10
128
#define SCORE_GOT            2
129
#define LIVES_INIT           3
130
 
131
#define STAT_PERIOD     400000
1535 giacomo 132
#define STAT_WCET         2000
1162 tavani 133
 
134
/* Statistic constants */
1535 giacomo 135
#define LOOK_PERIOD      30000
1376 giacomo 136
#define LOOK_WCET         4000
1162 tavani 137
 
138
typedef struct {
139
        PID pid;
140
        int x, y, r;
141
} rock_pos;
142
 
143
typedef struct {
144
        int i;
145
        int x, y, r;
146
} rock_ini;
147
 
148
double dist_xy(int x1, int y1, int x2, int y2);
1567 mauro 149
void draw_rock(int x, int y, int r, int c, int m);
1162 tavani 150
void rock_create(rock_ini* ri);
151
void frame_astro();
152
void frame_stat();
153
void init_astro();
154
void init_stat();
155
void init_rock();
156
void reset_astro();
157
void reset_rock();
158
void start_astro();
159
void start_rock();
160
void reset_game();
161
 
162
extern sem_t  mx_mat, mx_grf;       /* mutex semaphores */
163
extern sem_t  mx_pos, mx_vel;       /* mutex semaphores */
164
extern sem_t  mx_xy, mx_rk, mx_rn;  /* mutex semaphores */
165
extern sem_t  mx_st_scr, mx_st_nrg; /* mutex semaphores */
166
extern sem_t  mx_st_kil, mx_st_liv; /* mutex semaphores */
167
extern int nshot;                   /* number of shot active */
168
extern int nrock;                   /* number of rock active */
169
extern int astro_x, astro_y;        /* astro position */
170
extern int astro_grad;              /* astro angolar position */
171
extern int astro_vel;               /* astro velocity */
172
extern int score;                   /* current player score */
173
extern int energy;                  /* current player energy */
174
extern int enemy;                   /* current player strikes */
175
extern int lives;                   /* current player lives*/
176
extern int kill_rock;               /* kill active rocks */
177
extern int kill_shot;               /* kill active shots */
178
extern int freez_astro;             /* turn of control pad */
179
extern int crash;                   /* astro vs. rock */
180
extern rock_pos rocks[ROCK_NMAX];   /* rocks position */
181
extern rock_ini rock_new;