2017-08-10 102 views
-1

當我按下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步驟事件

/// 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; 
} 

回答

0

這是因爲在這一行:

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

您將attack_key分配給與x不同的X.它應該是:

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

我以爲我必須使用X而不是x鍵盤按鈕才能工作。 –

+0

我把X字幕字母改爲小寫字母,並沒有做任何改變。 –

+0

我嘗試在Obj_player的Alarm 0事件中爲我的破折號使用相同的解決方案。 –