added mousewheel support. added next/prev weapon support

This commit is contained in:
Magnus Auvinen 2007-10-04 22:37:35 +00:00
parent 10812e621a
commit b73dcec397
9 changed files with 103 additions and 83 deletions

View file

@ -324,6 +324,32 @@ projectileparticles {
} }
weapons { weapons {
hammer {
sprite_body sprites.game.weapon_hammer_body
sprite_cursor sprites.game.weapon_hammer_cursor
sprite_proj sprites.game.weapon_hammer_proj
sprite_muzzles {
}
nummuzzlesprites 0
muzzleoffsetx 0.0
muzzleoffsety 0.0
maxammo 10
costammo 0
recoil 10
firedelay 150
muzzleduration 0
visual_size 96
offsetx 4.0
offsety -20.0
meleedamage 4
meleereach 40
ammoregentime 0
duration -1
movetime 0
velocity 0
}
gun { gun {
sprite_body sprites.game.weapon_gun_body sprite_body sprites.game.weapon_gun_body
sprite_cursor sprites.game.weapon_gun_cursor sprite_cursor sprites.game.weapon_gun_cursor
@ -353,32 +379,6 @@ weapons {
velocity 0 velocity 0
} }
rocket {
sprite_body sprites.game.weapon_rocket_body
sprite_cursor sprites.game.weapon_rocket_cursor
sprite_proj sprites.game.weapon_rocket_proj
sprite_muzzles {
}
nummuzzlesprites 0
muzzleoffsetx 0.0
muzzleoffsety 0.0
maxammo 10
costammo 1
recoil 10
firedelay 600
muzzleduration 0
visual_size 96
offsetx 24.0
offsety -2.0
meleedamage 0
meleereach 0
ammoregentime 0
duration -1
movetime 0
velocity 0
}
shotgun { shotgun {
sprite_body sprites.game.weapon_shotgun_body sprite_body sprites.game.weapon_shotgun_body
sprite_cursor sprites.game.weapon_shotgun_cursor sprite_cursor sprites.game.weapon_shotgun_cursor
@ -407,36 +407,11 @@ weapons {
movetime 0 movetime 0
velocity 0 velocity 0
} }
hammer { rocket {
sprite_body sprites.game.weapon_hammer_body sprite_body sprites.game.weapon_rocket_body
sprite_cursor sprites.game.weapon_hammer_cursor sprite_cursor sprites.game.weapon_rocket_cursor
sprite_proj sprites.game.weapon_hammer_proj sprite_proj sprites.game.weapon_rocket_proj
sprite_muzzles {
}
nummuzzlesprites 0
muzzleoffsetx 0.0
muzzleoffsety 0.0
maxammo 10
costammo 0
recoil 10
firedelay 150
muzzleduration 0
visual_size 96
offsetx 4.0
offsety -20.0
meleedamage 4
meleereach 40
ammoregentime 0
duration -1
movetime 0
velocity 0
}
rocket_backpack {
sprite_body sprites.game.weapon_hammer_body
sprite_cursor sprites.game.weapon_hammer_cursor
sprite_proj sprites.game.weapon_hammer_proj
sprite_muzzles { sprite_muzzles {
} }
@ -446,18 +421,19 @@ weapons {
maxammo 10 maxammo 10
costammo 1 costammo 1
recoil 10 recoil 10
firedelay 100 firedelay 600
muzzleduration 0 muzzleduration 0
visual_size 64 visual_size 96
offsetx 4.0 offsetx 24.0
offsety -20.0 offsety -2.0
meleedamage 1 meleedamage 0
meleereach 25 meleereach 0
ammoregentime 0 ammoregentime 0
duration -1 duration -1
movetime 0 movetime 0
velocity 0 velocity 0
} }
ninja { ninja {
sprite_body sprites.game.weapon_ninja_body sprite_body sprites.game.weapon_ninja_body
sprite_cursor sprites.game.weapon_ninja_cursor sprite_cursor sprites.game.weapon_ninja_cursor

View file

@ -9,6 +9,8 @@ f = file("src/engine/keys.h", "w")
keynames = {} keynames = {}
KEY_MOUSE_FIRST = 256+128 KEY_MOUSE_FIRST = 256+128
KEY_MOUSE_WHEEL_DOWN = KEY_MOUSE_FIRST-2
KEY_MOUSE_WHEEL_UP = KEY_MOUSE_FIRST-1
print >>f, "#ifndef ENGINE_KEYS_H" print >>f, "#ifndef ENGINE_KEYS_H"
print >>f, "#define ENGINE_KEYS_H" print >>f, "#define ENGINE_KEYS_H"
@ -31,11 +33,16 @@ for line in lines:
# print to file # print to file
print >>f, "\t%s = %s," % (key.upper(), value) print >>f, "\t%s = %s," % (key.upper(), value)
# add to keynames # add to keynames
exec("%s = %s" % (key, value)) exec("%s = %s" % (key, value))
exec("keynames[%s] = '%s'" % (value, key)) exec("keynames[%s] = '%s'" % (value, key))
# do mouse buttons # do mouse buttons
print >>f, "\tKEY_MOUSE_WHEEL_DOWN = %d," % (KEY_MOUSE_WHEEL_DOWN)
print >>f, "\tKEY_MOUSE_WHEEL_UP = %d," % (KEY_MOUSE_WHEEL_UP)
keynames[KEY_MOUSE_WHEEL_DOWN] = 'KEY_MOUSE_WHEEL_DOWN'
keynames[KEY_MOUSE_WHEEL_UP] = 'KEY_MOUSE_WHEEL_UP'
print >>f, "\tKEY_MOUSE_FIRST = %d," % KEY_MOUSE_FIRST print >>f, "\tKEY_MOUSE_FIRST = %d," % KEY_MOUSE_FIRST
for line in lines: for line in lines:
if "GLFW_MOUSE" in line and not "CURSOR" in line: if "GLFW_MOUSE" in line and not "CURSOR" in line:

View file

@ -80,7 +80,7 @@ void inp_update()
keyboard_first = 0; keyboard_first = 0;
inp_update(); inp_update();
} }
keyboard_current = keyboard_current^1; keyboard_current = keyboard_current^1;
int i, v; int i, v;
for(i = 0; i < KEY_LAST; i++) for(i = 0; i < KEY_LAST; i++)
@ -92,4 +92,14 @@ void inp_update()
keyboard_state[keyboard_current][i] = v; keyboard_state[keyboard_current][i] = v;
} }
// handle mouse wheel
i = glfwGetMouseWheel();
keyboard_state[keyboard_current][KEY_MOUSE_WHEEL_UP] = 0;
keyboard_state[keyboard_current][KEY_MOUSE_WHEEL_DOWN] = 0;
if(i > 0)
keyboard_state[keyboard_current][KEY_MOUSE_WHEEL_UP] = 1;
if(i < 0)
keyboard_state[keyboard_current][KEY_MOUSE_WHEEL_DOWN] = 1;
glfwSetMouseWheel(0);
} }

View file

@ -386,8 +386,8 @@ static const char key_strings[512][16] =
"#379", "#379",
"#380", "#380",
"#381", "#381",
"#382", "mousewheeldown",
"#383", "mousewheelup",
"mouse1", "mouse1",
"mouse2", "mouse2",
"mouse3", "mouse3",

View file

@ -70,6 +70,8 @@ enum
KEY_KP_EQUAL = (KEY_SPECIAL+61), KEY_KP_EQUAL = (KEY_SPECIAL+61),
KEY_KP_ENTER = (KEY_SPECIAL+62), KEY_KP_ENTER = (KEY_SPECIAL+62),
KEY_REPEAT = 0x00030005, KEY_REPEAT = 0x00030005,
KEY_MOUSE_WHEEL_DOWN = 382,
KEY_MOUSE_WHEEL_UP = 383,
KEY_MOUSE_FIRST = 384, KEY_MOUSE_FIRST = 384,
KEY_MOUSE_1 = KEY_MOUSE_FIRST+0, KEY_MOUSE_1 = KEY_MOUSE_FIRST+0,
KEY_MOUSE_2 = KEY_MOUSE_FIRST+1, KEY_MOUSE_2 = KEY_MOUSE_FIRST+1,

View file

@ -1780,7 +1780,7 @@ void render_game()
input.target_x = (int)mouse_pos.x; input.target_x = (int)mouse_pos.x;
input.target_y = (int)mouse_pos.y; input.target_y = (int)mouse_pos.y;
input.activeweapon = -1; input.activeweapon = 0;
if(chat_mode != CHATMODE_NONE) if(chat_mode != CHATMODE_NONE)
input.state = STATE_CHATTING; input.state = STATE_CHATTING;
@ -1795,13 +1795,14 @@ void render_game()
// TODO: this is not very well done. it should check this some other way // TODO: this is not very well done. it should check this some other way
input.fire = emoticon_selector_active ? 0 : inp_key_pressed(config.key_fire); input.fire = emoticon_selector_active ? 0 : inp_key_pressed(config.key_fire);
input.hook = inp_key_pressed(config.key_hook); input.hook = inp_key_pressed(config.key_hook);
//input.blink = inp_key_pressed('S');
// Weapon switching // Weapon switching
if(inp_key_pressed(config.key_weapon1)) input.activeweapon = 0; if(inp_key_pressed(config.key_next_weapon)) input.activeweapon = -1;
if(inp_key_pressed(config.key_weapon2)) input.activeweapon = 1; if(inp_key_pressed(config.key_prev_weapon)) input.activeweapon = -2;
if(inp_key_pressed(config.key_weapon3)) input.activeweapon = 2; if(inp_key_pressed(config.key_weapon1)) input.activeweapon = 1;
if(inp_key_pressed(config.key_weapon4)) input.activeweapon = 3; if(inp_key_pressed(config.key_weapon2)) input.activeweapon = 2;
if(inp_key_pressed(config.key_weapon3)) input.activeweapon = 3;
if(inp_key_pressed(config.key_weapon4)) input.activeweapon = 4;
} }
// stress testing // stress testing

