Game Maker攻击无法正常工作

时间:2017-08-10 22:51:37

标签: c# gml

当我按下x键盘按钮时,我的播放器精灵因某种原因不会受到攻击。我可以做些什么来帮助我的精灵玩家进行攻击吗?

/// Obj_player创建活动

/// set fixed rotation for object player
event_inherited();
hp = 20;
spd = 4;
hspd = 0;
vspd = 0;
len = 0;
xaxis = 0;
yaxis = 0;
dir = 0;
attacked = false;
image_speed = 0;
scr_get_input();
state = scr_move_state;

/// Obj_player警报0

/// This alarm is for the dash state
state = scr_dash_state;
state = scr_attack_state;

/// Obj_player Step Event

/// move the player in the step event
event_inherited();
script_execute(state);
state = scr_move_state;
scr_get_input();

/// Obj_Animation结束

/// Change back to move state
if (state == scr_attack_state)  {
    state = scr_move_state;
    attacked = false;
}

/// scr_get_input

right_key = keyboard_check(vk_right);
left_key = keyboard_check(vk_left);
up_key = keyboard_check(vk_up);
down_key = keyboard_check(vk_down);
dash_key = keyboard_check_pressed(ord('C'));
attack_key = keyboard_check_pressed(ord('X'));

// Get the axis
xaxis = (right_key - left_key);
yaxis = (down_key - up_key);

/// scr_move_state

scr_get_input();

if (dash_key)   {
    state = scr_dash_state;
    alarm[0] = room_speed/7;
}

if (attack_key) {
    image_index = 0;
    state = scr_attack_state;
}

// get direction
dir = point_direction(0,0, xaxis, yaxis);

// Get the length
if (xaxis == 0 and yaxis = 0)   {
    len = 0;
} else {
    len = spd;
}

// Get the hspd and vspd
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);

// move 
phy_position_x += hspd;
phy_position_y += vspd;

// Control the sprite
image_speed = sign(len)*.2;
if (len == 0) image_index = 0;

// Vertical sprites
if (vspd > 0) {
    sprite_index = spr_player_down;
} else if (vspd < 0)    {
    sprite_index = spr_player_up;
}

// Horizontal sprites
if (hspd > 0) {
    sprite_index = spr_player_right;
} else if (hspd < 0)    {
    sprite_index = spr_player_left;
}

/// scr_attack_state

image_speed = .5;

switch (sprite_index)    {
    case spr_player_down:
        sprite_index = spr_player_attack_down;
        break;

    case spr_player_up:
        sprite_index = spr_player_attack_up;
        break;

    case spr_player_right:
        sprite_index = spr_player_attack_right;
        break;

    case spr_player_left:
        sprite_index = spr_player_attack_left;
        break;
}

1 个答案:

答案 0 :(得分:0)

这是因为在这一行:

attack_key = keyboard_check_pressed(ord('X'));

您将attack_key分配给X,这与x不同。它应该是:

attack_key = keyboard_check_pressed(ord('x'));