Subversion Repositories shark

Rev

Rev 1162 | Rev 1350 | 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
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
7
 * (see authors.txt for full list of hartik's authors)
8
 *
9
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
10
 *
11
 * http://www.sssup.it
12
 * http://retis.sssup.it
13
 * http://shark.sssup.it
14
 */
15
 
16
/*
17
 * Copyright (C) 2000 Paolo Gai
18
 *
19
 * This program is free software; you can redistribute it and/or modify
20
 * it under the terms of the GNU General Public License as published by
21
 * the Free Software Foundation; either version 2 of the License, or
22
 * (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
 *
33
 */
34
 
35
#include "asteroid.h"
36
#include <kernel/kern.h>
37
 
38
sem_t  mx_mat, mx_grf, mx_pos, mx_vel, mx_xy, mx_rk, mx_rn; /* mutex semaphores */
39
sem_t  mx_st_nrg, mx_st_scr, mx_st_kil, mx_st_liv;          /* mutex semaphores */
40
 
41
double dist_xy(int x1, int y1, int x2, int y2)
42
{
43
        double dst;
44
        int dx, dy;
45
 
46
        dx = x2 - x1;
47
        dy = y2 - y1;
48
        sem_wait(&mx_mat);
49
        dst = sqrt(dx*dx + dy*dy);
50
        sem_post(&mx_mat);
51
 
52
        return dst;
53
 
54
}
55
 
56
void frame_main()
57
{
58
#ifdef ASTRO_MOVE
59
        grx_text("S.Ha.R.K. - Asteroid 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
60
#else
61
        grx_text("S.Ha.R.K. - Defender 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
62
#endif
63
        grx_text("by Marinoni Mauro"            ,24,16, RGB_GREEN, RGB_BLACK );
64
        grx_text("   Scaricabarozzi Mattia"     ,24,24, RGB_GREEN, RGB_BLACK );
65
 
66
        grx_text("Ctrl-C, Ctrr-C: exit"  ,300, 0, RGB_GRAY, RGB_BLACK );
67
        grx_text("O-P : turn left/right" ,300,16, RGB_GRAY, RGB_BLACK );
68
#ifdef ASTRO_MOVE
69
        grx_text("A-Z : speed up/down"   ,300,24, RGB_GRAY, RGB_BLACK );
70
        grx_text("S   : stop engine"     ,300,32, RGB_GRAY, RGB_BLACK );
71
        grx_text("F   : flip astro"      ,300,40, RGB_GRAY, RGB_BLACK );
72
#else
73
        grx_text("Z-X : move left/right" ,300,24, RGB_GRAY, RGB_BLACK );
74
#endif
75
        grx_text("Space : fire"          ,485,16, RGB_GRAY, RGB_BLACK );
76
        grx_text("N     : new game"      ,485,24, RGB_GRAY, RGB_BLACK );
77
        grx_text("B     : begin game"    ,485,32, RGB_GRAY, RGB_BLACK );
78
 
79
        frame_stat();
80
        frame_astro();
81
}
82
 
1349 giacomo 83
void end_func(KEY_EVT *k) {
84
 
85
        FB26_close(FRAME_BUFFER_DEVICE);
86
        sys_end();
87
 
88
}
89
 
1162 tavani 90
int main(int argc, char **argv)
91
{
92
        KEY_EVT k;
93
        TIME seme;
94
 
95
        k.flag = CNTR_BIT;
96
        k.scan = KEY_C;
97
        k.ascii = 'c';
1349 giacomo 98
        k.status = KEY_PRESSED;
99
        keyb_hook(k,end_func,FALSE);
1162 tavani 100
 
101
        k.flag = CNTL_BIT;
102
        k.scan = KEY_C;
103
        k.ascii = 'c';
1349 giacomo 104
        k.status = KEY_PRESSED;
105
        keyb_hook(k,end_func,FALSE);
1162 tavani 106
 
107
        sem_init(&mx_mat,0,1);
108
        sem_init(&mx_grf,0,1);
109
        sem_init(&mx_pos,0,1);
110
        sem_init(&mx_vel,0,1);
111
        sem_init(&mx_xy ,0,1);
112
        sem_init(&mx_rk ,0,1);
113
        sem_init(&mx_rn ,0,1);
114
        sem_init(&mx_st_scr,0,1);
115
        sem_init(&mx_st_nrg,0,1);
116
        sem_init(&mx_st_kil,0,1);
117
        sem_init(&mx_st_liv,0,1);
118
 
119
        seme = sys_gettime(NULL);
120
        srand(seme);
121
 
1349 giacomo 122
        FB26_init();
1162 tavani 123
 
1349 giacomo 124
        FB26_open(FRAME_BUFFER_DEVICE);
1162 tavani 125
 
126
        frame_main();
127
 
128
        init_stat();
129
        init_astro();
130
        init_rock();
131
 
132
        return 0;
133
}