View file

@ -807,10 +807,12 @@ static int settings_controls_render()
{ "Jump:", &config_copy.key_jump, config_set_key_jump }, { "Jump:", &config_copy.key_jump, config_set_key_jump },
{ "Fire:", &config_copy.key_fire, config_set_key_fire }, { "Fire:", &config_copy.key_fire, config_set_key_fire },
{ "Hook:", &config_copy.key_hook, config_set_key_hook }, { "Hook:", &config_copy.key_hook, config_set_key_hook },
{ "Pistol:", &config_copy.key_weapon1, config_set_key_weapon1 }, { "Hammer:", &config_copy.key_weapon1, config_set_key_weapon1 },
{ "Grenade:", &config_copy.key_weapon2, config_set_key_weapon2 }, { "Pistol:", &config_copy.key_weapon2, config_set_key_weapon2 },
{ "Shotgun:", &config_copy.key_weapon3, config_set_key_weapon3 }, { "Shotgun:", &config_copy.key_weapon3, config_set_key_weapon3 },
{ "Hammer:", &config_copy.key_weapon4, config_set_key_weapon4 }, { "Grenade:", &config_copy.key_weapon4, config_set_key_weapon4 },
{ "Next Weapon:", &config_copy.key_next_weapon, config_set_key_next_weapon },
{ "Prev. Weapon:", &config_copy.key_prev_weapon, config_set_key_prev_weapon },
{ "Emoticon:", &config_copy.key_emoticon, config_set_key_emoticon }, { "Emoticon:", &config_copy.key_emoticon, config_set_key_emoticon },
{ "Screenshot:", &config_copy.key_screenshot, config_set_key_screenshot }, { "Screenshot:", &config_copy.key_screenshot, config_set_key_screenshot },
}; };

