~ubuntu-branches/ubuntu/jaunty/gravitywars/jaunty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/* -------------------------------------------------------------------------
   Gravity Wars v1.1, (C) Sami Niemi 1995, 1996

   NOTES: [960824] [RELEASE NOTES 961101]

   The game started as a bunch of fun routines that made the ship fly.
   Later on I added collition control, and after Pär got involved with
   the graphics I just couldn't stop... So, the structure of the game is
   just terrible, with lots of unecessary variables , flags that
   are used as variables etc.. I should've written the program in c++, and
   for X! Svgalib just contains too many bugs.. 
   
   I'd be fun to see this game ported to different operating systems, though
   the structure of the game might make it hard, especially since I used 
   the SVGALIB.

   You're free to modify the code and the graphics as long as you write
   that the original code was written by Sami Niemi, and the original
   graphics were drawn by Pär Johannesson (If you're using any parts of
   the original graphics)
   
   I'd love to hear from any changes that you've made to the game!

   / Sami

   e96sn@efd.lth.se
   sniemi@kuai.se
   http://www.kuai.se/~sniemi
   http://www.efd.lth.se/~e96sn


   REMEMBER:

   getbox(x,y,*ptr) Gets the original graphics based on the block[]&level[]
   getbox2(x,y,*ptr Gets the graphics directly from the screen



   BUGS (i.e. I don't have the time to fix'em):

   - consoleswitching takes away the splitscreen (real easy to fix)

   ------------------------------------------------------------------------- */
#include <unistd.h>
#include "includes.h"
#include "memory.h"
 
