commit 2afbcaf7633a95f4bf0c944c8bfbd57d3abed7da
parent b33b696dcd353397293eaa2265429792bcbdc95a
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 29 Dec 2022 10:45:53 +0900
delete extern variables
Diffstat:
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/ex7/ex7.c b/ex7/ex7.c
@@ -127,7 +127,6 @@ struct rect block[NUM_RECT];
struct rect player;
int player_is_falling;
enum next_menu next_menu = START_MENU;
-extern int win_width, win_height;
/* function prototypes */
@@ -151,6 +150,8 @@ start_menu(void)
{
char *menu_char_q = "press q to quit.";
char *menu_char_s = "press <space> to start.";
+ int win_width, win_height;
+ x_get_win_wh(&win_width, &win_height);
x_clear_area();
x_draw_string(0x00FFFF,
@@ -303,6 +304,9 @@ handle_inputs(enum key_state key_state[])
void
rect_next_tick(struct rect *s, long ndt) // nano second
{
+ int win_width, win_height;
+ x_get_win_wh(&win_width, &win_height);
+
s->ppx = s->px;
s->ppy = s->py;
s->vx += s->ax * ndt / 1000 / 1000 / 1000;
@@ -337,6 +341,9 @@ rect_next_tick(struct rect *s, long ndt) // nano second
void
circle_next_tick(struct circle *c, long ndt)
{
+ int win_width, win_height;
+ x_get_win_wh(&win_width, &win_height);
+
c->ppx = c->px;
c->ppy = c->py;
c->vx += c->ax * ndt / 1000 / 1000 / 1000;
@@ -654,6 +661,9 @@ game_play(void)
void
game_over(void)
{
+ int win_width, win_height;
+ x_get_win_wh(&win_width, &win_height);
+
char *menu_char = "GAME OVER";
x_clear_area();
@@ -669,6 +679,8 @@ game_over(void)
int
main(void)
{
+ int win_width, win_height;
+
win_width = 800;
win_height = 600;
x_setup_window(0, 0, win_width, win_height, 0x000000, "UNKO");
diff --git a/ex7/x.c b/ex7/x.c
@@ -129,3 +129,10 @@ x_pending(void)
{
return XPending(display);
}
+
+void
+x_get_win_wh(int *w, int *h)
+{
+ *w = win_width;
+ *h = win_height;
+}
diff --git a/ex7/x.h b/ex7/x.h
@@ -15,3 +15,4 @@ void x_flush(void);
void x_clean_up(void);
int x_next_event(char *c);
int x_pending(void);
+void x_get_win_wh(int *, int *);