Subversion Repositories shark

Rev

Rev 1378 | 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
 
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
 
1378 giacomo 66
        sys_end();
67
 
68
}
69
 
1162 tavani 70
int main(int argc, char **argv)
71
{
72
        KEY_EVT k;
73
        TIME seme;
74
 
75
        k.flag = CNTR_BIT;
76
        k.scan = KEY_C;
77
        k.ascii = 'c';
1349 giacomo 78
        k.status = KEY_PRESSED;
79
        keyb_hook(k,end_func,FALSE);
1162 tavani 80
 
81
        k.flag = CNTL_BIT;
82
        k.scan = KEY_C;
83
        k.ascii = 'c';
1349 giacomo 84
        k.status = KEY_PRESSED;
85
        keyb_hook(k,end_func,FALSE);
1162 tavani 86
 
87
        sem_init(&mx_mat,0,1);
88
        sem_init(&mx_grf,0,1);
89
        sem_init(&mx_pos,0,1);
90
        sem_init(&mx_vel,0,1);
91
        sem_init(&mx_xy ,0,1);
92
        sem_init(&mx_rk ,0,1);
93
        sem_init(&mx_rn ,0,1);
94
        sem_init(&mx_st_scr,0,1);
95
        sem_init(&mx_st_nrg,0,1);
96
        sem_init(&mx_st_kil,0,1);
97
        sem_init(&mx_st_liv,0,1);
98
 
99
        seme = sys_gettime(NULL);
100
        srand(seme);
101
 
102
        frame_main();
103
 
104
        init_stat();
105
        init_astro();
106
        init_rock();
107
 
108
        return 0;
1373 giacomo 109
 
1162 tavani 110
}