View file

@ -7,6 +7,10 @@ MACRO_CONFIG_INT(key_weapon1, '1', 32, 512)
MACRO_CONFIG_INT(key_weapon2, '2', 32, 512) MACRO_CONFIG_INT(key_weapon2, '2', 32, 512)
MACRO_CONFIG_INT(key_weapon3, '3', 32, 512) MACRO_CONFIG_INT(key_weapon3, '3', 32, 512)
MACRO_CONFIG_INT(key_weapon4, '4', 32, 512) MACRO_CONFIG_INT(key_weapon4, '4', 32, 512)
MACRO_CONFIG_INT(key_next_weapon, 382, 32, 512)
MACRO_CONFIG_INT(key_prev_weapon, 383, 32, 512)
MACRO_CONFIG_INT(key_emoticon, 'E', 32, 512) MACRO_CONFIG_INT(key_emoticon, 'E', 32, 512)
MACRO_CONFIG_INT(key_chat, 'T', 32, 512) MACRO_CONFIG_INT(key_chat, 'T', 32, 512)

View file

@ -725,16 +725,34 @@ int player::handle_weapons()
} }
// switch weapon if wanted // switch weapon if wanted
if(input.activeweapon >= 0 && input.activeweapon < NUM_WEAPONS && weapons[input.activeweapon].got && if(input.activeweapon && data->weapons[active_weapon].duration <= 0)
data->weapons[active_weapon].duration <= 0)
{ {
if (active_weapon != input.activeweapon) int new_weapon = active_weapon;
create_sound(pos, SOUND_WEAPON_SWITCH); if(input.activeweapon > 0) // straight selection
new_weapon = input.activeweapon-1;
else if(input.activeweapon == -1 && !previnput.activeweapon) // next weapon
{
do
new_weapon = (new_weapon+1)%NUM_WEAPONS;
while(!weapons[new_weapon].got);
}
else if(input.activeweapon == -2 && !previnput.activeweapon)
{
do
new_weapon = (new_weapon-1)<0?NUM_WEAPONS-1:new_weapon-1;
while(!weapons[new_weapon].got);
}
if(new_weapon >= 0 && new_weapon < NUM_WEAPONS && weapons[new_weapon].got)
{
if(active_weapon != new_weapon)
create_sound(pos, SOUND_WEAPON_SWITCH);
last_weapon = active_weapon; last_weapon = active_weapon;
active_weapon = input.activeweapon; active_weapon = new_weapon;
}
} }
if(!previnput.fire && input.fire) if(!previnput.fire && input.fire)
{ {
if(reload_timer == 0) if(reload_timer == 0)