C
clyver
Guest
(Sorry for bad english)
I know it is a especific problem, and it's a lot of code do analyze, but, i just don't know what to do.
When the player is walking, and I command it to attack by pressing "X", he attacks, but in the moment I command it, before it starts to attack, it moves about 5 pixels to the direction i'm moving it.
It is too weird, and you may think it's about the sprite or something like that, but it is not. I tested a lot of things, and even without any command or walk sprite or walk and attack sprite, it happens.
Just when I press "X", it happens.
You don't need to read all of it, I will just show all my codes. Just read what you think is necessary.
Here's the meaning of all sprites and object names
I know it is a especific problem, and it's a lot of code do analyze, but, i just don't know what to do.
When the player is walking, and I command it to attack by pressing "X", he attacks, but in the moment I command it, before it starts to attack, it moves about 5 pixels to the direction i'm moving it.
It is too weird, and you may think it's about the sprite or something like that, but it is not. I tested a lot of things, and even without any command or walk sprite or walk and attack sprite, it happens.
Just when I press "X", it happens.
You don't need to read all of it, I will just show all my codes. Just read what you think is necessary.
PLAYER OBJECT EVENTS:
--CREATE--
Code:
hsp = 0;
vsp = 0;
grv = 0.2;
walksp = 4;
--STEP--
Code:
//Commands
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up);
//Movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,OBloco2)) && (key_jump)
{
vsp = -7.1;
}
//Running(this is not walk, it is another aside command)
if (keyboard_check(ord("Z")))
{
walksp = 6;
}
else
{
walksp = 3;
}
if (keyboard_check(ord("Z"))) && (keyboard_check(ord("X")))
{
walksp = 3;
}
//Horizontal collision
if (place_meeting(x+hsp,y,OBloco2))
{
while (!place_meeting(x+sign(hsp),y,OBloco2))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical collision
if (place_meeting(x,y+vsp,OBloco2))
{
while (!place_meeting(x,y+sign(vsp),OBloco2))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//All kind of attack animation
if (!place_meeting(x,y+1,OBloco2)) && (keyboard_check(ord("X")))
{
if(sign(vsp) > 0)
{
sprite_index = SPiresAtP;
}
}
else
{
if (!place_meeting(x,y+1,OBloco2))
{
sprite_index = SPiresP;
image_speed = 0;
if(sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = SPires;
}
else
{
sprite_index = SPiresA;
image_speed = 0.5
}
if (keyboard_check(ord("X")))
{
sprite_index = SPiresAt
}
}
}
if (hsp != 0) image_xscale = sign(hsp);
//Attack while walk animation
if (keyboard_check(ord("X"))) && (key_left)
{
if (!place_meeting(x,y+1,OBloco2))
{
exit;
}
sprite_index = SPiresAtA;
image_speed = 0.5;
}
if (keyboard_check(ord("X"))) && (key_right)
{
if (!place_meeting(x,y+1,OBloco2))
{
exit;
}
sprite_index = SPiresAtA;
image_speed = 0.5;
}
//Running animation
if (keyboard_check(ord("Z"))) && (key_right)
{
if (!place_meeting(x,y+1,OBloco2))
{
exit;
}
sprite_index = SPiresC;
image_speed = 0.75;
}
if (keyboard_check(ord("Z"))) && (keyboard_check(ord("X")))
{
sprite_index= SPiresAtA
}
GUN OBJECT EVENT:
Code:
x = OPires.x;
y = OPires.y+10;
image_xscale = OPires.image_xscale;
firingdelay = firingdelay - 1;
if (keyboard_check(ord("X")) && (firingdelay < 0))
{
firingdelay = 10;
with (instance_create_layer(x,y,"Balas",OTiro))
{
speed = 10;
direction = -90 + 90 * other.image_xscale;
image_angle = direction;
}
}
SHOT OBJECT CODE
Code:
dir = 1;
if keyboard_check(vk_right) +(-keyboard_check(vk_left)) !=0
{
dir = keyboard_check(vk_right) +(-keyboard_check(vk_left));
image_xscale = dir;
}
Code:
if (keyboard_check(ord("X")))
{
sprite_index = STiro;
image_speed = 1;
}
Code:
if (place_meeting(x,y,OBloco)) instance_destroy();
Here's the meaning of all sprites and object names
SPires = Player standing
SPiresA = Player walking
SPiresP = Player jumping
SPiresAt = Player attacking
SBloco2 = Standard block
STiro = Shot
SPiresAtP = Player attacking while jumping
SPiresAtA = Player attacking while walking
SpiresC = Player running
SPiresA = Player walking
SPiresP = Player jumping
SPiresAt = Player attacking
SBloco2 = Standard block
STiro = Shot
SPiresAtP = Player attacking while jumping
SPiresAtA = Player attacking while walking
SpiresC = Player running
OPires = Player
OArma = Gun
OTiro = Shot
OBloco2 = Standard block
OArma = Gun
OTiro = Shot
OBloco2 = Standard block
Last edited by a moderator: