Logic Issue in JS Game

This topic is 2115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I was working on a basic algorithm for detecting collision between a creep and game entities (enemy towers, enemy walls, etc.). Now, this works perfect when tested offline, but when I uploaded it to my site, it seems to have issues; creeps continue to move even while colliding. This is a simple Tower Defense-type game.

Collision update:

function CpuUpdate()
{
//Update creeps
for(var j = 0; j < CpuCreeps.length; j++)
{
//Check if we collide with an enemy tower
if(CollidesWithTarget(CpuCreeps[j], P1Towers))
{
//Move toward the target
CpuCreeps[j].MoveToTarget(CpuCreeps[j].Target);
//Attack the target if we are in melee range
if(CpuCreeps[j].CollidesWith(CpuCreeps[j].Target))
CpuCreeps[j].Attack(CpuCreeps[j].Target);
}
//Check if we collide with a wall
else if(CollidesWithTarget(CpuCreeps[j], P1Walls))
{
//Move toward the target
CpuCreeps[j].MoveToTarget(CpuCreeps[j].Target);
//Attack the target if we are in melee range
if(CpuCreeps[j].CollidesWith(CpuCreeps[j].Target))
CpuCreeps[j].Attack(CpuCreeps[j].Target);
}
//Move Creeps if we aren't colliding with enemies
else
{
CpuCreeps[j].X--;
}
}
}

CollidesWithTarget(creep, targetGroup) method:

function CollidesWithTarget(creep, targetGroup)
{
for(var k = 0; k < targetGroup.length; k++)
{
if(creep.CollidesWith(targetGroup[k].View))
{
//Set our target
creep.Target = targetGroup[k];
//Return true and stop checking for other towers
return true;
break;
}
}
return false;
}

?

?

To see the error:  http://dikaioti.byethost7.com/TowerDefense/

thank you for any feedback

(By the way, new to GameDev, if I made a mistake concerning rules, let me know so I can fix it)

Edited by Scourge80

Share on other sites

it is kind of working, at least on one side the creeps stop at towers/walls and destroy them.

Share on other sites

It works for me too. Maybe he already fixed it.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 11
• 18
• 14
• 9
• 9
• Forum Statistics

• Total Topics
632929
• Total Posts
3009281
• Who's Online (See full list)

There are no registered users currently online

×