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

« back to all changes in this revision

Viewing changes to GravityWars101.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2001-04-03 15:04:12 UTC
  • Revision ID: james.westby@ubuntu.com-20010403150412-us89c34ffby3x6zw
Tags: upstream-1.102
Import upstream version 1.102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -------------------------------------------------------------------------
 
2
   Gravity Wars v1.1, (C) Sami Niemi 1995, 1996
 
3
 
 
4
   NOTES: [960824] [RELEASE NOTES 961101]
 
5
 
 
6
   The game started as a bunch of fun routines that made the ship fly.
 
7
   Later on I added collition control, and after P�r got involved with
 
8
   the graphics I just couldn't stop... So, the structure of the game is
 
9
   just terrible, with lots of unecessary variables , flags that
 
10
   are used as variables etc.. I should've written the program in c++, and
 
11
   for X! Svgalib just contains too many bugs.. 
 
12
   
 
13
   I'd be fun to see this game ported to different operating systems, though
 
14
   the structure of the game might make it hard, especially since I used 
 
15
   the SVGALIB.
 
16
 
 
17
   You're free to modify the code and the graphics as long as you write
 
18
   that the original code was written by Sami Niemi, and the original
 
19
   graphics were drawn by P�r Johannesson (If you're using any parts of
 
20
   the original graphics)
 
21
   
 
22
   I'd love to hear from any changes that you've made to the game!
 
23
 
 
24
   / Sami
 
25
 
 
26
   e96sn@efd.lth.se
 
27
   sniemi@kuai.se
 
28
   http://www.kuai.se/~sniemi
 
29
   http://www.efd.lth.se/~e96sn
 
30
 
 
31
 
 
32
   REMEMBER:
 
33
 
 
34
   getbox(x,y,*ptr) Gets the original graphics based on the block[]&level[]
 
