Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1668 → Rev 1669

/unsupported/trunk/arezzo/2004/defender/def_01.c
4,8 → 4,8
/*--------------------------------------------------------------*/
 
#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
#include <drivers/shark_fb26.h>
#include <drivers/shark_keyb26.h>
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>
19,7 → 19,6
#define ANG 30 /* angolo massimo sterzata (30) */
#define D 3 /* raggio alieno */
#define DD 6 /* diametro alieno */
#define ESC 27 /* ASCII code of ESCAPE key */
#define MAX_ALIEN 30 /* max number of aliens */
#define MAX_MISSIL 10 /* numero massimo di missili */
 
43,6 → 42,8
char command_astro ; // comandi astronave
int AstroCmdState ;
 
extern int vga16color[16];
 
struct argAlien {
int orig_x ; // coordinate iniziali
int orig_y ;
96,20 → 97,20
if (y < 8) y = 8;
 
sem_wait(&grx_mutex);
grx_line(x, y-8, x, y+8, c);
grx_line(x, y-8, x+5, y-4, c);
grx_line(x, y+8, x+5, y+4, c);
grx_line(x+5, y-4, x+10, y-4, c);
grx_line(x+5, y+4, x+10, y+4, c);
grx_line(x+10, y-4, x+15, y, c);
grx_line(x+10, y+4, x+15, y, c);
grx_line(x+15, y, x+17, y, c);
grx_box(x-3, y-6, x, y-2, c);
grx_box(x-3, y+2, x, y+6, c);
grx_box(x+8, y-3, x+10, y-1, c);
grx_box(x+8, y+1, x+10, y+3, c);
grx_line(x+3, y-4, x+8, y-1, c);
grx_line(x+3, y+4, x+8, y+1, c);
grx_line(x, y-8, x, y+8, vga16color[c]);
grx_line(x, y-8, x+5, y-4, vga16color[c]);
grx_line(x, y+8, x+5, y+4, vga16color[c]);
grx_line(x+5, y-4, x+10, y-4, vga16color[c]);
grx_line(x+5, y+4, x+10, y+4, vga16color[c]);
grx_line(x+10, y-4, x+15, y, vga16color[c]);
grx_line(x+10, y+4, x+15, y, vga16color[c]);
grx_line(x+15, y, x+17, y, vga16color[c]);
grx_box(x-3, y-6, x, y-2, vga16color[c]);
grx_box(x-3, y+2, x, y+6, vga16color[c]);
grx_box(x+8, y-3, x+10, y-1, vga16color[c]);
grx_box(x+8, y+1, x+10, y+3, vga16color[c]);
grx_line(x+3, y-4, x+8, y-1, vga16color[c]);
grx_line(x+3, y+4, x+8, y+1, vga16color[c]);
sem_post(&grx_mutex);
}
 
120,8 → 121,8
if (y < 0) y = 0;
 
sem_wait(&grx_mutex);
grx_disc(x, y, D, c); // disco
grx_line(x-DD, y, x+DD, y, c); // linea
grx_disc(x, y, D, vga16color[c]); // disco
grx_line(x-DD, y, x+DD, y, vga16color[c]); // linea
sem_post(&grx_mutex);
}
 
134,12 → 135,12
if (y < 8) y = 8;
 
sem_wait(&grx_mutex);
grx_box(x-10, y-10, x-5, y+5, c); // box
grx_box(x+5, y-10, x+10, y+5, c); // box
grx_disc(x, y, 5, c); // disco
grx_line(x, y+8, x, y-8, c); // linea
grx_box(x-10, y-10, x-5, y+5, vga16color[c]); // box
grx_box(x+5, y-10, x+10, y+5, vga16color[c]); // box
grx_disc(x, y, 5, vga16color[c]); // disco
grx_line(x, y+8, x, y-8, vga16color[c]); // linea
for (i = 0; i < d ; i++) {
grx_disc(x + (rand()%20)-10, y + (rand()%10)-5, d/2, 0);
grx_disc(x + (rand()%20)-10, y + (rand()%10)-5, d/2, vga16color[0]);
}
sem_post(&grx_mutex);
}
149,11 → 150,11
if (y < 3) y = 3;
 
sem_wait(&grx_mutex);
grx_box (x, y-1, x+6, y+1, c);
grx_line(x+1, y-3, x+1, y+3, c);
grx_line(x+1, y+3, x+3, y, c);
grx_line(x+1, y-3, x+3, y, c);
grx_disc(x+6, y, 1, c);
grx_box (x, y-1, x+6, y+1, vga16color[c]);
grx_line(x+1, y-3, x+1, y+3, vga16color[c]);
grx_line(x+1, y+3, x+3, y, vga16color[c]);
grx_line(x+1, y-3, x+3, y, vga16color[c]);
grx_disc(x+6, y, 1, vga16color[c]);
sem_post(&grx_mutex);
}
/******************************************************************/
501,11 → 502,8
 
if (pid_Alien == NIL)
{
grx_text("pid_Alien == NIL", 200, 80 , 4, 0);
grx_text("pid_Alien == NIL", 200, 80 , vga16color[4], 0);
return 0;
//grx_close();
//perror("Could not create task <Alieno>\n");
//sys_abort(1);
}
 
