Subversion Repositories shark

Rev

Rev 1349 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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