With lessons 1-10 complete, this task is to add an additional enemy that fires weapons directly toward the player when in range.
The task is complete when the desired results are met. A walkthrough is provided to help along the way.
New enemy that fires weapons directly toward the player while in range.
Utilize the Systems Method to ensure compatability with other contributors.
New enemy that fires weapons directly toward the player while in range.
What systems (if any) already exist for the desired results? Check the projects wiki page.
What systems need to be modified? Are we the system owner or need to request a new system interface?
What systems are being integrated? How do we do that?
obj_playerfor position.The behaviour of firing when only in range is new. How can we go from descriptive comments into code?
// If player is in range and not reloading, fire towards the enemy
Architecturally, the reload wait will be implemented with alarm[0]. Translate the intent into appropriate code syntax.
// If player is in range and not reloading, fire towards the enemy
if distance_to_object(obj_player) <= range and alarm[0] <= 0 {
// Fire
// Reload
}
Leverage the implementation notes of relevant systems.
// If player is in range and not reloading, fire towards the enemy
if distance_to_object(obj_player) <= range and alarm[0] <= 0 {
// Fire
var arrow_direction = point_direction(x, y, obj_player.x, obj_player.y)
var offset = 48
var weapon_x = x + lengthdir_x(offset, arrow_direction)
var weapon_y = y + lengthdir_y(offset, arrow_direction)
var Weapon = instance_create_layer(weapon_x, weapon_y, "Instances", obj_weapon)
Weapon.speed = 6
Weapon.direction = arrow_direction
Weapon.image_angle = arrow_direction
Weapon.player_weapon = false
// Reload
alarm[0] = reload_time * game_get_speed(gamespeed_fps)
}