(moderator hat on)
A gentle reminder about the special rules of the For Beginners forum.
Specifically:
* This forum is for beginners to ask questions without being harassed because someone more experienced thinks the answer should be obvious.
* Make sure replies are helpful and guiding the beginner in the right direction.
The focus in For Beginners is to help educate, guide, and answer questions in a reasonably safe environment. Even the experts were beginners once. Sometimes the best answers are a code snippet, or a link to a tutorial. Other times the best answers are step-by-step guidance to help think and reason and guide to reach a viable solution.
(moderator hat off)
In a more useful note, it looks like Alberth has been guiding toward the right answer, and those are the correct things to think about to solve this problem and other problems like it.
I'd also break it down similarly:
1. First you need to figure out generally how you are going to move objects. It looks like you've described some shapes.
2. After you know how objects will move, describe those motions as very specific steps. Looks like you've got back-and-forth and square, and possibly circle. Describe those motions in terms of world coordinates and game systems. Describe every step precisely. Eventually you will need to explain it to the computer that will only do exactly what you tell it, nothing more or less. You might try explaining it to an obnoxious person who only does exactly the words you say to make sure you really understand the steps involved.
3. Take the descriptions in regular words, and figure out how to describe it as a series of math steps. For example, a math function where you pass in the current time and the details of the path to follow, then you divide the time by the time it takes to complete a full cycle (at the current time step it is on cycle 2341.36), then compute the portion within the current cycle (it is 36% complete), then compute the position at that time in the cycle (36% of the distance on the path yields coordinates (X,Y,Z) which should be where you set the position). Or another approach might mean a math function where you evaluate the time that has passed (it has moved for 14.6 milliseconds), evaluate the speed and direction it is traveling (7.83 pixels per millisecond in a specific direction), then advance the position based on the time (elapsed time * speed at direction). There are many other ways you might describe the direction.
4. After you've got the steps figured out and you can describe it using math, then attempt to describe it in computer code.
It looks like you're somewhere between step 2 and 3. It can be a struggle, but the skills are vital if you want to develop software. Even in professional work environments we will talk to others to explain every individual step, then explain the steps using the right notations. Sometimes we'll even explain it to an inanimate object to help reason through the steps.