Making an object move?

Hi,

Right now, I'm trying make an object move. Let say I'm trying to print a box or a circle, what commands should I use in order to make it move? Like should I use while loops, etc? Examples would be nice.
How are you printing them? you should add the new coordinates to the original coordinates
I printed them by using a basic drawing function, like bgDrawBox (x,y,x1,y1,x2,y2,x3,y3).

What do you mean by adding new coordinates on original coordinates?
correct.. now lets say you want to move it on timer or on keyboard input...

lets say you want to move it to right.. so what should happen??? which coordinates should increase?? moving to right increases x or y coordinates??
Oh, I should say that I don't want to move the box using keyboard inputs. I'm using Codeblocks and within a 16x16 coordinate screen I want the box to move in a constant motion, bouncing back and forth.
Last edited on
hmm..so it should move on timer.. lets say you have a timer function.
we can do it like this:

//some code..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
case WM_TIMER: 
			switch(wParam) 
				case ID_TIMER1: 
			{ 
				//if msgbox is showing, dont move it 
				if(!bMsgBoxShowing) 
				{ 
					//timer event, handling window movement 
					MoveWindow(hDlg,cxPos,cyPos,90,90,TRUE); 
					cxPos += cxSpeed; 
					cyPos += cySpeed; 
 
					if((cxPos+90) >= cxScreen || cxPos <= 0) 
						cxSpeed *= -1; 
 
					if((cyPos+90) >= cyScreen || cyPos <= 0) 
						cySpeed *= -1; 
 
				} 
				break; 
 
			}


see whats happening.on each timer tick i am incrementing x and y coordinates to cxSpeed and cySpeed. these are displacement variables which determine how to move on one tick.

now if the box reaches to the edges then change the sign of the Speed variable and the box will automatically start to move in opposite direction. lets say its moving right and down and lets say it touches right most boundary. so what should happen.. it should now start to move in left and down position. because now cxSpeed will be negative. think and i hope you will get it.
Topic archived. No new replies allowed.