| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- function enemy_move_and_collide()
- {
- var _y_spd_total = (y_spd + y_spd_kb) * global.time_scale;
- var _x_spd_total = (x_spd + x_spd_kb) * global.time_scale;
-
- if place_meeting(x, y + _y_spd_total, oParentSolid)
- {
- while !place_meeting(x, y + sign(_y_spd_total), oParentSolid)
- y += sign(_y_spd_total);
-
- _y_spd_total = 0;
- y_spd = 0;
- y_spd_kb = 0;
- }
- y += _y_spd_total;
- if place_meeting(x + _x_spd_total, y, oParentSolid)
- {
- while !place_meeting(x + sign(_x_spd_total), y, oParentSolid)
- x += sign(_x_spd_total);
-
- _x_spd_total = 0;
- x_spd = 0;
- x_spd_kb = 0;
- }
- x += _x_spd_total;
- }
- function enemy_check_hazard()
- {
- var _current_hazard = instance_place(x, y, oParentHazard);
-
- if _current_hazard != noone
- {
- hp -= _current_hazard.damage;
- if hp <= 0
- {
- is_dead = true;
- instance_destroy();
- }
- }
-
- if hitstun_timer > 0
- return;
-
- var _dist_x = x_spd + (sign(x_spd) * sprite_width * 0.25);
- var _dist_y = y_spd + (sign(y_spd) * sprite_height * 0.25);
-
- if place_meeting(x + _dist_x, y, oParentSolid) ||
- place_meeting(x + _dist_x, y, oParentHazard)
- x_spd = 0;
-
- if place_meeting(x, y + _dist_y, oParentHazard)
- y_spd = 0;
- }
- function enemy_check_hitstun()
- {
- if hitstun_timer > 0
- {
- hitstun_timer -= global.time_scale;
- x_spd_kb = lerp(x_spd_kb, 0, 0.2);
- y_spd_kb = lerp(y_spd_kb, 0, 0.2);
-
- x_spd = 0;
- y_spd = 0;
-
- if global.developer_mode
- image_blend = c_orange;
- }
- else
- {
- x_spd_kb = 0;
- y_spd_kb = 0;
-
- image_blend = c_white;
- }
- }
- /// @desc 优雅地以该实例为原点,给定宽高、偏移与持续时间为参数,生成敌人middle/left碰撞箱(多用于横向攻击)
- /// @param {real} _x 碰撞箱宽度
- /// @param {real} _y 碰撞箱高度
- /// @param {real} _x_offset 碰撞箱与该实例在x轴上的偏移量,默认为0
- /// @param {real} _y_offset 碰撞箱与该实例在y轴上的偏移量,默认为0
- /// @param {real} _duration 碰撞箱持续时间,默认为0,即无限
- function enemy_create_hitboxML(_x, _y,
- _x_offset = 0, _y_offset = 0, _duration = 0)
- {
- var _hb = icd(oEnemyHitbox, x + _x_offset, y + _y_offset);
- _hb.owner = id;
- _hb.sprite_index = sEnemyHitboxML;
- _hb.x_offset = _x_offset;
- _hb.y_offset = _y_offset;
-
- var _base = 2;
- _hb.image_xscale = _x / _base * facing_x;
- _hb.image_yscale = _y / _base;
- /*
- oEnemyHitbox的基础大小为2*2
- 因为gml的1*1sprite无法将重心放在middle/center
- 此处定义后续用于缩放
- */
- if _duration != 0
- {
- _hb.hitbox_type = "BLADE";
- _hb.duration = _duration;
- }
- return _hb;
- }
- /// @desc 优雅地以该实例为原点,给定宽高为参数,生成敌人middle/center碰撞箱(多用于空中本体,射弹等)
- /// @param {real} _x 碰撞箱宽度
- /// @param {real} _y 碰撞箱高度
- function enemy_create_hitboxMC(_x, _y)
- {
- var _hb = icd(oEnemyHitbox, x, y);
- _hb.owner = id;
- _hb.sprite_index = sEnemyHitboxMC;
-
- var _base = 2;
- _hb.image_xscale = _x / _base;
- _hb.image_yscale = _y / _base;
- return _hb;
- }
- /// @desc 优雅地以该实例为原点,给定宽高、偏移与持续时间为参数,生成敌人bottom/center碰撞箱(多用于地面本体、纵向攻击等)
- /// @param {real} _x 碰撞箱宽度
- /// @param {real} _y 碰撞箱高度
- /// @param {real} _x_offset 碰撞箱与该实例在x轴上的偏移量,默认为0
- /// @param {real} _y_offset 碰撞箱与该实例在y轴上的偏移量,默认为0
- /// @param {real} _duration 碰撞箱持续时间,默认为0,即无限
- function enemy_create_hitboxBC(_x, _y,
- _x_offset = 0, _y_offset = 0, _duration = 0)
- {
- var _hb = icd(oEnemyHitbox, x + _x_offset, y + _y_offset);
- _hb.owner = id;
- _hb.sprite_index = sEnemyHitboxBC;
- _hb.x_offset = _x_offset;
- _hb.y_offset = _y_offset;
-
- var _base = 2;
- _hb.image_xscale = _x / _base;
- _hb.image_yscale = _y / _base;
- if _duration != 0
- {
- _hb.hitbox_type = "BLADE";
- _hb.duration = _duration;
- }
- return _hb;
- }
- function enemy_death()
- {
- var _corpse = icd(oEnemyCorpse, x, y, 50);
- _corpse.x_spd = x_spd_kb;
- _corpse.y_spd = -max(abs(y_spd_kb), abs(x_spd_kb));
- _corpse.sprite_index = sprite_index;
- _corpse.image_angle = image_angle;
- _corpse.image_index = image_index;
-
- if is_method(death_callback)
- death_callback();
-
- instance_destroy();
- }
- function weighted_pick(_weights)
- {
- var _total = 0;
- for (var i = 0; i < array_length(_weights); i++)
- _total += _weights[i];
-
- var _roll = irandom(_total - 1);
- var _acc = 0;
- for (var i = 0; i < array_length(_weights); i++)
- {
- _acc += _weights[i];
- if _roll < _acc
- return i;
- }
- }
|