Imiglikos
Member
Hello everyone
When I am a hero by the mirror and have more than one weapon with me, each of the hero's weapons displays.
But I have it in several loops and I would not like to burden the code in this way. How to combine it so that all weapons on the surface are displayed in one loop?
Thanks for any help, the code looks like this
obj_game
create
step
and mirror object
obj_mirror
draw
When I am a hero by the mirror and have more than one weapon with me, each of the hero's weapons displays.
But I have it in several loops and I would not like to burden the code in this way. How to combine it so that all weapons on the surface are displayed in one loop?
Thanks for any help, the code looks like this
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";
step
GML:
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)
}
obj_mirror
draw
GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);
// mirror position
_xx = x;
_yy = y;
_surf = surface_create(300,200); // mirror size
surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)
var _xx1 = x
var _yy1 = y
//weapon1
with obj_ball
{
for (i = 0; i < instance_number(obj_ball); i += 1) {
obj= instance_find(obj_ball, i);
draw_sprite_ext(spr_ball,0,obj.x - _xx1+ 32 ,obj.y - _yy1 - 70,1,1,0,image_blend,.5)
}
}
//weapon2
with obj_thunder {
for (i = 0; i < instance_number(obj_thunder); i += 1) {
obj = instance_find(obj_thunder, i);
draw_sprite_ext(spr_thunder,0,obj.x - _xx1+ 32 ,obj.y - _yy1 - 70,image_xscale,image_yscale,0,image_blend,.5)
}
}
//weapon3
with obj_shotgun {
for (i = 0; i < instance_number(obj_shotgun); i += 1) {
obj = instance_find(obj_shotgun, i);
draw_sprite_ext(spr_shotgun,0,obj.x - _xx1+ 32 ,obj.y - _yy1 - 70,image_xscale,image_yscale,0,image_blend,.5)
}
}
//weapon4
with obj_blue_laser {
for (i = 0; i < instance_number(obj_blue_laser); i += 1) {
obj = instance_find(obj_blue_laser, i);
draw_sprite_ext(spr_blue_laser,0,obj.x - _xx1+ 32 ,obj.y - _yy1 - 70,image_xscale,image_yscale,0,image_blend,.5)
}
}
//weapon5
with obj_ice {
for (i = 0; i < instance_number(obj_ice); i += 1) {
obj = instance_find(obj_ice, i);
draw_sprite_ext(spr_ice,0,obj.x - _xx1+ 32 ,obj.y - _yy1 - 70,image_xscale,image_yscale,0,image_blend,.5)
}
}
surface_reset_target();
draw_surface(_surf,_xx,_yy); // draw mirror
surface_free(_surf) // clear mirror