move objects from right-left
Hi everybody,
I have this:
[code]
private bool MoveInvaders()
{
bool directionChanged = false;
//if ((TimerCounter % TheSpeed) == 0)
//{
//foreach (Invader invader in invaders)
// {
// invader.Move(Direction.Right);
//}
if (direction == Direction.Right)
{
//invader.Move( Direction.Right);
var invaderGroups = from invader in invaders
where invader.Location.X > boundaries.Right - 800
orderby invader.Location.Y descending
group invader by invader.Location.X into invaderGroup
//select invaderGroup;
select invader;
//theInvader.Move(Direction.Left);
//where
//select invaderGroup;
if (invaderGroups.Count() > 0) directionChanged = true;
}
//End if
else
// if (direction == Direction.Left)
{
int pixxel = boundaries.Width - GameConstants.InvaderEdgeOfScreen;
var invaderGroups = from invader in invaders
where invader.Location.X < pixxel + invader.image.Width-100 //boundaries.Width - 300
orderby invader.Location.Y descending
//select invaderGroup;
group invader by invader.Location.Y into invaderGroup
select invader;
}
if (directionChanged)
{
if (direction == Direction.Right)
{
direction = Direction.Left;
}
else
direction = Direction.Right - boundaries.Width-100;
}
//}//End timercount
//End foreacht invader
return directionChanged;
}//End method
private void MoveInvaderReal()
{
if ((TimerCounter % TheSpeed) == 0)
{
//TimerCounter = 0;
foreach (Invader invader in invaders)//These method returns a list with the moving invaders.
{
invader.Move(direction);
}
}
TimerCounter++;
}
[/code]
U see there are 2 methods. But the invaders are moving from right - left and back to left. But then the invaders are going off screen and dont come back :(.
THX for helping me!!