NimNom1234
Member
Hello.
I have a feeling that the reason for error is something silly, as this is a pretty basic part of a games programming, but when my character attacks, he can still move freely, despite my efforts.
I was fed up with platformer programming, so I caved and used Shaun Spaldings code.
In the step event:
In the create event:
in the Animation End event:
I have a feeling that the reason for error is something silly, as this is a pretty basic part of a games programming, but when my character attacks, he can still move freely, despite my efforts.
I was fed up with platformer programming, so I caved and used Shaun Spaldings code.
In the step event:
Code:
//Get Input
key_right = keyboard_check(ord("D"))
key_left = -keyboard_check(ord("A"))
key_jump = keyboard_check(ord("O"))
//React to Input
move = key_left + key_right
hsp = move * movespeed
if (vsp < 10) vsp += grav
if (place_meeting(x,y+1,obj_floor)) {
vsp = key_jump * -jumpspeed
}
if keyboard_check_pressed(ord("K")) {
attacking = true
image_speed = .3
if direction = 1 {
sprite_index = spr_char_attack_left
}
if direction = 2 {
sprite_index = spr_char_attack_right
}
}
if keyboard_check(ord("D")) && attacking = false {
direction = 2
image_speed = .3
sprite_index = spr_char_walk_right
}
if keyboard_check(ord("A")) && attacking = false {
direction = 1
image_speed = .3
sprite_index = spr_char_walk_left
}
//General Collision
if (place_meeting(x+hsp, y+vsp, obj_floor)) {
hsp = 0;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_floor)) {
while !(place_meeting(x+sign(hsp),y,obj_floor)){
x += sign(hsp)
}
hsp = 0
}
//Vertical Collision
if (place_meeting(x,y+vsp,obj_floor)) {
while !(place_meeting(x,y+sign(vsp),obj_floor)){
y += sign(vsp)
}
vsp = 0
}
x += hsp
y += vsp
//Check Idle
if !keyboard_check(ord("A")) && !keyboard_check(ord("D")) && attacking = false {
image_speed = 0
if direction = 1 {
sprite_index = spr_char_idle_left
}
if direction = 2 {
sprite_index = spr_char_idle_right
}
}
In the create event:
Code:
///Initialize Variables
direction = 2
attacking = false
grav = 1
hsp = 0
vsp = 0
jumpspeed = 7.5
movespeed = 3
Code:
if sprite_index = spr_char_attack_left || spr_char_attack_right {
attacking = false
if direction = 1 {
image_speed = .3
sprite_index = spr_char_idle_left
}
if direction = 2 {
image_speed = .3
sprite_index = spr_char_idle_right
}
}