R
royer14
Guest
Hi, I have difficulties creating a player to shoot, I have taken a course on the internet and decided to use the code and implement it in my source, but I have lost, can you check the code and say where can I place the said action?
Object Player
event create
now I execute the state in the step event
Once the action is completed on the object player, we proceed to create the script
name script---> mov_estate
Here is my variable and a stupid action that I put
name of script ----> ledge_grab()
collision
name script --->movimiento
my only goal is that when I press the space key, the player changes sprite to shoot and also when he jumps execute the same action.
Object Player
event create
Code:
///create event
spd = 8;
acc = 2;
vspd = 0;
hspd = 0;
grav =1.2;
image_speed = 0.4;
estate = mov_estate;
Code:
///control of state
script_execute(estate);
name script---> mov_estate
Code:
///mov_estate()
var right = keyboard_check(vk_right);
var left = keyboard_check(vk_left);
var up = keyboard_check(vk_up);
var up_release = keyboard_check_released(vk_up);
var down = keyboard_check(vk_down);
var shooting = keyboard_check(vk_space); // Here is the variable, now I don't know where to create the action
if(!place_meeting(x,y+1,o_Solid))
{
vspd += grav;
//player in air
sprite_index = s_p_jump;
image_index = (vspd > 0);
//control jump
if (up_release && vspd <-6)
{
vspd =-6;
}
}
else {
vspd = 0;
//code for jump
if (up)
{
vspd =-18;
}
//player in floor
if (hspd == 0 and !shooting) // Here I put the variable, but it is not correct
{
sprite_index = s_p_idle; //sprite idle
}
else{
sprite_index = s_p_walk; //sprite walk
}
}
//control speed
if (right || left)
{
hspd +=(right - left)*acc;
hspd_dir = right - left; //
if (hspd > spd)
{
hspd = spd;
}
if (hspd < -spd)
{
hspd = -spd;
}
}else
{hspd =0;
aplic_friccion(acc);
}
//orientation of sprite
if (hspd != 0)
{
image_xscale =sign(hspd);
}
//scrip move
movimiento(o_Solid); // other script
//check of ledge grav
var falling = y-yprevious > 0;
var wasnt_wall = !position_meeting(x+17*image_xscale,yprevious,o_Solid);
var is_wall = position_meeting(x+17*image_xscale,y,o_Solid);
if (falling && wasnt_wall && is_wall)
{
hspd = 0;
vspd = 0;
//repair pixel fail of ledge grav
while(!place_meeting(x+image_xscale,y,o_Solid))
{
x += image_xscale;
}
// create mov
while(position_meeting(x+image_xscale,y-1,o_Solid))
{
y -=1;
}
sprite_index = s_p_ledge;
estate = ledge_grab; // other sprite
}
var shooting = keyboard_check(vk_space);
if (hspd == 0 and !shooting)
name of script ----> ledge_grab()
Code:
///ledge_grab()
var up = keyboard_check(vk_up);
var down = keyboard_check(vk_down);
if (down)
{
estate = mov_estate;
}
if (up)
{
estate = mov_estate;
vspd = -18
}
name script --->movimiento
Code:
///movimiento()
var colision_obj = argument0; // O_solid is the collision
//collision horizontal
if (place_meeting(x+ hspd,y,colision_obj))
{
while(!place_meeting(x+ sign(hspd),y,colision_obj))
{
x += sign(hspd);
}
hspd = 0;
}
x +=hspd;
//collision vertical
if (place_meeting(x,y+vspd,colision_obj))
{
while(!place_meeting(x,y + sign(vspd),colision_obj))
{
y += sign(vspd);
}
vspd = 0;
}
y +=vspd;