aboutsummaryrefslogtreecommitdiffstats
path: root/grv.c
blob: 9edc1f382ca7638229a3d8217804d56bc1fb6f2c (plain)
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
/*
 * grv.c
 *
 * Main program - converted from BASIC
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "graphics.h"
#include "grv.h"

struct gameparams gp;
struct monster ghost[MAXGHOST];

void init_gameparams(void)
{
 /* As good a start as any... */
  gp.gameid = (uint64_t)genrand_int32() << 32;
  gp.have_id = 0;

  gp.Sc = 0;
  gp.Life = 3;
  gp.SBs = 0;
  gp.Lvf = 0;
  gp.GkCh = 0;
  gp.MLev = 0;
  gp.KulSpr = 0;
  gp.Level = 0;
  gp.Cheat = 0;
}

static int screen_width = 40;
void initscreen(int w)
{
  if ( w != screen_width )
    width(screen_width = w);

  color(0,gp.c);
  cls();
}

void newlevel(void)
{
  gp.Bon = 0;
  gp.FrSpok = -1;
  gp.TF = -1;
  gp.Hyp = 0;
  gp.Bar = 0;
  gp.ChBd = gp.GkCh;
  gp.FS = 1;			/* Ghosts are not frozen or reversed */
  /* 150 ms/step is the speed for level 0 */
  gp.Speed = (150*ELev)/(gp.Level+ELev);
  gp.EOLWait = 1;
  gp.Tid = 0.0;

  reset_actions();
  addaction(0, 0, 1800.0, act_toolate);	/* 30 minutes -> dead */

  if ( gp.Level == ELev-1 ) {
    /* Last level */
    gp.KulSpr = 0;
  } else {
    /* Not the last level */
    int i, e;
    i = gp.KulSpr;
    for ( e = 0 ; e < i ; e++ ) {
      if ( rnd() < 0.9 )
	gp.KulSpr--;
    }
    if ( gp.KulSpr > 80 )
      gp.KulSpr = 80;
  }

  if ( gp.Level > gp.MLev )
    gp.MLev = gp.Level;

  drawlevel();

  play();
}

void game(void)
{
  init_gameparams();
  while ( gp.Level < ELev && gp.Life >= 0 ) {
    newlevel();
    if ( gp.EOLWait )
      mymssleep(4000);
  }
} 

int main(int argc, char *argv[])
{
  randomize();

  if ( screen_init() ) {
    fprintf(stderr, "%s: Cannot initalize graphics!\n", argv[0]);
    exit(1);
  }

  while ( 1 ) {
    game();
    break;
  }

  return 0;
}