Store user data in $HOME
[kball.git] / include / control.h
blob13ad6d7549ccbae1e80ea303cf1f162aba2bcfc2
1 // -----------------------------------------------------------------------
2 // Controller wrapper
3 // control.cpp
4 // -----------------------------------------------------------------------
5 // This class handles a generic controller.
6 // Simulates a 8 way gamepad with 6 buttons using keyboard,joystick,mouse
7 // By Kronoman - In loving memory of my father
8 // Copyright (c) 2003 - Released under the MIT license
9 // 08-NOV-2003
11 // ** NOTE **
12 // Modified 04-MAR-2004 to add customize control interface.
13 // This class is arcane, I have a better implementation.
15 // We will use this in this game, in future games, we will use the new implementation.
17 // **** NOTICE ****
18 // THIS PARTICULAR GAME, KBALL DOES NOT NEED BUTTONS, SO IS DISABLED IN INTERACTIVE CONFIGURATION!
19 // ** NOTICE ** I CHANGED SOME DATA TO PUBLIC DUE TO KBALL REQUIREMENTS!
20 // -----------------------------------------------------------------------
22 #ifndef KCONTROL_H
23 #define KCONTROL_H
25 #include <allegro.h>
28 // This are the return values of the controller
29 // they are returned as a bit mask
30 // So, all joystick input is DIGITAL
31 #define KC_NONE 0
32 #define KC_UP 1
33 #define KC_DOWN 2
34 #define KC_LEFT 4
35 #define KC_RIGHT 8
37 // buttons (there is room left, for adding more axis in future)
38 #define KC_BTN1 256
39 #define KC_BTN2 512
40 #define KC_BTN3 1024
41 #define KC_BTN4 2048
42 #define KC_BTN5 4096
43 #define KC_BTN6 8192
45 class CController
47 public:
48 CController();
49 ~CController();
51 // Set functions
52 // -------------
54 // keyboard
55 void set_default_keyboard(); // we have a 'default' configuration for keyboard
56 void set_keyboard_par(int value, int index); // this sets one value for key_val[] array
57 void set_use_keyboard(bool use); // set if you want to use keyboard input or not
58 void interactive_configuration_keyboard(FONT *font, int color); // to interactive configure keyboard
60 // mouse
61 void set_mouse_sens(int s); // set mouse sensitiviness
62 void set_use_mouse(bool use); // use the mouse?
63 void interactive_configuration_mouse(FONT *font, int color); // interactive configure mouse
65 // joystick
66 void set_joystick_number(int n); // wich joystick you want to input?
67 void set_use_joystick(bool use); // use the joystick?
68 void interactive_configuration_joystick(FONT *font, int color); // interactive configure joystick
70 // Get functions
71 // -------------
73 // this is the one that does the actual input from user
74 int do_input_poll();
76 int get_keyboard_par(int value, int index); // get keyboard key, -1 on error (bad index passed)
77 bool get_use_keyboard() { return this->use_keyboard; }
79 bool get_use_mouse() { return this->use_mouse; }
80 int get_mouse_sens() { return this->mouse_sens; }
82 bool get_use_joystick() { return this->use_joystick; }
83 int get_joystick_number() { return this->joy_num; }
85 int get_controller_id() { return this->controller_id; } // unique controller ID (assigned by creation)
87 // Config saving stuff
88 // NOTICE: you have to _previously_ call to allegro's set_config_file
89 void save_configuration_of_controller(char *cfg_section); // save current configuration in a file (cfg_section = section)
90 void load_configuration_of_controller(char *cfg_section); // load configuration from a config file (cfg_section = section)
92 // Static members (available from the class itself)
93 // --------------
95 static int get_controller_count() { return CController::controller_count; }
97 // ** NOTICE ** I CHANGED SOME DATA TO PUBLIC DUE TO KBALL REQUIREMENTS!
98 bool use_keyboard; // want to use keyboard input? (default=true)
99 bool use_joystick; // want to use joystick? (default=false)
100 bool use_mouse; // use mouse input? (default=true)
102 private:
103 // keyboard stuff
104 int key_val[15]; // keys to input: 0..3= up,down,left,right | 4..7= reserved | 8..13= buttons | 14= reserved
107 // joystick stuff
108 int joy_num; // wich joystick to use? 0..num_joysticks (default=0)
111 // mouse stuff
112 int mouse_sens; // square of 'dead' until mouse movement is detected; (default 10, smaller is more sens)
114 // ID of controller
115 int controller_id; // controller ID: automated (useful for saving configuration, you can have different sections, well, use it for something... )
117 // static members, available to all
118 static int controller_count;
121 #endif