35
   getbox2(x,y,*ptr Gets the graphics directly from the screen
 
36
 
 
37
 
 
38
 
 
39
   BUGS (i.e. I don't have the time to fix'em):
 
40
 
 
41
   - consoleswitching takes away the splitscreen (real easy to fix)
 
42
 
 
43
   ------------------------------------------------------------------------- */
 
44
#include <unistd.h>
 
45
#include "includes.h"
 
46
#include "memory.h"
 
47
 
 
48
/*--------------------------------------------------------------------- main */
 
49
int main(int n_args, char *arg[]) {
 
50
  
 
51
 
 
52
  int n,ch,x,y;
 
53
  
 
54
  long tmp_long;
 
55
  
 
56
  long  pal_m;
 
57
  long pal_n;
 
58
  
 
59
  short baselevel;
 
60
  char filename[128];
 
61
  
 
62
  char firstlevel[20]="levels/level01";
 
63
  char buf[128];
 
64
  
 
65
  levelnum=1;
 
66
  
 
67
  if (readlink(arg[0],buf,128)==-1) 
 
68
    strcpy(buf,arg[0]);
 
69
  
 
70
  n=strlen(buf);
 
71
  while(n>=0)                       
 
72
    if (buf[n--]=='/') break;
 
73
  if (n<0) {
 
74
    strcpy(gamename,"./");
 
75
    gamenamelen=2;
 
76
  }  
 
77
  else {
 
78
    strcpy(gamename,buf);
 
79
    gamename[n+2]=0;
 
80
    gamenamelen=strlen(gamename);
 
81
  }
 
82
  
 
83
 
 
84
  if (n_args>1) {
 
85
    n=0;
 
86
    do {
 
87
      n++;
 
88
    } while ( (strncmp(arg[1],codes[n],6)) && (n<99));
 
89
    if (n!=99) {
 
90
      levelnum=n+1;
 
91
      if (n_args>2)
 
92
        delay_len=atoi(arg[2]);
 
93
    } else {
 
94
      if ((arg[1][0]<'0') || (arg[1][0]>'9')) {
 
95
        printf("\nUsage: %s [code-to-a-given-level] [beam-adjustment]\n"
 
96
               "(Sure you've got the right code?)\n\n",arg[0]);
 
97
        exit(0);
 
98
      }
 
99
      else 
 
100
        delay_len=atoi(arg[1]);
 
101
    } 
 
102
  }    
 
103
  
 
104
  baselevel=levelnum;
 
105
 
 
106
  strcpy(firstlevel,nextlevel);
 
107
 
 
108
 
 
109
  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"
 
110
"\n"
 
111
"-----------------------------------------------------------------------------\n"
 
112
"                         G R A V I T Y    W A R S\n\n"
 
113
"                                   v 1.1\n"
 
114
"                              (November 1995)\n"
 
115
"\n"
 
116
"            A Gravity Force clone for the Linux operating system\n"
 
117
 
 
118
"\n\n"
 
119
"                           Coding by Sami Niemi\n\n"
 
120
 
 
121
"                       Graphics by P�r Johannesson\n"
 
122
 
 
123
"-----------------------------------------------------------------------------\n"
 
124
);
 
125
  initParams();
 
126
  loadGfx();
 
127
  rotGfx();
 
128
 
 
129
  initScreen();
 
130
 
 
131
  keyboard_init();
 
132
  mouse_init("/dev/mouse", MOUSE_MICROSOFT, MOUSE_DEFAULTSAMPLERATE);
 
133
  scans=keyboard_getstate();
 
134
 
 
135
  ending=TRUE;
 
136
 
 
137
  while(ending) {
 
138
 
 
139
    intro();
 
140
    if (escape) 
 
141
      goto escaped;
 
142
    loaddata();
 
143
    drawScreen();
 
144
 
 
145
/*
 
146
    old_x=0;
 
147
    old_y=0;
 
148
    getbox(old_x, old_y, shipback[0]);
 
149
    putbox(old_x, old_y, shipback[0]);
 
150
    moveShip(0,0);
 
151
*/
 
152
    old_x=sx[0] >> STEP;
 
153
    old_y=sy[0] >> STEP;
 
154
    moveShip(0,0);
 
155
 
 
156
    updatescore();
 
157
    win_y=(sy[0] >> STEP)-232;
 
158
    if (win_y<8)
 
159
      win_y=8;
 
160
    else
 
161
      if (win_y>968)
 
162
        win_y=968;
 
163
    putscore(0,win_y); 
 
164
 
 
165
 
 
166
    /*CenterShip*/
 
167
    y=(sy[0] >> STEP)-240;
 
168
    if (y<16)
 
169
      y=16;
 
170
    else
 
171
      if (y>960) 
 
172
        y=960;
 
173
    gl_setdisplaystart(0,y);
 
174
 
 
175
    stampnum(levelnum);
 
176
    putstamp(272,y+184,68,69,70);
 
177
 
 
178
    if (levelnum&1) {
 
179
      for(pal_n=0; pal_n<=1024; pal_n+=16) {
 
180
        for (pal_m=0; pal_m<=767; pal_m++)
 
181
          p1[pal_m]=(((long)pal[pal_m])*pal_n)>>10;
 
182
        vga_waitretrace();
 
183
        gl_setpalette(p1);
 
184
      }
 
185
      gl_setpalette(pal);
 
186
    }
 
187
    else {
 
188
      for(pal_n=0; pal_n<=1024; pal_n+=16) {
 
189
        for (pal_m=0; pal_m<=767; pal_m++)
 
190
          p1[pal_m]=(((long)palB[pal_m])*pal_n)>>10;
 
191
        vga_waitretrace();
 
192
        gl_setpalette(p1);
 
193
      }
 
194
      gl_setpalette(palB);
 
195
    }
 
196
 
 
197
    waitanykey();
 
198
 
 
199
    killstamp(272,y+184);
 
200
 
 
201
    anim_frame=0;
 
202
    ShipScore=0;
 
203
  
 
204
    control(0); 
 
205
 
 
206
    /*------ The End --------*/
 
207
    if (ending) {
 
208
 
 
209
      for(n=0; n<=4095; n++) {
 
210
        tmpscore[n]=score[n];
 
211
        score[n]=highscore[n];
 
212
      }
 
213
 
 
214
      tmp_long=Dec2BCD[ShipScore];
 
215
 
 
216
      putdigit(1375,tmp_long>>16);
 
217
      putdigit(1383,(tmp_long>>12)&15);
 
218
      putdigit(1391,(tmp_long>>8)&15);
 
219
      putdigit(1399,(tmp_long>>4)&15);
 
220
      putdigit(1407,tmp_long&15);
 
221
 
 
222
      if (ShipScore>HighScore) {
 
223
        HighScore=ShipScore;
 
224
 
 
225
        strcpy(filename,gamename);
 
226
        strcpy(&filename[gamenamelen],"data/hscore.gw");
 
227
        if ( ( fileptr=fopen(filename,"w") )!=NULL) {
 
228
          fprintf(fileptr,"%d\n",ShipScore);
 
229
          fclose(fileptr);
 
230
        }
 
231
        else {
 
232
          printf("Can't write the HighScore!!!!");
 
233
          doPanic();
 
234
        }
 
235
      }
 
236
 
 
237
      tmp_long=Dec2BCD[HighScore];
 
238
 
 
239
      putdigit(1474,tmp_long>>16);
 
240
      putdigit(1482,(tmp_long>>12)&15);
 
241
      putdigit(1490,(tmp_long>>8)&15);
 
242
      putdigit(1498,(tmp_long>>4)&15);
 
243
      putdigit(1506,tmp_long&15);
 
244
 
 
245
      putscoreOnly(0,win_y);
 
246
 
 
247
      putstamp(272,win_y+192,54,60,61);
 
248
      waitanykey();
 
249
      killstamp(272,win_y+192);
 
250
      if (*(scans+SCANCODE_ESCAPE))
 
251
        goto escaped;
 
252
 
 
253
      for(n=0; n<=4095; n++) {
 
254
        score[n]=tmpscore[n];
 
255
      }
 
256
 
 
257
      if (levelnum&1) {
 
258
        for(pal_n=1024; pal_n>=0; pal_n-=16) {
 
259
          for (pal_m=0; pal_m<=767; pal_m++)
 
260
            p1[pal_m]=(((long)pal[pal_m])*pal_n)>>10;
 
261
          vga_waitretrace();
 
262
          gl_setpalette(p1);
 
263
        }
 
264
        gl_setpalette(p0);
 
265
      }
 
266
      else {
 
267
        for(pal_n=1024; pal_n>=0; pal_n-=16) {
 
268
          for (pal_m=0; pal_m<=767; pal_m++)
 
269
            p1[pal_m]=(((long)palB[pal_m])*pal_n)>>10;
 
270
          vga_waitretrace();
 
271
          gl_setpalette(p1);
 
272
        }
 
273
        gl_setpalette(p0);
 
274
      }
 
275
 
 
276
      strcpy(nextlevel,firstlevel);
 
277
      levelnum=baselevel;
 
278
      ShipLife=3;
 
279
    }
 
280
 
 
281
  }
 
282
 escaped:    
 
283
 
 
284
  mouse_close();
 
285
  keyboard_close();
 
286
 
 
287
  vga_setmode(TEXT);
 
288
  printf("\n");
 
289
  exit(0);
 
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