File: ned.cc

package info (click to toggle)
nighthawk 1.0-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,420 kB
  • ctags: 18,064
  • sloc: fortran: 17,597; cpp: 4,948; makefile: 87; sh: 13
file content (152 lines) | stat: -rw-r--r-- 3,707 bytes parent folder | download | duplicates (6)
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
/***************************************************************************
****************************************************************************
****************************************************************************
*
* NightHawk - By Jason Nunn - Oct 96  (jsno@dayworld.net.au)
* FREEWARE.
*
* Xwindows (C++)
*
* ==================================================================
* The Floor Editor
*
****************************************************************************
****************************************************************************
***************************************************************************/
extern "C" {
#include <stdio.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/xpm.h>
#include <X11/keysym.h>
}
#include "defs.h"
#include "misc.h"
#include "tedit_floor.h"

#define UPDATE_DELAY 100000
#define REALTIME_DELAY 50000

tedit_floor edit_floor;
int         end_game = 0;

/***************************************************************************
*
***************************************************************************/
void fg_loop(void)
{
  edit_floor.draw();
  XCopyArea(display,render_screen,window,gc_bgblt,0,0,
    window_width,window_height,0,0);
  while(!end_game)
  {
    XEvent event;

    while(XPending(display))
    {
      XNextEvent(display,&event);
      edit_floor.action(&event);
      switch(event.xany.type) 
      {
        case KeyPress:
          switch(XLookupKeysym((XKeyEvent *)&event,0))
          {
            case 'q':
              end_game = 1;
              break;
          }
          break;
      }
      if(event.xany.type == KeyPress)
      {
        edit_floor.draw();
        XCopyArea(display,render_screen,window,gc_bgblt,0,0,
          window_width,window_height,0,0);
      }
    }
  }
}

/***************************************************************************
*
***************************************************************************/
void print_help(void)
{
  printf("Usage: ned <options>\n"
          " -h            Display this help info\n"
          " -n Width Height Indice <floor_map>\n"
          " -l <floor_map>\n"
          "\n");
}

int main(int argc,char *argv[])
{
  register int x,new_f = 1;
  int map_x_size = 2,map_y_size = 2;
  char *map_filename = "";

  printf("Welcome to NightHawk (Floor Editor) - By Jason Nunn\n");
  if(argc == 1)
  {
    print_help();
    return 1;
  }
  edit_floor.default_map_value = 0;
  for(x = 0;x < argc;x++)
  {
    if(argv[x][0] == '-')
    {
      switch(argv[x][1])
      {
        case 'h':
          print_help();
          return 1;
        case 'n':
          new_f = 1;
          sscanf(argv[x + 1],"%d",&map_x_size);
          sscanf(argv[x + 2],"%d",&map_y_size);
          sscanf(argv[x + 3],"%d",&edit_floor.default_map_value);
          map_filename = (char *)argv[x + 4];
          break;
        case 'l':
          new_f = 0;
          map_filename = (char *)argv[x + 1];
          break;
      }
    }
  }
  if(x_init())
  {
    XAutoRepeatOn(display);
    if(load_flr_xpms())
    {
      if(load_sprite_xpms())
      {
        edit_floor.init_colours();
        x = 1;
        if(new_f)
        {
          if(!edit_floor.create(map_filename,map_x_size,map_y_size))
            x = 0;
        }
        else
          if(!edit_floor.load(map_filename,"Edit"))
            x = 0;
        if(x)
        {
          XMapWindow(display,window);
          XSync(display,0);
          printf("Running..\n");
          fg_loop();
          edit_floor.unload();
        }
        free_sprite_xpms();
      }
      free_flr_xpms();
    }
    Xreaper();
  }
  printf("See ya\n");
  return 1;
}