Single Target Targeting
BlitzMax Forums/BlitzMax Programming/Single Target Targeting
| ||
I was bored and needed to do something to take up some time, so I decided to make a Tower Defense type game. As I programmed my towers I realized that when monsters get in the radius of the tower that ALL the monsters get hit, I need the first monster in line to get shot at until it leaves the radius then the tower goes for the next one that is in the radius. I may just be dense, but I couldn't think of a simple way to do this. Its not really important due to this being a "I was bored project", but If anyone has a suggestion i'm all ears. Here is the update function in my towers basically if it helps any... For Local AllCreeps:Creep = EachIn CreepList If Distance(AllTowers.x%,AllTowers.y%,AllCreeps.x%,AllCreeps.y%) <= (AllTowers.LoS% * 10) AllCreeps.DealDamage(AllTowers.Damage%) EndIf Next Obviously, I know this code will hit anything, but I need it to hit single targets. |
| ||
Here is some psudocode i just threw together. It should be handled by the tower itself. Type Tower Field Target:Creep Field Distance% 'distance of towers weapon Method Update() If Target = null then 'scan for target within range Target = Get_Target(Xloc%,Yloc%,distance%) 'if a target is found then target field has it Return Endif If TargetIsInDistance(Target) = false then target = null return Endif 'target is not null and in distance 'Aim at target and fire Return End Method End Type |
| ||
You need a 'currently shooting at' field in your tower type. When it finds an enemy in-range it should set it as the current enemy, and when it leaves or dies nullifies the field and look for another one to shoot at. So.. If we are NOT currently shooting at something AND if there is an enemy within the range of the tower set it to the current target. If target dies, or is no longer in-range, THEN we nullify (unset) the current target. |
| ||
Thanks, i think I got it, I had those same ideas just couldn't... Place them I guess or integrate them would be better wording. EDIT: Yep, got it working, thanks! |