Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Logic Issue in JS Game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Scourge80   Members   -  Reputation: 102

Like
0Likes
Like

Posted 31 December 2012 - 06:04 PM

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, 31 December 2012 - 06:04 PM.


Sponsor:

#2 DpakoH   Members   -  Reputation: 1029

Like
0Likes
Like

Posted 01 January 2013 - 05:07 AM

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



#3 EmployeeNumber8   Crossbones+   -  Reputation: 1103

Like
0Likes
Like

Posted 01 January 2013 - 08:20 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS