Hey all, Having some issues with the loops in my code, so the aim is to continuously bounce a set of coordinates off the edge of the screen up until a certain time. The coordinates change, however, once they reach a limit they just stay there and I can't get them to reverse. I've tried a few variations in my code but any feedback would be welcome.
xCoord = randi([20,30],1,1); yCoord = randi([20,30],1,1);
speed_1 = 1;
boundsLeft = 0; boundsTop = 0; boundsRight = 100; boundsBottom = 90;
Coords_1 = [xCoord, yCoord]
timeID = tic;
while 1
Coords_1 = Coords_1 + speed_1 if (toc(timeID) > 0.1) break; end if Coords_1 > boundsRight Coords_1 = Coords_1 - speed_1; elseif Coords_1 > boundsBottom Coords_1 = Coords_1 - speed_1; end if Coords_1 < boundsLeft Coords_1 = Coords_1 + speed_1; elseif Coords_1 < boundsTop Coords_1 = Coords_1 + speed_1; end
end
Best Answer