1 /*
2 * Volleyball - video game similary to GNU Arcade Volleyball
3 * Copyright (C) 2005, 2006 Hugo Ruscitti : hugoruscitti@gmail.com
4 * web site: http://www.loosersjuegos.com.ar
5 *
6 * This file is part of Volleyball.
7 *
8 * Volleyball is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Volleyball is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24 #include "player_control.h"
25
26 /*!
27 * \brief inicia el m�dulo
28 * \return el control de un personaje
29 */
player_control_init(Control * control,int player)30 Player_control * player_control_init (Control * control, int player)
31 {
32 Player_control * data;
33
34 data = (Player_control *) malloc (sizeof (Player_control));
35
36 if (! data)
37 {
38 util_print_fail_module ("Player_control");
39 exit (1);
40 }
41
42 data->control = control;
43 data->player = player;
44 data->last_key = -1;
45
46 return data;
47 }
48
49
50 /*!
51 * \brief libera el m�dulo de control
52 * \param data m�dulo principal
53 */
player_control_free(Player_control * data)54 void player_control_free (Player_control * data)
55 {
56 free (data);
57 }
58
59 /*!
60 * \brief indica si el usuario ha pulsado una tecla
61 * \param m�dulo principal
62 * \param key tecla a consultar
63 * \return TRUE en caso afirmativo o FALSE si no se puls� esa tecla
64 */
player_control_query(Player_control * data,enum player_key key)65 int player_control_query (Player_control * data, enum player_key key)
66 {
67 return control_query (data->control, key + 2 + data->player * 5);
68 }
69
70 /*!
71 * \brief indica si el usuario ha pulsado una tecla (sin repetici�n)
72 * \param m�dulo principal
73 * \param key tecla a consultar
74 * \return TRUE en caso afirmativo o FALSE si no se puls� esa tecla
75 */
player_control_query_no_repeat(Player_control * data,enum player_key key)76 int player_control_query_no_repeat (Player_control * data, enum player_key key)
77 {
78 int offset = 2 + data->player * 5;
79
80 if (data->last_key != -1)
81 {
82 if (control_query (data->control, data->last_key + offset))
83 return FALSE;
84 else
85 data->last_key = -1;
86 }
87
88 if (control_query (data->control, key + offset))
89 {
90 data->last_key = key;
91 return TRUE;
92 }
93 else
94 return FALSE;
95 }
96