S
supesdupes
Guest
I essentially have my character's movement down, but I am having trouble figuring out how to make it so that when the player holds down and crouches the bullet lowers accordingly to the player's shorter height.
I am also confused as to make it so that the bullet comes from the tip of the player's gun. Any and all help would be greatly appreciated.
I am also confused as to make it so that the bullet comes from the tip of the player's gun. Any and all help would be greatly appreciated.
Code:
/// player create event
image_speed = 0.3; //How quickly the frames are played in the game, at 0 it wont' animate
walkSpeed = 1.2; //The variable controlling how quickly the player walks
grv = 2;
vspd = 0;
can_shoot = false;
can_minjump = true;
is_crouching = false;
//Sprites
spriteStand = spr_player;
spriteWalking = spr_player_walking;
GML:
///player step event
right = keyboard_check(ord("D"));
left = keyboard_check(ord("A"));
down = keyboard_check_pressed(ord("S"));
down1 = keyboard_check_released(ord("S"));
jump = keyboard_check_pressed(vk_space);
shoot = keyboard_check_pressed(ord("J"));
var move = (right - left) * walkSpeed;
hMoveDir = right - left
yMove = vspd + grv;
//Movement
if (move != 0)
{
image_xscale = hMoveDir
image_speed = walkSpeed / .75;
sprite_index = spriteWalking;
}
else
{
sprite_index = spriteStand;
}
//Jumping
if (place_meeting(x,y+1,obj_block)) && jump
{
yMove = -25
}
//Horizontal Collisions
if(place_meeting(x + move, y, obj_block))
{
while(!place_meeting(x + sign(move), y, obj_block))
x += sign(move);
move = 0;
}
x += move;
//Vertical Collisions
if(place_meeting(x, y + yMove, obj_block))
{
while(!place_meeting(x, y + sign(yMove), obj_block))
y += sign(yMove);
yMove = 0
}
y += yMove
//Shooting
if (shoot)
{
// Create a bullet
bullet = instance_create_depth(x, y, -1, obj_bullet);
bullet.hspeed = image_xscale * 5;
// Shooting
can_shoot = true;
alarm[0] = 60;
}
if (can_shoot == false)
{
spriteStand = spr_player;
spriteWalking = spr_player_walking;
}
else
{
spriteStand = spr_player_shoot;
spriteWalking = spr_player_walking_shoot;
}
//Crouching
if (down)
{
is_crouching = true;
}
if (down1)
{
is_crouching = false;
}
if (is_crouching == true)
{
spriteStand = spr_player_crouching;
if (can_shoot == true)
{
spriteStand = spr_player_crshoot
}
}