一些控制器具有相同的布局但面部不同,例如360和PS3(X是A,三角形是Y等)。像打斗棒,飞行杆,吉他等额外外设 - 它们只是映射到控制台预期的不同面孔。由于按钮通常在任何控制器被塑造之前就已经定义,所以你可以做同样的事情。
每个映射并不都适用于每个控制器,因此可能不是理想的-考虑到现代控制器,它应该没问题。如果加入Intellivision控制器和键盘/鼠标,事情可能会变得奇怪。
// using CHAR(8) for absolutely no good reason. change at will.
CREATE TABLE button_maps (
id tinyint unsigned not null auto_increment,
map_id char(8) not null,
primary key (id),
unique key map_id (map_id)
);
INSERT INTO button_maps (map_id)
VALUES
// dual analog, any direction
('ANA_LFT'), ('ANA_RT'),
// 4-button compass face
('BT_N'), ('BT_S'), ('BT_E'), ('BT_W'),
// shoulder buttons
('BT_LT1'), ('BT_LT2'), ('BT_RT1'), ('BT_RT2'),
// system buttons
('BT_START'), ('BT_SEL'), ('BT_MENU'),
// analog stick click-in, usually called "L/R 3"
('ANA_L3'), ('ANA_R3'),
// 8-direction d-pad - add clockface points for both analogs too
('DPAD_N'), ('DPAD_S'), ('DPAD_E'), ('DPAD_W'),
('DPAD_NW'), ('DPAD_NE'), ('DPAD_SW'), ('DPAD_SE'),
// and DS stylus so it's not obvious what I'm looking at right now
('STL_TAP'), ('STL_DTAP'), ('STL_DRAG'),
// and so on
注意:我不知道那些全身动作控制器是如何内部处理的,如果你不得不处理它们,祝你好运。例如:
LFOOT_HOKEYPOKEY
。
注意2:认真点,不要在这里使用char(8)。要详细,但保持足够通用以适用于通用控制器风格,而非品牌。
现在每个控制器品牌的按钮及其名称(假设有一个“controllers”表):
CREATE TABLE buttons (
id tinyint unsigned not null auto_increment,
controller_id tinyint unsigned not null references controllers.id,
map_id tinyint unsigned not null references button_maps.id,
button_name varchar(32) not null,
primary key (id),
unique key controller_map (controller_id, map_id)
);
INSERT INTO buttons (controller_id, map_id, button_name)
VALUES
(2, 1, 'Left Analog'), (2, 2, 'Right Analog'),
(2, 3, 'Y'), (2, 4, 'A'), (2, 5, 'B'), (2, 6, 'X'),
(2, 7, 'Left Trigger (LT)'), (2, 8, 'Right Trigger (RT)'),
(2, 9, 'Left Bumper (LB)'), (2, 10, 'Right Bumper (RB)')
// and so on. PS3 with button shapes and R1/2, L1/2 instead of trigger/bumper
现在,对于按钮按下(或多个按钮或序列),它在游戏中代表的行为。这并没有考虑上下文(原始问题的2和3),例如游戏模式或备用按钮配置,但是Josh Smeaton和littlegreen已经涵盖了这一点。
这定义了每个单独游戏的动作,这不是非常有效的。通过添加通用的游戏“类型”层,您可能能够大大压缩事物。某些类型/视角内的许多游戏具有共同的控制方式,这只会变得更加普遍(控制台FPS添加预定义的Halo和CoD样式按钮配置,因为玩家知道它们这样做)。因此,如果您可以定义每种类型的常见操作,并仅在需要时使用此操作来覆盖/扩展这些默认值,则可能能够实现更清洁的解决方案。
首先,定义每个操作:
CREATE TABLE game_actions (
id int unsigned not null auto_increment,
game_id int unsigned not null references games.id,
action varchar(32) not null,
primary key (id)
);
INSERT INTO game_actions (game_id, action)
VALUES (1, 'Shoot'), (1, 'Reload'), (1, 'Turn Left'), (1, 'Turn Right')
// and so on
最后,定义与每个动作相关联的按钮按下。 "序数"字段用于组合序列,例如格斗游戏中的连招 - 单个动作为0序数,序列从1开始计数,只是为了方便区分它们。它不考虑时间因素,因此您可能需要一个“无操作”按钮作为一些更复杂的连招游戏(如Soul Caliber等)的休息。
CREATE TABLE game_action_buttons (
id int unsigned not null auto_increment,
game_action_id int unsigned not null references game_actions.id,
ordinal tinyint unsigned not null,
button_map_id tinyint unsigned not null references button_maps.id,
primary key (id)
);
INSERT INTO game_action_buttons (game_action_id, ordinal, button_map_id)
VALUES
(1, 0, 8), // right trigger to shoot
(2, 0, 6), // west face button (X/square) to reload
(3, 0, 7), (3, 0, 9) // combo: both bumpers for rear view look-back while driving
// and a Street Fighter shoryuken on the d-pad to show a sequence:
(4, 1, 21), // DPAD_E: right
(4, 2, 20), // DPAD_S: down
(4, 3, 26), (4, 3, 4) // DPAD_SE + BT_S: down/right + fierce... i think.
(免责声明:我曾为一家游戏工作室创建过类似的数据库。虽然不完全相同,但足够相似以至于我有意留下了很多细节。抱歉!希望这些足以启发您的灵感,这是一个有趣的问题。)