/*--------------------------------------------------------------------- main */
int main(int n_args, char *arg[]) {
  

  int n,ch,x,y;
  
  long tmp_long;
  
  long  pal_m;
  long pal_n;
  
  short baselevel;
  char filename[128];
  
  char firstlevel[20]="levels/level01";
  char buf[128];
  
  levelnum=1;
  
  if (readlink(arg[0],buf,128)==-1) 
    strcpy(buf,arg[0]);
  
  n=strlen(buf);
  while(n>=0)                       
    if (buf[n--]=='/') break;
  if (n<0) {
    strcpy(gamename,"./");
    gamenamelen=2;
  }  
  else {
    strcpy(gamename,buf);
    gamename[n+2]=0;
    gamenamelen=strlen(gamename);
  }
  

  if (n_args>1) {
    n=0;
    do {
      n++;
    } while ( (strncmp(arg[1],codes[n],6)) && (n<99));
    if (n!=99) {
      levelnum=n+1;
      if (n_args>2)
	delay_len=atoi(arg[2]);
    } else {
      if ((arg[1][0]<'0') || (arg[1][0]>'9')) {
	printf("\nUsage: %s [code-to-a-given-level] [beam-adjustment]\n"
	       "(Sure you've got the right code?)\n\n",arg[0]);
	exit(0);
      }
      else 
	delay_len=atoi(arg[1]);
    } 
  }    
  
  baselevel=levelnum;

  strcpy(firstlevel,nextlevel);


  printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
"\n"
"-----------------------------------------------------------------------------\n"
"                         G R A V I T Y    W A R S\n\n"
"                                   v 1.1\n"
"                              (November 1995)\n"
"\n"
"            A Gravity Force clone for the Linux operating system\n"

"\n\n"
"                           Coding by Sami Niemi\n\n"

"                       Graphics by Pär Johannesson\n"

"-----------------------------------------------------------------------------\n"
);
  initParams();
  loadGfx();
  rotGfx();

  initScreen();

  keyboard_init();
  mouse_init("/dev/mouse", MOUSE_MICROSOFT, MOUSE_DEFAULTSAMPLERATE);
  scans=keyboard_getstate();

  ending=TRUE;

  while(ending) {

    intro();
    if (escape) 
      goto escaped;
    loaddata();
    drawScreen();

/*
    old_x=0;
    old_y=0;
    getbox(old_x, old_y, shipback[0]);
    putbox(old_x, old_y, shipback[0]);
    moveShip(0,0);
*/
    old_x=sx[0] >> STEP;
    old_y=sy[0] >> STEP;
    moveShip(0,0);

    updatescore();
    win_y=(sy[0] >> STEP)-232;
    if (win_y<8)
      win_y=8;
    else
      if (win_y>968)
	win_y=968;
    putscore(0,win_y); 


    /*CenterShip*/
    y=(sy[0] >> STEP)-240;
    if (y<16)
      y=16;
    else
      if (y>960) 
	y=960;
    gl_setdisplaystart(0,y);

    stampnum(levelnum);
    putstamp(272,y+184,68,69,70);

    if (levelnum&1) {
      for(pal_n=0; pal_n<=1024; pal_n+=16) {
	for (pal_m=0; pal_m<=767; pal_m++)
	  p1[pal_m]=(((long)pal[pal_m])*pal_n)>>10;
	vga_waitretrace();
	gl_setpalette(p1);
      }
      gl_setpalette(pal);
    }
    else {
      for(pal_n=0; pal_n<=1024; pal_n+=16) {
        for (pal_m=0; pal_m<=767; pal_m++)
          p1[pal_m]=(((long)palB[pal_m])*pal_n)>>10;
        vga_waitretrace();
        gl_setpalette(p1);
      }
      gl_setpalette(palB);
    }

    waitanykey();

    killstamp(272,y+184);
 
    anim_frame=0;
    ShipScore=0;
  
    control(0); 

    /*------ The End --------*/
    if (ending) {

      for(n=0; n<=4095; n++) {
	tmpscore[n]=score[n];
	score[n]=highscore[n];
      }

      tmp_long=Dec2BCD[ShipScore];

      putdigit(1375,tmp_long>>16);
      putdigit(1383,(tmp_long>>12)&15);
      putdigit(1391,(tmp_long>>8)&15);
      putdigit(1399,(tmp_long>>4)&15);
      putdigit(1407,tmp_long&15);

      if (ShipScore>HighScore) {
	HighScore=ShipScore;

	strcpy(filename,gamename);
	strcpy(&filename[gamenamelen],"data/hscore.gw");
	if ( ( fileptr=fopen(filename,"w") )!=NULL) {
	  fprintf(fileptr,"%d\n",ShipScore);
	  fclose(fileptr);
	}
	else {
	  printf("Can't write the HighScore!!!!");
	  doPanic();
	}
      }
 
      tmp_long=Dec2BCD[HighScore];
 
      putdigit(1474,tmp_long>>16);
      putdigit(1482,(tmp_long>>12)&15);
      putdigit(1490,(tmp_long>>8)&15);
      putdigit(1498,(tmp_long>>4)&15);
      putdigit(1506,tmp_long&15);

      putscoreOnly(0,win_y);

      putstamp(272,win_y+192,54,60,61);
      waitanykey();
      killstamp(272,win_y+192);
      if (*(scans+SCANCODE_ESCAPE))
	goto escaped;

      for(n=0; n<=4095; n++) {
	score[n]=tmpscore[n];
      }

      if (levelnum&1) {
	for(pal_n=1024; pal_n>=0; pal_n-=16) {
	  for (pal_m=0; pal_m<=767; pal_m++)
	    p1[pal_m]=(((long)pal[pal_m])*pal_n)>>10;
	  vga_waitretrace();
	  gl_setpalette(p1);
	}
	gl_setpalette(p0);
      }
      else {
        for(pal_n=1024; pal_n>=0; pal_n-=16) {
          for (pal_m=0; pal_m<=767; pal_m++)
            p1[pal_m]=(((long)palB[pal_m])*pal_n)>>10;
          vga_waitretrace();
          gl_setpalette(p1);
        }
        gl_setpalette(p0);
      }

      strcpy(nextlevel,firstlevel);
      levelnum=baselevel;
      ShipLife=3;
    }

  }
 escaped:    

  mouse_close();
  keyboard_close();

  vga_setmode(TEXT);
  printf("\n");
  exit(0);

}