TayTrash
Member
Hi guys, I was here programming a Dungeon Crawler style game and I'm having some doubts about how to do certain functions for my weapons in the game.
So far I only have the pistol and a machine gun, my player when he gets to any of the weapons, he takes it and can shoot, then he reaches the other weapon that is on the ground and takes it and changes the weapon he just picked up, however, he he doesn’t switch weapons when the two are already caught, he doesn’t switch from pistol to machine gun or machine gun to pistol, besides my bullets are infinite and I just want the pistol bullets to be infinite.
in short, what I want is for my character to switch from one weapon to another and for the pistol to have infinite bullets and for the machine gun, limited bullets.
Create event of "oPistol" :
My step event from "oPistol" :
My draw event from "oPistol":
my script "ChangeWeapon":
and for least my "oWeapon_pickup"
the tutorial i follow to do this is from Shaun Spalding:
sorry if my english is bad,im learning how to speak this language
So far I only have the pistol and a machine gun, my player when he gets to any of the weapons, he takes it and can shoot, then he reaches the other weapon that is on the ground and takes it and changes the weapon he just picked up, however, he he doesn’t switch weapons when the two are already caught, he doesn’t switch from pistol to machine gun or machine gun to pistol, besides my bullets are infinite and I just want the pistol bullets to be infinite.
in short, what I want is for my character to switch from one weapon to another and for the pistol to have infinite bullets and for the machine gun, limited bullets.
Create event of "oPistol" :
GML:
///@desc Variaveis
//UnArmed
weapons[0] = ds_map_create();
ds_map_add(weapons[0], "sprite", -1);
ds_map_add(weapons[0], "recoil", 0);
ds_map_add(weapons[0], "recoil_push", 0);
ds_map_add(weapons[0], "damage", 0);
ds_map_add(weapons[0], "projectile", -1);
ds_map_add(weapons[0], "startup", 0);
ds_map_add(weapons[0], "length", 0);
ds_map_add(weapons[0], "cooldown", 0);
ds_map_add(weapons[0], "bulletspeed", 0);
ds_map_add(weapons[0], "automatic", false);
//PISTOL
weapons[1] = ds_map_create();
ds_map_add(weapons[1], "sprite", sPistola);
ds_map_add(weapons[1], "recoil", 3);
ds_map_add(weapons[1], "recoil_push", 0);
ds_map_add(weapons[1], "damage", 1);
ds_map_add(weapons[1], "projectile", oBullet);
ds_map_add(weapons[1], "startup", 0);
ds_map_add(weapons[1], "length", 24);
ds_map_add(weapons[1], "cooldown", 3);
ds_map_add(weapons[1], "bulletspeed", 3);
ds_map_add(weapons[1], "automatic", false);
//SubMachine fodase
weapons[2] = ds_map_create();
ds_map_add(weapons[2], "sprite", sMetralhadora);
ds_map_add(weapons[2], "recoil", 6);
ds_map_add(weapons[2], "recoil_push", 2);
ds_map_add(weapons[2], "damage", 3);
ds_map_add(weapons[2], "projectile", oBullet);
ds_map_add(weapons[2], "startup", 0);
ds_map_add(weapons[2], "length", 24);
ds_map_add(weapons[2], "cooldown", 10);
ds_map_add(weapons[2], "bulletspeed", 16);
ds_map_add(weapons[2], "automatic", true);
weapon = 0;
ammo[array_length_1d(weapons)-1] = 0;
ammo[0] = -1;
ChangeWeapon(0);
current_cd = 0;
current_delay = -1;
current_recoil = 0;
My step event from "oPistol" :
GML:
x = oPlayer.x;
y = oPlayer.y;
direction = point_direction(x,y,mouse_x,mouse_y);
if (direction > 90) && (direction < 270) image_yscale = -1; else image_yscale = 1;
image_angle = direction;
var mouseb;
if (automatic) mouseb = mouse_check_button(mb_left); else mouseb = mouse_check_button_pressed(mb_left);
if (mouseb)
{
if (current_cd == 0)
{
current_cd = cooldown;
current_delay = startup;
with(oPlayer)
{
hSPD -= lengthdir_x(other.recoil_push,other.direction);
vSPD -= lengthdir_y(other.recoil_push,other.direction);
}
current_recoil = recoil;
}
}
if (current_delay == 0) && (projectile != -1) && (weapon != 0)
{
if (ammo[weapon] != 0)
with (instance_create_layer(x , y, "Tiros",projectile))
{
audio_play_sound(bala2,10,false);
direction = other.direction;
speed = other.bulletspeed;
}
ammo[weapon] -= 1;
}
current_delay = max(-1,current_delay-1);
if (current_delay == -1) current_cd = max(0,current_cd-1);
current_recoil = max(0,floor(current_recoil*0.8));
depth = oPlayer.depth-1;
GML:
if (sprite != -1)
{
draw_sprite_ext(
sprite,
image_index,
x-lengthdir_x(current_recoil,direction),
y-lengthdir_y(current_recoil,direction),
image_xscale,
image_yscale,
image_angle,
image_blend,
image_alpha
);
}
GML:
function ChangeWeapon(){
weapon = argument0;
var wp_map = weapons[weapon];
sprite = ds_map_find_value(wp_map,"sprite");
recoil = wp_map[? "recoil"];
recoil_push = wp_map[? "recoil_push"];
damage = wp_map[? "damage"];
projectile = wp_map[? "projectile"];
startup = wp_map[? "startup"];
bulletspeed = wp_map[? "bulletspeed"];
length = wp_map[? "length"];
cooldown = wp_map[? "cooldown"];
automatic = wp_map[? "automatic"];
}
the tutorial i follow to do this is from Shaun Spalding:
sorry if my english is bad,im learning how to speak this language