Imiglikos
Member
Hello,
I have a weapon swap system ... but the current behavior of each weapon is the same ...
I would like to change it a bit ...
1.The first primary weapon is the ball that the hero shoots.
I would like to achieve this effect on this weapon ..
when the hero shots once every time, a different ball should come out ... I mean a different color of it ...
each of these balls has the same animation in several sprites ..
when it hits an enemy it destroys and splashes ..
Each weapon should have a distance ... balls should be destroyed on some distance if there is no enemy and obstacles ... the same is weapon lightning / thunder
I described it in the picture below
2.The next weapon is lightning / thunder
when the hero fires this weapon, it creates lightning /thunder at some distance .. And if there is an enemy or several enemies at this distance, each of them will receive damage
I also described it in the picture below
This is what my weapon swap system looks like in the code
obj_game
create
obj_hero
create
step
The code of the first weapon
for the second weapon the code is the same
obj_ball
create
step
draw
enemy collision with weapon
I have a weapon swap system ... but the current behavior of each weapon is the same ...
I would like to change it a bit ...
1.The first primary weapon is the ball that the hero shoots.
I would like to achieve this effect on this weapon ..
when the hero shots once every time, a different ball should come out ... I mean a different color of it ...
each of these balls has the same animation in several sprites ..
when it hits an enemy it destroys and splashes ..
Each weapon should have a distance ... balls should be destroyed on some distance if there is no enemy and obstacles ... the same is weapon lightning / thunder
I described it in the picture below
2.The next weapon is lightning / thunder
when the hero fires this weapon, it creates lightning /thunder at some distance .. And if there is an enemy or several enemies at this distance, each of them will receive damage
I also described it in the picture below
This is what my weapon swap system looks like in the code
obj_game
create
GML:
enum e_wep { have,ammo,firerate,dmg_min,dmg_max,ammo_type,name,ammo_sound }
enum e_gun { ball,thunder,shotgun,blue_laser,ice }
weapons_total = 5;
current_weapon = 0;
var i = 0;
//basic weapon
global.wep[0 ,e_wep.ammo_type] = obj_ball;
global.wep[0, e_wep.have] = true;
global.wep[0 ,e_wep.ammo] = -1; //endless ammo
global.wep[0 ,e_wep.firerate] = 5;
global.wep[0 ,e_wep.dmg_min] = 3;
global.wep[0 ,e_wep.dmg_max] = 5;
global.wep[0 ,e_wep.name] = "ball";
//second weapon
global.wep[1 ,e_wep.ammo_type] = obj_thunder;
global.wep[1, e_wep.have] = false;
global.wep[1 ,e_wep.ammo] = 30;
global.wep[1 ,e_wep.firerate] = 10;
global.wep[1 ,e_wep.dmg_min] = 3;
global.wep[1 ,e_wep.dmg_max] = 5;
global.wep[1 ,e_wep.name] = "thunder";
//third weapon
global.wep[2 ,e_wep.ammo_type] = obj_shotgun;
global.wep[2, e_wep.have] = false;
global.wep[2 ,e_wep.ammo] = 20;
global.wep[2 ,e_wep.firerate] = 15;
global.wep[2 ,e_wep.dmg_min] = 3;
global.wep[2 ,e_wep.dmg_max] = 5;
global.wep[2 ,e_wep.name] = "shotgun";
//fourth weapon
global.wep[3 ,e_wep.ammo_type] = obj_blue_laser;
global.wep[3, e_wep.have] = false;
global.wep[3 ,e_wep.ammo] = 10;
global.wep[3 ,e_wep.firerate] = 20;
global.wep[3 ,e_wep.dmg_min] = 3;
global.wep[3 ,e_wep.dmg_max] = 5;
global.wep[3 ,e_wep.name] = "blue_laser";
//fifth weapon
global.wep[4 ,e_wep.ammo_type] = obj_ice;
global.wep[4, e_wep.have] = false;
global.wep[4 ,e_wep.ammo] = 5;
global.wep[4 ,e_wep.firerate] = 25;
global.wep[4 ,e_wep.dmg_min] = 3;
global.wep[4 ,e_wep.dmg_max] = 5;
global.wep[4 ,e_wep.name] = "ice";
obj_hero
create
GML:
//variables for weapons
have = true;
ammo = 10;
firerate = 15;
dmg_min = 3;
dmg_max = 5;
damageClock = 0;
timeAttack = 0;
current_attack = 0;
step
GML:
var cur = obj_game.current_weapon; //the control object has the index of the current weapon, so we need to get it first
if keyboard_check_pressed(ord('X')) && timeAttack <= 0 && in_air=false &&
(global.wep[cur,e_wep.ammo] > 0 || global.wep[cur,e_wep.ammo] == -1) {
timeAttack = global.wep[cur,e_wep.firerate];
timeAttack = _attackClock;
current_attack =1;
with instance_create(x,y,par_attack) {
sprite_index = spr_hero_attack;
image_xscale = other.image_xscale;
}
var box, ins;
if image_xscale == -1
box = bbox_left;
else
box = bbox_right;
if (global.wep[cur,e_wep.ammo] >= 1) // if not infinite ammo
{
global.wep[cur,e_wep.ammo]-=1;
}
var ins = instance_create(box+image_xscale*42, y-17,global.wep[cur,e_wep.ammo_type] );
ins.hspeed = image_xscale * 15;
ins.dmg = irandom_range(global.wep[cur,e_wep.dmg_min],global.wep[cur,e_wep.dmg_max]);
audio_play_sound(global.wep[cur,e_wep.ammo_sound],10,false)
}
The code of the first weapon
for the second weapon the code is the same
obj_ball
create
GML:
owner = noone;
g = 0; //gravitation
f = 0; //flight parabola
step
GML:
image_angle=direction
draw
GML:
draw_sprite_ext(sprite_index, image_index, round(x), round(y), image_xscale, image_yscale, image_angle, image_blend, image_alpha);
enemy collision with weapon
GML:
if damageClock == 0 {
hp -= 3;
damageClock = room_speed/2;
}
Last edited: