Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1162 tavani 1
/*
2
 * Project: S.Ha.R.K.
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://shark.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 "asteroid.h"
31
#include <kernel/kern.h>
32
 
33
sem_t  mx_mat, mx_grf, mx_pos, mx_vel, mx_xy, mx_rk, mx_rn; /* mutex semaphores */
34
sem_t  mx_st_nrg, mx_st_scr, mx_st_kil, mx_st_liv;          /* mutex semaphores */
35
 
36
double dist_xy(int x1, int y1, int x2, int y2)
37
{
38
        double dst;
39
        int dx, dy;
40
 
41
        dx = x2 - x1;
42
        dy = y2 - y1;
43
        sem_wait(&mx_mat);
44
        dst = sqrt(dx*dx + dy*dy);
45
        sem_post(&mx_mat);
46
 
47
        return dst;
48
 
49
}
50
 
51
void frame_main()
52
{
1350 giacomo 53
 
54
        grx_clear(RGB_BLACK);
55
 
1162 tavani 56
#ifdef ASTRO_MOVE
57
        grx_text("S.Ha.R.K. - Asteroid 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
58
#else
59
        grx_text("S.Ha.R.K. - Defender 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
60
#endif
61
        grx_text("by Marinoni Mauro"            ,24,16, RGB_GREEN, RGB_BLACK );
62
        grx_text("   Scaricabarozzi Mattia"     ,24,24, RGB_GREEN, RGB_BLACK );
63
 
64
        grx_text("Ctrl-C, Ctrr-C: exit"  ,300, 0, RGB_GRAY, RGB_BLACK );
65
        grx_text("O-P : turn left/right" ,300,16, RGB_GRAY, RGB_BLACK );
66
#ifdef ASTRO_MOVE
67
        grx_text("A-Z : speed up/down"   ,300,24, RGB_GRAY, RGB_BLACK );
68
        grx_text("S   : stop engine"     ,300,32, RGB_GRAY, RGB_BLACK );
69
        grx_text("F   : flip astro"      ,300,40, RGB_GRAY, RGB_BLACK );
70
#else
71
        grx_text("Z-X : move left/right" ,300,24, RGB_GRAY, RGB_BLACK );
72
#endif
73
        grx_text("Space : fire"          ,485,16, RGB_GRAY, RGB_BLACK );
74
        grx_text("N     : new game"      ,485,24, RGB_GRAY, RGB_BLACK );
75
        grx_text("B     : begin game"    ,485,32, RGB_GRAY, RGB_BLACK );
76
 
77
        frame_stat();
78
        frame_astro();
79
}
80
 
1349 giacomo 81
void end_func(KEY_EVT *k) {
82
 
1550 pj 83
        exit(0);
1378 giacomo 84
}
85
 
1162 tavani 86
int main(int argc, char **argv)
87
{
88
        KEY_EVT k;
89
        TIME seme;
90
 
91
        k.flag = CNTR_BIT;
92
        k.scan = KEY_C;
93
        k.ascii = 'c';
1349 giacomo 94
        k.status = KEY_PRESSED;
95
        keyb_hook(k,end_func,FALSE);
1162 tavani 96
 
97
        k.flag = CNTL_BIT;
98
        k.scan = KEY_C;
99
        k.ascii = 'c';
1349 giacomo 100
        k.status = KEY_PRESSED;
101
        keyb_hook(k,end_func,FALSE);
1162 tavani 102
 
103
        sem_init(&mx_mat,0,1);
104
        sem_init(&mx_grf,0,1);
105
        sem_init(&mx_pos,0,1);
106
        sem_init(&mx_vel,0,1);
107
        sem_init(&mx_xy ,0,1);
108
        sem_init(&mx_rk ,0,1);
109
        sem_init(&mx_rn ,0,1);
110
        sem_init(&mx_st_scr,0,1);
111
        sem_init(&mx_st_nrg,0,1);
112
        sem_init(&mx_st_kil,0,1);
113
        sem_init(&mx_st_liv,0,1);
114
 
115
        seme = sys_gettime(NULL);
116
        srand(seme);
117
 
118
        frame_main();
119
 
120
        init_stat();
121
        init_astro();
122
        init_rock();
123
 
124
        return 0;
1373 giacomo 125
 
1162 tavani 126
}