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 {
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 {
sprite_body sprites.game.weapon_gun_body
sprite_cursor sprites.game.weapon_gun_cursor
@ -353,32 +379,6 @@ weapons {
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 {
sprite_body sprites.game.weapon_shotgun_body
sprite_cursor sprites.game.weapon_shotgun_cursor
@ -408,35 +408,10 @@ weapons {
velocity 0
}
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
}
rocket_backpack {
sprite_body sprites.game.weapon_hammer_body
sprite_cursor sprites.game.weapon_hammer_cursor
sprite_proj sprites.game.weapon_hammer_proj
rocket {
sprite_body sprites.game.weapon_rocket_body
sprite_cursor sprites.game.weapon_rocket_cursor
sprite_proj sprites.game.weapon_rocket_proj
sprite_muzzles {
}
@ -446,18 +421,19 @@ weapons {
maxammo 10
costammo 1
recoil 10
firedelay 100
firedelay 600
muzzleduration 0
visual_size 64
offsetx 4.0
offsety -20.0
meleedamage 1
meleereach 25
visual_size 96
offsetx 24.0
offsety -2.0
meleedamage 0
meleereach 0
ammoregentime 0
duration -1
movetime 0
velocity 0
}
ninja {
sprite_body sprites.game.weapon_ninja_body
sprite_cursor sprites.game.weapon_ninja_cursor

View file

@ -9,6 +9,8 @@ f = file("src/engine/keys.h", "w")
keynames = {}
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, "#define ENGINE_KEYS_H"
@ -36,6 +38,11 @@ for line in lines:
exec("keynames[%s] = '%s'" % (value, key))
# 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
for line in lines:
if "GLFW_MOUSE" in line and not "CURSOR" in line:

View file

@ -92,4 +92,14 @@ void inp_update()
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",
"#380",
"#381",
"#382",
"#383",
"mousewheeldown",
"mousewheelup",
"mouse1",
"mouse2",
"mouse3",

View file

@ -70,6 +70,8 @@ enum
KEY_KP_EQUAL = (KEY_SPECIAL+61),
KEY_KP_ENTER = (KEY_SPECIAL+62),
KEY_REPEAT = 0x00030005,
KEY_MOUSE_WHEEL_DOWN = 382,
KEY_MOUSE_WHEEL_UP = 383,
KEY_MOUSE_FIRST = 384,
KEY_MOUSE_1 = KEY_MOUSE_FIRST+0,
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_y = (int)mouse_pos.y;
input.activeweapon = -1;
input.activeweapon = 0;
if(chat_mode != CHATMODE_NONE)
input.state = STATE_CHATTING;
@ -1796,12 +1796,13 @@ void render_game()
input.fire = emoticon_selector_active ? 0 : inp_key_pressed(config.key_fire);
input.hook = inp_key_pressed(config.key_hook);
//input.blink = inp_key_pressed('S');
// Weapon switching
if(inp_key_pressed(config.key_weapon1)) input.activeweapon = 0;
if(inp_key_pressed(config.key_weapon2)) input.activeweapon = 1;
if(inp_key_pressed(config.key_weapon3)) input.activeweapon = 2;
if(inp_key_pressed(config.key_weapon4)) input.activeweapon = 3;
if(inp_key_pressed(config.key_next_weapon)) input.activeweapon = -1;
if(inp_key_pressed(config.key_prev_weapon)) input.activeweapon = -2;
if(inp_key_pressed(config.key_weapon1)) input.activeweapon = 1;
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

View file

@ -807,10 +807,12 @@ static int settings_controls_render()
{ "Jump:", &config_copy.key_jump, config_set_key_jump },
{ "Fire:", &config_copy.key_fire, config_set_key_fire },
{ "Hook:", &config_copy.key_hook, config_set_key_hook },
{ "Pistol:", &config_copy.key_weapon1, config_set_key_weapon1 },
{ "Grenade:", &config_copy.key_weapon2, config_set_key_weapon2 },
{ "Hammer:", &config_copy.key_weapon1, config_set_key_weapon1 },
{ "Pistol:", &config_copy.key_weapon2, config_set_key_weapon2 },
{ "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 },
{ "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_weapon3, '3', 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_chat, 'T', 32, 512)

View file

@ -725,14 +725,32 @@ int player::handle_weapons()
}
// switch weapon if wanted
if(input.activeweapon >= 0 && input.activeweapon < NUM_WEAPONS && weapons[input.activeweapon].got &&
data->weapons[active_weapon].duration <= 0)
if(input.activeweapon && data->weapons[active_weapon].duration <= 0)
{
if (active_weapon != input.activeweapon)
int new_weapon = active_weapon;
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;
active_weapon = input.activeweapon;
active_weapon = new_weapon;
}
}
if(!previnput.fire && input.fire)