1 /* $Id: stage-title.c,v 1.7 2011/08/23 20:49:38 oohara Exp $ */
2
3 #include <stdio.h>
4 /* malloc */
5 #include <stdlib.h>
6 /* strlen, strcmp */
7 #include <string.h>
8
9 #include "const.h"
10 #include "tenm_object.h"
11 #include "tenm_graphic.h"
12 #include "util.h"
13 #include "tenm_table.h"
14 #include "stage.h"
15
16 #include "stage-title.h"
17
18 static int stage_title_act(tenm_object *my, const tenm_object *player);
19 static int stage_title_draw(tenm_object *my, int priority);
20
21 tenm_object *
stage_title_new(void)22 stage_title_new(void)
23 {
24 tenm_object *new = NULL;
25 int *count = NULL;
26
27 count = (int *) malloc(sizeof(int) * 1);
28 if (count == NULL)
29 {
30 fprintf(stderr, "stage_title_new: malloc(count) failed\n");
31 return NULL;
32 }
33
34 /* list of count
35 * [0] timer
36 */
37 count[0] = 0;
38
39 new = tenm_object_new("stage title", 0, 0,
40 1, 0.0, 0.0,
41 1, count, 0, NULL, 0, NULL,
42 (int (*)(tenm_object *, double))
43 NULL,
44 (int (*)(tenm_object *, tenm_object *))
45 NULL,
46 (int (*)(tenm_object *, const tenm_object *))
47 (&stage_title_act),
48 (int (*)(tenm_object *, int))
49 (&stage_title_draw));
50
51 if (new == NULL)
52 {
53 fprintf(stderr, "stage_title_new: tenm_object_new failed\n");
54 if (count != NULL)
55 free(count);
56 return NULL;
57 }
58
59 return new;
60 }
61
62 static int
stage_title_act(tenm_object * my,const tenm_object * player)63 stage_title_act(tenm_object *my, const tenm_object *player)
64 {
65 /* sanity check */
66 if (my == NULL)
67 {
68 fprintf(stderr, "stage_title_act: my is NULL\n");
69 return 0;
70 }
71 if (player == NULL)
72 return 0;
73
74 (my->count[0])++;
75 if (my->count[0] >= 100)
76 return 1;
77
78 return 0;
79 }
80
81 static int
stage_title_draw(tenm_object * my,int priority)82 stage_title_draw(tenm_object *my, int priority)
83 {
84 int status = 0;
85 char temp[32];
86
87 /* sanity check */
88 if ((get_stage_number() < 1) || (get_stage_number() > 5))
89 return 0;
90 if (get_stage_name(get_stage_number()) == NULL)
91 return 0;
92
93 if (priority != 1)
94 return 0;
95
96 if (get_stage_number() <= 4)
97 sprintf(temp, "stage %d", get_stage_number());
98 else
99 sprintf(temp, "final stage");
100 if (draw_string(WINDOW_WIDTH / 2 - ((int) strlen(temp)) * 9 / 2, 190,
101 temp, (int) strlen(temp)) != 0)
102 {
103 fprintf(stderr, "stage_title_draw: draw_string (stage number) failed\n");
104 status = 1;
105 }
106
107 sprintf(temp, "%.20s", get_stage_name(get_stage_number()));
108 if (draw_string(WINDOW_WIDTH / 2 - ((int) strlen(temp)) * 9 / 2, 220,
109 temp, (int) strlen(temp)) != 0)
110 {
111 fprintf(stderr, "stage_title_draw: draw_string (stage name) failed\n");
112 status = 1;
113 }
114
115 return status;
116 }
117