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: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/*
18
 * Copyright (C) 2000 Paolo Gai
19
 *
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
36
#include "asteroid.h"
37
#include <string.h>
38
 
39
int score;             /* current player score */
40
int energy;            /* current player energy */
41
int enemy;             /* current player killed enemy */
42
int lives;             /* current player lives */
43
int crash;             /* astro vs. rock */
44
 
45
TASK stat_write()
46
{
47
        char st[20];
48
        int l;
49
 
50
        while (1) {
51
 
52
                sem_wait(&mx_st_scr);
53
                sprintf(st, "%6d", score);
54
                sem_post(&mx_st_scr);
55
                sem_wait(&mx_grf);
56
                grx_text(st, GB_XMAX+80, GB_YMIN+ 8, RGB_YELLOW, RGB_BLACK);
57
                sem_post(&mx_grf);
58
 
59
                sem_wait(&mx_st_nrg);
60
                sprintf(st, "%6d", energy);
61
                if (energy <= 0) crash = 1;
62
                sem_post(&mx_st_nrg);
63
                sem_wait(&mx_grf);
64
                grx_text(st, GB_XMAX+80, GB_YMIN+24, RGB_YELLOW, RGB_BLACK);
65
                sem_post(&mx_grf);
66
 
67
                sem_wait(&mx_st_kil);
68
                sprintf(st, "%6d", enemy);
69
                sem_post(&mx_st_kil);
70
                sem_wait(&mx_grf);
71
                grx_text(st, GB_XMAX+80, GB_YMIN+40, RGB_YELLOW, RGB_BLACK);
72
                sem_post(&mx_grf);
73
 
74
                strcpy(st,LIVE_X);
75
                sem_wait(&mx_st_liv);
76
                l = lives;
77
                sem_post(&mx_st_liv);
78
                if (l == 0) strcpy(st,LIVE_0);
79
                if (l == 1) strcpy(st,LIVE_1);
80
                if (l == 2) strcpy(st,LIVE_2);
81
                if (l == 3) strcpy(st,LIVE_3);
82
                if (l == 4) strcpy(st,LIVE_4);
83
                if (l == 5) strcpy(st,LIVE_5);
84
                if (l == 6) strcpy(st,LIVE_6);
85
                sem_wait(&mx_grf);
86
                grx_text(st, GB_XMAX+80, GB_YMIN+56, RGB_YELLOW, RGB_BLACK);
87
                sem_post(&mx_grf);
88
 
89
                task_endcycle();
90
        }
91
}
92
 
93
void reset_game()
94
{
95
        sem_wait(&mx_st_liv);
96
        if (lives > 0) {
97
                lives--;
98
                sem_post(&mx_st_liv);
99
        } else {
100
                lives = LIVES_INIT;
101
                sem_post(&mx_st_liv);
102
 
103
                sem_wait(&mx_st_scr);
104
                score = 0;
105
                sem_post(&mx_st_scr);
106
 
107
                sem_wait(&mx_st_kil);
108
                enemy = 0;
109
                sem_post(&mx_st_kil);
110
        }
111
 
112
        sem_wait(&mx_st_nrg);
113
        energy = ENERGY_INIT;
114
        sem_post(&mx_st_nrg);
115
}
116
 
117
void new_game(KEY_EVT *k)
118
{
119
        reset_rock();
120
        reset_astro();
121
        reset_game();
122
}
123
 
124
void start_game(KEY_EVT *k)
125
{
126
        start_astro();
127
        start_rock();
128
}
129
 
130
void frame_stat()
131
{
132
        grx_text("Statistics", GB_XMAX+10, 45, RGB_BLUE, RGB_BLACK);
133
        grx_line(GB_XMAX+8,55,640-8,55,RGB_RED);
134
 
135
        grx_rect(GB_XMAX+7, GB_YMIN-3, 640-6, GB_YMIN+70, RGB_GREEN);
136
        grx_text("Score  : ", GB_XMAX+15, GB_YMIN+ 8, RGB_CYAN, RGB_BLACK);
137
        grx_text("Energy : ", GB_XMAX+15, GB_YMIN+24, RGB_CYAN, RGB_BLACK);
138
        grx_text("Enemy  : ", GB_XMAX+15, GB_YMIN+40, RGB_CYAN, RGB_BLACK);
139
        grx_text("Lives  : ", GB_XMAX+15, GB_YMIN+56, RGB_CYAN, RGB_BLACK);
140
}
141
 
142
void create_stat_task()
143
{
144
        SOFT_TASK_MODEL ms;
145
        PID pid;
146
 
147
        soft_task_default_model(ms);
148
        soft_task_def_level(ms,1);
149
        soft_task_def_ctrl_jet(ms);
150
        soft_task_def_met(ms, STAT_WCET);
151
        soft_task_def_period(ms,STAT_PERIOD);
152
        soft_task_def_usemath(ms);
153
        pid = task_create("StatWrite", stat_write, &ms, NULL);
154
        if (pid == NIL) {
155
                grx_close();
156
                perror("Could not create task <StatWrite>");
157
                sys_end();
158
        } else
159
                task_activate(pid);
160
}
161
 
162
void init_stat()
163
{
164
        KEY_EVT k;
165
 
166
        score  = 0;
167
        enemy  = 0;
168
        energy = ENERGY_INIT;
169
        lives  = LIVES_INIT;
170
 
171
        create_stat_task();
172
 
173
        k.flag = 0;
174
        k.scan = KEY_N;
175
        k.ascii = 'n';
176
        keyb_hook(k,new_game);
177
 
178
        k.flag = 0;
179
        k.scan = KEY_B;
180
        k.ascii = 'b';
181
        keyb_hook(k,start_game);
182
}
183