/// @description Insert description here
// You can write your code in this editor
mouse_direction=point_direction(x,y,mouse_x,mouse_y)
walk_direction=270
walk_speed=0
if mouse_direction>=90 and mouse_direction<270 then side=-1 else side=1
if keyboard_check(ord("W")) then {walk_direction=90 walk_speed=stat_walk_speed}
if keyboard_check(ord("D")) then {walk_direction=point_direction(0,0,lengthdir_x(walk_speed,walk_direction)+lengthdir_x(stat_walk_speed,0),lengthdir_y(walk_speed,walk_direction)+lengthdir_y(stat_walk_speed,0)) walk_speed=stat_walk_speed}
if keyboard_check(ord("A")) then {walk_direction=point_direction(0,0,lengthdir_x(walk_speed,walk_direction)+lengthdir_x(stat_walk_speed,180),lengthdir_y(walk_speed,walk_direction)+lengthdir_y(stat_walk_speed,180)) walk_speed=stat_walk_speed}
if keyboard_check(ord("S")) then {walk_direction=point_direction(0,0,lengthdir_x(walk_speed,walk_direction)+lengthdir_x(stat_walk_speed,270),lengthdir_y(walk_speed,walk_direction)+lengthdir_y(stat_walk_speed,270)) walk_speed=stat_walk_speed}
if (walk_direction>=315 and walk_direction<=360) or (walk_direction>=0 and walk_direction<45) then sprite_index=spr_right
if walk_direction>=45 and walk_direction<135 then sprite_index=spr_up
if walk_direction>=135 and walk_direction<225 then sprite_index=spr_left
if walk_direction>=225 and walk_direction<315 then sprite_index=spr_down
if walk_speed>0 then image_speed=1 else image_speed=0
if place_meeting(x+lengthdir_x(walk_speed,walk_direction),y,obj_wall)=0 then x+=lengthdir_x(walk_speed,walk_direction)
if place_meeting(x,y+lengthdir_y(walk_speed,walk_direction),obj_wall)=0 then y+=lengthdir_y(walk_speed,walk_direction)


if reload>0 then reload-=1
if instance_number(obj_enemy)<=0 then 
{
wave_timer-=1
if wave_timer>250 then wave_ad+=0.02
if wave_timer<50 then wave_ad-=0.02
if wave_timer=0 then 
 {
 wave+=1
 wave_timer=300
 //Начинаем спавнить врагов
 enemy_number=2*wave+5
 ammo_rifle+=wave
 ammo_auto+=4*wave
 for(i=0;i<enemy_number;i++)
  {
	do t=irandom(4) until(point_distance(x,y,spawn_x[t],spawn_y[t])>500)  
	if wave<2 then enemy=0
	if wave>=2 and wave<4 then enemy=irandom(1)
	if wave>=4 and wave<7 then enemy=irandom(2)
	if wave>=7 and wave<10 then enemy=irandom(3)
	if wave>=10 and wave<14 then enemy=irandom(4)
	if wave>=14 and wave<16 then enemy=irandom(5)
	if wave=16 then {instance_create_depth(0,0,-2,obj_boss)}
	if wave!=16 then
	{
	if enemy=0 then instance_create_depth(spawn_x[t]+random_range(-10,10),spawn_y[t]+random_range(-10,10),2,obj_enemy_not_armored)
	if enemy=1 then instance_create_depth(spawn_x[t]+random_range(-10,10),spawn_y[t]+random_range(-10,10),2,obj_enemy_indian)
	if enemy=2 then instance_create_depth(spawn_x[t]+random_range(-10,10),spawn_y[t]+random_range(-10,10),2,obj_enemy_boom)
	if enemy=3 then instance_create_depth(spawn_x[t]+random_range(-10,10),spawn_y[t]+random_range(-10,10),2,obj_enemy_masked)
	if enemy=4 then instance_create_depth(spawn_x[t]+random_range(-10,10),spawn_y[t]+random_range(-10,10),2,obj_enemy_armored)
	if enemy=5 then instance_create_depth(spawn_x[t]+random_range(-10,10),spawn_y[t]+random_range(-10,10),2,obj_enemy_cyborg)
	}
 }
 }
} else if wave_ad>0 then wave_ad-=0.05
if skill_reload>0 then skill_reload-=1
if mouse_check_button(mb_right) and skill_reload=0 then
{
if hero=1 then 
{
a=instance_create_depth(x,y,2,obj_grenade)
a.speed=10
a.direction=mouse_direction
skill_reload=600
}
if hero=2 then
{
dash=20
skill_reload=300	
dash_dir=walk_direction
invinc_timer=21
}
}
if dash>0 then
{
dash-=1
if place_meeting(x+lengthdir_x(2*walk_speed,dash_dir),y,obj_wall)=0 then x+=lengthdir_x(2*walk_speed,dash_dir)
if place_meeting(x,y+lengthdir_y(2*walk_speed,dash_dir),obj_wall)=0 then y+=lengthdir_y(2*walk_speed,dash_dir)
}

if mouse_wheel_up() then
{
wep_id+=1
if wep_id=3 then wep_id=0
wep_sprite=weapon_stats(wep_id,3)
wep_reload=weapon_stats(wep_id,2)
wep_damage=weapon_stats(wep_id,1)
wep_name=weapon_stats(wep_id,0)
wep_direction=point_direction(sprite_get_xoffset(wep_sprite),sprite_get_yoffset(wep_sprite),weapon_stats(wep_id,4),weapon_stats(wep_id,5))
wep_distance=point_distance(2*sprite_get_xoffset(wep_sprite),2*sprite_get_yoffset(wep_sprite),2*weapon_stats(wep_id,4),2*weapon_stats(wep_id,5))
}
if mouse_wheel_down() then
{
wep_id-=1
if wep_id=-1 then wep_id=2
wep_sprite=weapon_stats(wep_id,3)
wep_reload=weapon_stats(wep_id,2)
wep_damage=weapon_stats(wep_id,1)
wep_name=weapon_stats(wep_id,0)
wep_direction=point_direction(sprite_get_xoffset(wep_sprite),sprite_get_yoffset(wep_sprite),weapon_stats(wep_id,4),weapon_stats(wep_id,5))
wep_distance=point_distance(2*sprite_get_xoffset(wep_sprite),2*sprite_get_yoffset(wep_sprite),2*weapon_stats(wep_id,4),2*weapon_stats(wep_id,5))
}
if mouse_check_button(mb_left) and reload<=0 then 
{
	if wep_id=0 then weapon_fire(wep_reload,wep_damage)
	if wep_id=1 and ammo_rifle>0 then {weapon_fire(wep_reload,wep_damage) ammo_rifle-=1}
	if wep_id=2 and ammo_auto>0 then {weapon_fire(wep_reload,wep_damage) ammo_auto-=1}
}
if hp<=0 then room_goto(room_death)
if invinc_timer>0 then invinc_timer-=1
if keyboard_check_pressed(vk_escape) then {pause=1 instance_create_depth(0,0,-1,obj_pause)}