home *** CD-ROM | disk | FTP | other *** search
- /* Shifty Death Effect started by Noah Vawter on Halloween, 1992 */
- /* Special thanks to Pete Kazmier */
-
- /* stuff to add:
- aliens that shoot
- explosions for aliens when hit
- better keyboard routine
- more random placement
- better algorithim for aliens appearing
- no-blink erase routine
- */
- #include <stdio.h>
- #include <cursesX.h> /* Ultrix uses cursesX not curses */
- #define SHOTS 6 /* don't forget shots=SHOTS-1 !*/
- #define SHIPY 15
- #define RIGHTEDGE 40
- #define LEFTEDGE 10
- #define TOP 3
- #define ALIENBASEMENT 13
- #define ALIENS 20
- int score;
- void main (void)
- {
- int sh_flag[SHOTS],shot_x[SHOTS],shot_y[SHOTS];
- int al_flag[ALIENS],al_x[ALIENS],al_y[ALIENS];
- int al_dy[ALIENS],al_dx[ALIENS];
- void drawship (int);
- void draw_shots (int sh_flag[], int shot_y[], int shot_x[]);
- void move_shots (int shot_y[],int sh_flag[]);
- void move_ship (int *, int sh_flag[], int shot_x[], int shot_y[]);
- void move_aliens (int al_flag[],int al_y[],int al_x[],int al_dx[],int al_dy[]);
- void draw_aliens (int al_flag[],int al_y[],int al_x[]);
- void add_aliens (int al_flag[],int al_y[],int al_x[]);
- void int_aliens (int al_y[],int al_x[],int al_dy[],int al_dy[]);
- void al_die (int al_flag[],int al_y[],int al_x[],int shot_y[],int shot_x[]);
- void show_score();
- int loop;
- int shipx =10,
- nlines = 20,
- ncols = 40,
- begin_x = 1,
- begin_y = 1;
-
- initscr (); /* must be called first before you use curses functions */
- clear (); /* clears the main screen */
- refresh (); /* clear screen now not later */
-
- int_aliens (al_y,al_x,al_dy,al_dx);
- al_flag[1]=1;
- al_flag[2]=1;
- al_flag[3]=1;
- for (loop = 1; loop < 9991; loop++)
- {
- move_ship(&shipx, sh_flag, shot_x, shot_y);
- drawship(shipx);
- move_shots(shot_y,sh_flag);
- draw_shots(sh_flag, shot_y, shot_x);
- move_aliens(al_flag,al_y,al_x,al_dx,al_dy);
- draw_aliens(al_flag,al_y,al_x);
- al_die(al_flag,al_y,al_x,shot_y,shot_x);
- show_score();
- refresh();
- }
- endwin ();
- }
-
- void drawship (int shipx)
- {
- move(SHIPY,shipx);
- printw ("A"); /* QUESTION: why not use putch */
- refresh();
- }
-
- void move_ship (int *shpx, int shflag[], int shotx[], int shoty[])
- {
- chtype widget;
- widget = getch();
- clear();
- /* putch (widget); */
- if (widget == 'j')
- {
- *shpx = *shpx - 2;
- if (*shpx < LEFTEDGE)
- *shpx = LEFTEDGE;
- }
- if (widget == 'k')
- {
- *shpx = *shpx + 2;
- if (*shpx > RIGHTEDGE)
- *shpx = RIGHTEDGE;
- }
-
- if (widget == 'a')/* shot is fired! */
- {
- int loop;
- for (loop = 1; loop < (SHOTS) ; loop++)
- {
- if (shflag[loop] != 1)
- {
- shflag[loop] = 1;
- shotx[loop] = *shpx;
- shoty[loop] = (SHIPY-1);
- break;
- }
- }
- }
- }
-
- void draw_shots (int shflag[], int shoty[], int shotx[])
- {
- int loop;
- for (loop=1 ; loop < (SHOTS); loop++)
- {
- if (shflag[loop] == 1)
- {
- move (shoty[loop], shotx[loop]);
- printw("|",loop);
- }
- }
- }
-
- void move_shots (int shoty[], int shflag[])
- {
- int loop;
- for (loop=1 ; loop < (SHOTS); loop++)
- {
- if (shflag[loop] == 1)
- {
- shoty[loop] = shoty[loop] -1;
- if (shoty[loop] == (TOP))
- {
- shflag[loop]= 0;
- }
- }
- }
- }
-
- void draw_aliens (int al_flag[],int al_y[],int al_x[])
- {
- int loop;
- for (loop = 1;loop < ALIENS+1;loop++)
- {
- if (al_flag[loop] == 1)
- {
- move (al_y[loop],al_x[loop]);
- printw ("%d",loop);
- }
- }
- }
-
- void move_aliens (int al_flag[],int al_y[],int al_x[],int al_dx[],int al_dy[])
- {
- int loop;
- for (loop = 1;loop < ALIENS+1;loop++)
- {
- if (al_flag[loop] == 1)
- {
- al_y[loop]=al_y[loop]+al_dy[loop];
- if (al_y[loop] > ALIENBASEMENT)
- al_dy[loop]= -al_dy[loop];
- if (al_y[loop] < TOP)
- al_dy[loop]= -al_dy[loop];
- al_x[loop]=al_x[loop]+al_dx[loop];
- if (al_x[loop] > RIGHTEDGE)
- al_dx[loop]= -al_dx[loop];
- if (al_x[loop] < LEFTEDGE)
- al_dx[loop]= -al_dx[loop];
- }
- }
- }
-
- void int_aliens (int al_y[], int al_x[], int al_dx[], int al_dy[])
- {
- int loop;
- for (loop = 1;loop < ALIENS+1; loop++)
- {
- al_y[loop]=10;
- al_x[loop]=10;
- al_dy[loop]=1;
- al_dx[loop]=1;
- }
- al_y[2]=7;
- al_x[2]=11;
- al_y[3]=9;
- al_x[3]=10;
- }
-
- void al_die (int al_flag[], int al_y[], int al_x[], int shot_y[], int shot_x[])
- {
- int loop1,loop2;
- for (loop1=1;loop1<ALIENS+1;loop1++)
- {
- for (loop2=1;loop2<SHOTS;loop2++)
- {
- if (al_y[loop1] == shot_y[loop2])
- if (al_x[loop1] == shot_x[loop2])
- if (al_flag[loop1] == 1)
- {
- al_flag[loop1] = 0;
- score=score+100;
- }
- }
- }
- }
-
- void show_score()
- {
- move(SHIPY+1,RIGHTEDGE);
- printw("%d",score);
- }
-
- void add_aliens (int al_flag[], int al_y[], int al_x[])
- {
- int loop, used[ALIENS];
- for (loop=1;loop<ALIENS+1;loop++)
- {
- if (al_flag[loop] !=1)
- {
- al_flag[loop] =1;
- al_y[loop] = TOP+2;
- al_x[loop] = 23;
- break;
- }
- }
- }
-