task_activate(pid_Alien);
827,12 → 825,12
if (stat1==0)
{
sprintf(s,"Astro->TimeMax = %d ", (int) T_Astro_Max);
grx_text(s , XMIN+350, YMENU+20, 4, 0);
grx_text(s , XMIN+350, YMENU+20, vga16color[4], vga16color[0]);
}
else
{
sprintf(s," ") ;
grx_text(s , XMIN+350, YMENU+20, 4, 0) ;
grx_text(s , XMIN+350, YMENU+20, vga16color[4], vga16color[0]) ;
}
 
 
844,12 → 842,12
if (stat2==0)
{
sprintf(s,"Madre->TimeMax = %d ", (int) T_Madre_Max);
grx_text(s , XMIN+350, YMENU+30, 4, 0);
grx_text(s , XMIN+350, YMENU+30, vga16color[4], vga16color[0]);
}
else
{
sprintf(s," ") ;
grx_text(s , XMIN+350, YMENU+30, 4, 0) ;
grx_text(s , XMIN+350, YMENU+30, vga16color[4], vga16color[0]) ;
}
 
 
857,14 → 855,7
 
}
}
/****************************************************************/
 
/* This function is called when the system exits */
void byebye(void *arg)
{
grx_close();
cprintf("Bye Bye!\n");
}
 
/****************************** MAIN ******************************/
 
908,17 → 899,12
pid_Monitor = task_create("Monitor", Monitor, &monitor, NULL);
 
if (pid_Monitor == NIL) {
grx_close();
perror("Could not create task <Monitor>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <Monitor>\n");
sys_end();
}
 
task_activate(pid_Monitor); // parte immediatamente
 
 
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* Semaphore Initialization */
sem_init(&grx_mutex,0,1);
sem_init(&keyb_mutex,0,1);
929,27 → 915,16
sem_init(&missile_mutex[i],0,1);
}
 
/* graphic card Initialization */
if (grx_init() < 1) {
cprintf("GRX Init\n");
sys_abort(1);
}
 
if (grx_open(640, 480, 8) < 0) {
cprintf("GRX Err\n");
sys_abort(1);
}
 
/* The scenario */
grx_line(XMIN-D-1, YMIN-D-1, XMAX+D+1, YMIN-D-1, 14);
grx_line(XMIN-D-1, YMAX+D+1, XMAX+D+1, YMAX+D+1, 14);
grx_line(XMIN-D-1, YMIN-D-1, XMAX+D+1, YMIN-D-1, vga16color[14]);
grx_line(XMIN-D-1, YMAX+D+1, XMAX+D+1, YMAX+D+1, vga16color[14]);
 
grx_text("Simulation of Defender Game", XMIN, YMENU+10, 1, 0);
grx_text("a -> crea Astronave" , XMIN, YMENU+20, 3, 0);
grx_text("m -> crea Madre alieni" , XMIN, YMENU+30, 13, 0);
grx_text("space -> sparo" , XMIN, YMENU+40, 14, 0);
grx_text("ESC exit to DOS" , XMIN, YMENU+50, 4, 0);
grx_text("SCORE " , XMIN, YMENU+60, 4, 0);
grx_text("Simulation of Defender Game", XMIN, YMENU+10, vga16color[1], 0);
grx_text("a -> crea Astronave" , XMIN, YMENU+20, vga16color[3], 0);
grx_text("m -> crea Madre alieni" , XMIN, YMENU+30, vga16color[13], 0);
grx_text("space -> sparo" , XMIN, YMENU+40, vga16color[14], 0);
grx_text("ESC exit to DOS" , XMIN, YMENU+50, vga16color[4], 0);
grx_text("SCORE " , XMIN, YMENU+60, vga16color[4], 0);
 
c = keyb_getch(BLOCK);
 
980,9 → 955,8
pid_Missile = task_create("Missile", Missile, &ms, NULL);
 
if (pid_Missile == NIL) {
grx_close();
perror("Could not create task <Missile>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <Missile>\n");
sys_end();
}
 
task_activate(pid_Missile);
1005,9 → 979,8
pid_Madre = task_create("MadreAlieni", MadreAlieni, &m, NULL);
 
if (pid_Madre == NIL) {
grx_close();
perror("Could not create task <MadreAlieni>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <MadreAlieni>\n");
sys_end();
}
task_activate(pid_Madre);
}
1024,9 → 997,8
pid_Astro = task_create("Astronave", Astronave, &a, NULL);
 
if (pid_Astro == NIL) {
grx_close();
perror("Could not create task <Astronave>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <Astronave>\n");
sys_end();
}
 
AstronavePosition.FlagAstronave = TRUE ;
1049,12 → 1021,12
 
grx_text( s , XMIN, YMENU+60, 4, 0);
 
grx_text("Nemici uccisi", XMIN+250, YMENU+10, 1, 0);
grx_text(s1 , XMIN+250, YMENU+20, 1, 0);
grx_text(s2 , XMIN+250, YMENU+30, 1, 0);
grx_text(s3 , XMIN+250, YMENU+40, 1, 0);
grx_text(s4 , XMIN+250, YMENU+50, 1, 0);
grx_text(s5 , XMIN+250, YMENU+60, 1, 0);
grx_text("Nemici uccisi", XMIN+250, YMENU+10, vga16color[1], 0);
grx_text(s1 , XMIN+250, YMENU+20, vga16color[1], 0);
grx_text(s2 , XMIN+250, YMENU+30, vga16color[1], 0);
grx_text(s3 , XMIN+250, YMENU+40, vga16color[1], 0);
grx_text(s4 , XMIN+250, YMENU+50, vga16color[1], 0);
grx_text(s5 , XMIN+250, YMENU+60, vga16color[1], 0);
 
c = keyb_getch(BLOCK);