Subversion Repositories shark

Rev

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