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: 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 endfun(KEY_EVT *k)
57
{
58
        cprintf("Ctrl-Brk pressed! Ending...\n");
59
        sys_end();
60
}
61
 
62
void my_grx_close(void *arg)
63
{
64
        grx_close();
65
        kern_printf("Graphic mode closed.\n");
66
}
67
 
68
void frame_main()
69
{
70
#ifdef ASTRO_MOVE
71
        grx_text("S.Ha.R.K. - Asteroid 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
72
#else
73
        grx_text("S.Ha.R.K. - Defender 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
74
#endif
75
        grx_text("by Marinoni Mauro"            ,24,16, RGB_GREEN, RGB_BLACK );
76
        grx_text("   Scaricabarozzi Mattia"     ,24,24, RGB_GREEN, RGB_BLACK );
77
 
78
        grx_text("Ctrl-C, Ctrr-C: exit"  ,300, 0, RGB_GRAY, RGB_BLACK );
79
        grx_text("O-P : turn left/right" ,300,16, RGB_GRAY, RGB_BLACK );
80
#ifdef ASTRO_MOVE
81
        grx_text("A-Z : speed up/down"   ,300,24, RGB_GRAY, RGB_BLACK );
82
        grx_text("S   : stop engine"     ,300,32, RGB_GRAY, RGB_BLACK );
83
        grx_text("F   : flip astro"      ,300,40, RGB_GRAY, RGB_BLACK );
84
#else
85
        grx_text("Z-X : move left/right" ,300,24, RGB_GRAY, RGB_BLACK );
86
#endif
87
        grx_text("Space : fire"          ,485,16, RGB_GRAY, RGB_BLACK );
88
        grx_text("N     : new game"      ,485,24, RGB_GRAY, RGB_BLACK );
89
        grx_text("B     : begin game"    ,485,32, RGB_GRAY, RGB_BLACK );
90
 
91
        frame_stat();
92
        frame_astro();
93
}
94
 
95
int main(int argc, char **argv)
96
{
97
        KEY_EVT k;
98
        TIME seme;
99
        int modenum;
100
 
101
        k.flag = CNTR_BIT;
102
        k.scan = KEY_C;
103
        k.ascii = 'c';
104
        keyb_hook(k,endfun);
105
 
106
        k.flag = CNTL_BIT;
107
        k.scan = KEY_C;
108
        k.ascii = 'c';
109
        keyb_hook(k,endfun);
110
 
111
        sem_init(&mx_mat,0,1);
112
        sem_init(&mx_grf,0,1);
113
        sem_init(&mx_pos,0,1);
114
        sem_init(&mx_vel,0,1);
115
        sem_init(&mx_xy ,0,1);
116
        sem_init(&mx_rk ,0,1);
117
        sem_init(&mx_rn ,0,1);
118
        sem_init(&mx_st_scr,0,1);
119
        sem_init(&mx_st_nrg,0,1);
120
        sem_init(&mx_st_kil,0,1);
121
        sem_init(&mx_st_liv,0,1);
122
 
123
        seme = sys_gettime(NULL);
124
        srand(seme);
125
 
126
        sys_atrunlevel(my_grx_close, NULL, RUNLEVEL_BEFORE_EXIT);
127
 
128
        grx_init();
129
        modenum = grx_getmode(640, 480, 16);
130
        grx_setmode(modenum);
131
 
132
        frame_main();
133
 
134
        init_stat();
135
        init_astro();
136
        init_rock();
137
 
138
        return 0;
139
}