Talking about turret attacks and character attacks in the game (DOTA) (to be continued)

Source: Internet
Author: User
Tags dota

Players who have played Dota know that the turret in the game will give priority to the enemy heroes who attack their own heroes within the attack range. We will discuss the implementation of both attacks and attacks below

1. In standalone mode, all the current map monsters are loaded to the data Class public classes in combat scenariosClass NPC {// target of the attack // type (building, NPC, hero, turret, etc.) type // determine whether the attack target is within the attack range private Boolean functon isinrange () {If (target! = NULL) {long distance = math. SPRT (this. worldX-target.worldX) * (this. worldX-target.worldX) + (this. worldY-target.worldY) * (this. worldY-target.worldY); If (distance <attack range) return true;} return false;} // determines whether the target is activated (with a target, within the range, no death) private Boolean function isactive () {return target! = NULL & target. isdead & isinrange ();}

}HeroClass hero extends NPC {type = npctype. hero // start to attack public function attack () {// The skill form fighteffertmanager that plays a hero at a specified position. playeffert (the hero's skill effect ID, worldx, worldy); // The target is attacked. receivebeattacked (this); // sends a message to inform the turret of the attack event (target);} // J receives the public function receivebeattacked (attacknpc) attacked) {// play the skill fighteffertmanager of the hero at the specified position. playeffert (ID of the skill effect attacked by a hero, worldx, worldy); // reduce the blood and the blood volume is the HP-= attacknpc of the skill currently used by the attacker. getcurrentattack (). attackstrength (); If (HP <0) HP = 0;} // The UI image of the hero is rendered by a thread (processing view, public Function render () {}// the thread (processing logic), such as playing attack graphics, is used to catch up with the attack in the range, move the attack, determine whether the hero is dead, and reclaim the death.

Public Function Update () {// chaseattack (); // MOVE (); // whether isdead () is killed ();}}TurretClass tower extends NPC {type = npctype. tower // register the turret attack listener addeventlisenter (towerattackevent, receiveattackcmd); // receives the public function receiveattackcmd (event) attack command event {// If the turret already has an attack target, and is the hero's target. If (target! = NULL & target. type = NPC. hero & isactivetarget () {return;} else // prepare get }}// the interface image of the turret rendered by the thread (processing view, public Function render () {}// target within the range specified by the thread (processing logic), such as playing attack graphics or ordinary public function render () {}// target, attack public function Update () {// in normal times, if the target is not activated, search for the target attack if (isactive () findtarget (); // if the target has a target within the attack frequency and the target is within the range, if (idle time> attack frequency time & isactive () attack (target)

} To be continued, A * seek the path, switch the mobile Attack Status, graphic rendering, and pursuit attack ·······

 

2. In standalone mode, the current map monster loads data according to the interface range, and removes the files that are not in the range to be continued. 3. multiplayer combat mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.