D
dawson2223
Guest
Hi everyone!
I'm coding a shooter with 4-directional sprites. I have programmed the top and right sides to place my gun in the place I want it to be. For the bottom and left animations of the character, I want the gun to be in a different place so it matches the character movement, it has to be in the other hand. I can't find a way of doing it. I will attach my code.
Here's a link of what I'm trying to explain.
obj_player:
Create:
/// Variables
move = 0 // 0 for stop and 1 for running
// Initiate Weapon
x_offset = 13;
y_offset = -3;
my_gun = instance_create(x+x_offset, y+y_offset, obj_pistol);
// Initiate Weapon
x_offset = 13;
y_offset = -3;
my_gun = instance_create(x+x_offset, y+y_offset, obj_pistol);
my_gunLeft = instance_create(x+x_offset, y+y_offset, obj_pistol);
Step:
// Movement
depth = -y;
if (keyboard_check(ord('W')) && place_free (x,y-3)) {
y -= 3
sprite_index = sprPlayerRunUp
move = 1
}
if (keyboard_check(ord('S')) && place_free (x,y+3)) {
y += 3
sprite_index = sprPlayerRunDown
move = 1
}
if (keyboard_check(ord('D')) && place_free (x+3,y)) {
x += 3
sprite_index = sprPlayerRunRight
move = 1
}
if (keyboard_check(ord('A')) && place_free (x-3,y)) {
x -= 3
sprite_index = sprPlayerRunLeft
move = 1
}
if (x=xprevious && y=yprevious)
move = 0
if move = 0 {
image_speed = 0
if sprite_index = sprPlayerRunUp
image_index = 0
if sprite_index = sprPlayerRunDown
image_index = 1
if sprite_index = sprPlayerRunLeft
image_index = 3
if sprite_index = sprPlayerRunRight
image_index = 2
sprite_index = sprPlayerStand
}
End Step:
my_gun.x = x + x_offset;
my_gun.y = y + y_offset;
I tried using an if statement in the end step but it didn't work out right. I could just be using a bad code for it, not very good at coding. Please help me out!!! Thank you!!!!!
I'm coding a shooter with 4-directional sprites. I have programmed the top and right sides to place my gun in the place I want it to be. For the bottom and left animations of the character, I want the gun to be in a different place so it matches the character movement, it has to be in the other hand. I can't find a way of doing it. I will attach my code.
Here's a link of what I'm trying to explain.
obj_player:
Create:
/// Variables
move = 0 // 0 for stop and 1 for running
// Initiate Weapon
x_offset = 13;
y_offset = -3;
my_gun = instance_create(x+x_offset, y+y_offset, obj_pistol);
// Initiate Weapon
x_offset = 13;
y_offset = -3;
my_gun = instance_create(x+x_offset, y+y_offset, obj_pistol);
my_gunLeft = instance_create(x+x_offset, y+y_offset, obj_pistol);
Step:
// Movement
depth = -y;
if (keyboard_check(ord('W')) && place_free (x,y-3)) {
y -= 3
sprite_index = sprPlayerRunUp
move = 1
}
if (keyboard_check(ord('S')) && place_free (x,y+3)) {
y += 3
sprite_index = sprPlayerRunDown
move = 1
}
if (keyboard_check(ord('D')) && place_free (x+3,y)) {
x += 3
sprite_index = sprPlayerRunRight
move = 1
}
if (keyboard_check(ord('A')) && place_free (x-3,y)) {
x -= 3
sprite_index = sprPlayerRunLeft
move = 1
}
if (x=xprevious && y=yprevious)
move = 0
if move = 0 {
image_speed = 0
if sprite_index = sprPlayerRunUp
image_index = 0
if sprite_index = sprPlayerRunDown
image_index = 1
if sprite_index = sprPlayerRunLeft
image_index = 3
if sprite_index = sprPlayerRunRight
image_index = 2
sprite_index = sprPlayerStand
}
End Step:
my_gun.x = x + x_offset;
my_gun.y = y + y_offset;
I tried using an if statement in the end step but it didn't work out right. I could just be using a bad code for it, not very good at coding. Please help me out!!! Thank you!!!!!
Last edited by a moderator: