1 /* $Id: main.c,v 1.271 2009/11/10 18:50:55 oohara Exp $ */
2
3 #include <stdio.h>
4 /* rand, exit */
5 #include <stdlib.h>
6 /* time */
7 #include <time.h>
8
9 #include "const.h"
10 #include "tenm_graphic.h"
11 #include "tenm_input.h"
12 #include "tenm_math.h"
13 #include "tenm_table.h"
14 #include "tenm_timer.h"
15 #include "util.h"
16 #include "loop.h"
17 #include "title.h"
18 #include "option.h"
19 #include "background.h"
20 #include "show-record.h"
21
22 /* note that delay granularity is 10 ms */
23 #define NUM_WAIT 3
24
25 int
main(int argc,char * argv[])26 main(int argc, char *argv[])
27 {
28 int temp;
29 int choice;
30 const option *op = NULL;
31 int graphic_flag;
32
33 if (set_option(argc, argv) != 0)
34 {
35 fprintf(stderr, "main: set_option failed\n");
36 return 1;
37 }
38 op = get_option();
39 if (op == NULL)
40 {
41 fprintf(stderr, "main: get_option failed\n");
42 return 1;
43 }
44
45 if (op->help != 0)
46 {
47 do_help();
48 return 0;
49 }
50 if (op->version != 0)
51 {
52 do_version();
53 return 0;
54 }
55
56 srand((unsigned int) time(NULL));
57
58 if (op->full_screen != 0)
59 graphic_flag = TENM_FULLSCREEN;
60 else
61 graphic_flag = 0;
62 tenm_graphic_init(WINDOW_WIDTH, WINDOW_HEIGHT, graphic_flag, "dangen");
63 set_background(0);
64 clear_window_with_background();
65 tenm_timer_init(NUM_WAIT);
66 if (tenm_math_init(810, 11) != 0)
67 fprintf(stderr, "main: tenm_math_init failed, continuing (can be slow)\n");
68 tenm_table_init(256, -1, 1);
69 tenm_set_key(8, TENM_KEY_UP, TENM_KEY_DOWN, TENM_KEY_RIGHT, TENM_KEY_LEFT,
70 TENM_KEY_SPACE, TENM_KEY_ESCAPE, TENM_KEY_p, TENM_KEY_s);
71
72 temp = tenm_joystick_init(8192);
73 if (temp == TENM_JOYSTICK_INIT_ERROR)
74 {
75 fprintf(stderr, "main: tenm_joystick_init failed\n");
76 return 1;
77 }
78 else if (temp == TENM_JOYSTICK_INIT_NO_JOYSTICK)
79 {
80 fprintf(stderr, "main: don't worry, just use the keyboard\n");
81 }
82 else
83 {
84 tenm_joystick_map_axis(TENM_JOYSTICK_UP, TENM_KEY_UP);
85 tenm_joystick_map_axis(TENM_JOYSTICK_DOWN, TENM_KEY_DOWN);
86 tenm_joystick_map_axis(TENM_JOYSTICK_LEFT, TENM_KEY_LEFT);
87 tenm_joystick_map_axis(TENM_JOYSTICK_RIGHT, TENM_KEY_RIGHT);
88 tenm_joystick_map_button(0, TENM_KEY_SPACE);
89 }
90 util_init(WINDOW_WIDTH, WINDOW_HEIGHT);
91
92 while (1 == 1)
93 {
94 choice = title();
95 if (choice == 3)
96 break;
97 if (choice == 2)
98 {
99 if (show_record() != 0)
100 break;
101
102 continue;
103 }
104
105 if (game_loop(choice) != 0)
106 break;
107 }
108
109 return 0;
110 }
111