1 /* $Id: info.c,v 1.8 2005/07/02 05:32:28 oohara Exp $ */
2
3 #include <stdio.h>
4 /* strlen */
5 #include <string.h>
6
7 #include "tenm_object.h"
8 #include "const.h"
9 #include "util.h"
10 #include "score.h"
11 #include "ship.h"
12 #include "chain.h"
13
14 #include "info.h"
15
16 static int chain_scroll = 0;
17 static int ship_scroll = 0;
18 static int score_scroll = 0;
19
20 void
clear_chain_scroll(void)21 clear_chain_scroll(void)
22 {
23 chain_scroll = 0;
24 }
25
26 /* return 0 on success, 1 on error */
27 int
show_chain(const tenm_object * player)28 show_chain(const tenm_object *player)
29 {
30 char temp[16];
31 int chain;
32
33 /* sanity check */
34 chain = get_chain();
35 if (chain < 0)
36 return 0;
37
38 /* hide the stat if the game is still on and
39 * if the player is near it
40 */
41 if ((player != NULL) && (get_ship() >= 0)
42 && (player->x > (double) (WINDOW_WIDTH * 2 / 3))
43 && (player->y < 60.0))
44 {
45 if (chain_scroll < 20)
46 chain_scroll += 2;
47 }
48 else
49 {
50 if (chain_scroll > 0)
51 chain_scroll -= 2;
52 }
53
54 sprintf(temp, "chain %4d", chain);
55 if (draw_string(WINDOW_WIDTH - 100, 10 - chain_scroll,
56 temp, (int) strlen(temp)) != 0)
57 {
58 fprintf(stderr, "show_chain: draw_string failed\n");
59 return 1;
60 }
61 return 0;
62 }
63
64 void
clear_ship_scroll(void)65 clear_ship_scroll(void)
66 {
67 ship_scroll = 0;
68 }
69
70 /* return 0 on success, 1 on error */
71 int
show_ship(const tenm_object * player)72 show_ship(const tenm_object *player)
73 {
74 int ship;
75 char temp[16];
76
77 /* sanity check */
78 ship = get_ship();
79 if (ship < 0)
80 return 0;
81
82 /* hide the stat if the game is still on and
83 * if the player is near it
84 */
85 if ((player != NULL) && (get_ship() >= 0)
86 && (player->x > (double) (WINDOW_WIDTH * 2 / 3))
87 && (player->y > (double) (WINDOW_HEIGHT - 60)))
88 {
89 if (ship_scroll < 20)
90 ship_scroll += 2;
91 }
92 else
93 {
94 if (ship_scroll > 0)
95 ship_scroll -= 2;
96 }
97
98 sprintf(temp, "ship %3d", ship);
99 if (draw_string(WINDOW_WIDTH - 80, WINDOW_HEIGHT - 10 + ship_scroll,
100 temp, (int) strlen(temp)) != 0)
101 {
102 fprintf(stderr, "show_ship: draw_string failed\n");
103 return 1;
104 }
105
106 return 0;
107 }
108
109 void
clear_score_scroll(void)110 clear_score_scroll(void)
111 {
112 score_scroll = 0;
113 }
114
115 /* return 0 on success, 1 on error */
116 int
show_score(const tenm_object * player)117 show_score(const tenm_object *player)
118 {
119 int score;
120 char temp[32];
121
122 score = get_score();
123
124 /* hide the stat if the game is still on and
125 * if the player is near it
126 */
127 if ((player != NULL) && (get_ship() >= 0)
128 && (player->x < (double) (WINDOW_WIDTH / 3))
129 && (player->y > (double) (WINDOW_HEIGHT - 60)))
130 {
131 if (score_scroll < 20)
132 score_scroll += 2;
133 }
134 else
135 {
136 if (score_scroll > 0)
137 score_scroll -= 2;
138 }
139
140 sprintf(temp, "score %8d", score);
141 if (draw_string(10, WINDOW_HEIGHT - 10 + score_scroll,
142 temp, (int) strlen(temp)) != 0)
143 {
144 fprintf(stderr, "show_score: draw_string failed\n");
145 return 1;
146 }
147 return 0;
148 }
149