Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- obj_setup_pathway - place in room
- ----------------
- //adjust if needed
- grid = mp_grid_create(0, 0, room_width/32, room_height/32, 32, 32);
- mp_grid_add_instances(grid, obj_wall, 0);
- obj_enemy
- ---------------
- ~create
- s_emit = audio_emitter_create();
- max_audio = 200;
- drop_audio = 100;
- audio_falloff_set_model(audio_falloff_linear_distance);
- audio_emitter_position(s_emit, obj_enemy.x, obj_enemy.y, 0);
- audio_emitter_falloff(s_emit, drop_audio, max_audio, 1);
- state = 0;
- seen = false;
- fade_alpha = 0;
- path = path_add();
- seen = false;
- target_x = obj_player.x;
- target_y = obj_player.y;
- xspd = 0;
- yspd = 0;
- move_spd = 0.8;
- alarm[0] = 1;
- hit_play = true;
- ----------------
- ~step
- if (state == 0){
- audio_play_sound_on(s_emit, snd_footstep, true, 1);
- state = 1;
- }
- audio_emitter_position(s_emit, x, y, 0);
- var _pd = direction - 90;
- var _ad = angle_difference(image_angle, _pd);
- image_angle -= min(abs(_ad), 10) * sign(_ad);
- image_alpha = fade_alpha;
- if (collision_line(x, y, obj_player.x, obj_player.y, obj_wall, 1, 0)) {
- fade_alpha -= 0.12;
- if (fade_alpha <= 0) {
- seen = false;
- visible = false;
- fade_alpha = 0;
- }
- } else {
- if (fade_alpha < 1) {
- fade_alpha += 0.12;
- }
- visible = true;
- seen = true;
- }
- ---------------
- ~alarm 0
- path_delete(path);
- path = path_add();
- target_x = obj_player.x;
- target_y = obj_player.y;
- //chase state if seen or within the radius
- if(collision_circle(x, y, 64, obj_player, false, false)) && seen == true{
- if (hit_play){
- audio_sound_pitch(snd_approach, 1.1);
- audio_play_sound(snd_approach, 1.3, false);
- hit_play = false;
- }
- move_spd = 1.53
- mp_grid_path(obj_setup_pathway.grid, path, x, y, target_x, target_y, 1);
- path_start(path, move_spd, path_action_stop, true);
- audio_emitter_gain(s_emit, 100);
- audio_emitter_pitch(s_emit, 1.45);
- }
- //patrol mode
- else{
- move_spd = 1.2;
- mp_grid_path(obj_setup_pathway.grid, path, x, y, target_x, target_y, 1);
- audio_emitter_pitch(s_emit, 1);
- audio_emitter_gain(s_emit, 0.3);
- path_start(path, move_spd, path_action_stop, true);
- seen = false;
- hit_play = true;
- }
- alarm_set(0, 10);
- --------------
- ~destroy
- audio_emitter_free(s_emit);
- audio_stop_sound(snd_footstep);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement