File: pause.c

package info (click to toggle)
tenmado 0.10-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,208 kB
  • sloc: ansic: 22,906; sh: 1,072; yacc: 321; makefile: 300; lex: 170
file content (92 lines) | stat: -rw-r--r-- 1,653 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
/* $Id: pause.c,v 1.14 2002/07/10 11:01:37 oohara Exp $ */

#include <stdio.h>

/* WINDOW_WIDTH */
#include "const.h"
/* draw_string() */
#include "util.h"
/* tenm_redraw_window() */
#include "tenm_graphic.h"

#include "pause.h"

static int paused = 0;
static int paused_modify_ok = 1;

static int show_pause_message(void);

void
clear_pause(void)
{
  paused = 0;
  paused_modify_ok = 1;
}

/* return 1 if the game is paused, 0 if not */
int
do_pause(int pause_key_pressed)
{
  if (pause_key_pressed)
  {
    if (paused_modify_ok)
    {
      paused_modify_ok = 0;
      if (paused)
      {
        paused = 0;
      }
      else
      {
        paused = 1;
        if (show_pause_message() != 0)
          fprintf(stderr, "do_pause: show_pause_message failed\n");
      }
    }
  }
  else
  {
    paused_modify_ok = 1;
  }

  if (paused)
    return 1;

  return 0;
}

/* pause the game if the mouse cursor is out of the window
 * note that moving the mouse cursor into the window does not
 * continue the game
 */
void
pause_by_mouse(int gain)
{
  if ((gain != 1) && (!(paused)))
  {
    paused = 1;
    if (show_pause_message() != 0)
      fprintf(stderr, "pause_by_mouse: show_pause_message failed\n");
  }
}

/* return 0 on success, 1 on error */
static int
show_pause_message(void)
{
  int status = 0;

  if (draw_string(10, WINDOW_HEIGHT - 40, "paused --- press p "
                  "to continue", 30) != 0)
  {
    fprintf(stderr, "show_pause_message: draw_string failed\n");
    status = 1;
  }
  if (tenm_redraw_window() != 0)
  {
    fprintf(stderr, "show_pause_message: tenm_redraw_window failed\n");
    status = 1;
  }

  return status;
}