| Mouse Movement 
 
	 
	
		| Author | Message |   
		| upthescale 
 
 
 
 
 | 
			
				|  Posted: Tue May 23, 2006 3:04 pm    Post subject: Mouse Movement |  |   
				| 
 |  
				| Oj thism ight sound hard but i would like to learn it, any ideas? 
 
 first i got my mouse, and i am using Mouse.Where....i want it so i have a blue ball (or whatever the objecti s) and whne i move my mouse, it will come toward it so it will follo my mouse, so if i move my left to the top corner, the ball will slowly move to the top corner...what shud i learn to do this?
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| TheOneTrueGod 
 
  
 
 
 | 
			
				|  Posted: Tue May 23, 2006 3:09 pm    Post subject: (No subject) |  |   
				| 
 |  
				| You allready know everything you need to do that... All you have to do is apply logic.  Think about the problem, DON'T post here every minor problem you have, try some debugging on your own first, and the answer to your question is actually within the question itself. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| upthescale 
 
 
 
 
 | 
			
				|  Posted: Tue May 23, 2006 3:11 pm    Post subject: (No subject) |  |   
				| 
 |  
				| setscreen ("offscreenonly") var x, y, b : int
 
 loop
 mousewhere (x, y, b)
 
 cls
 drawfilloval (x, y, 10, 10, 7)
 
 
 delay (45)
 View.Update
 end loop
 
 
 i have that so far, but i dont want a delay !! ther is an easier whay but i haven o clue, this is my 3rd day OneTrueGod trying to do this lol
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Cervantes 
 
  
 
 
 | 
			
				|  Posted: Tue May 23, 2006 3:23 pm    Post subject: (No subject) |  |   
				| 
 |  
				| You know all the Turing you need to do this. The part you might not know is the math behind it. 
 You'll need to know Trigonometry. You'll need to be able to determine the angle between two points (arctan), then use SOHCAHTOA (well, mostly just SOHCAH...) to update the position of each ball.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| upthescale 
 
 
 
 
 | 
			
				|  Posted: Tue May 23, 2006 3:34 pm    Post subject: (No subject) |  |   
				| 
 |  
				| i got 90 in trig...ui no trig just i cant apply it in turnig i dont no where t put the X and Y and () and stuff liek that |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Cervantes 
 
  
 
 
 | 
			
				|  Posted: Tue May 23, 2006 3:46 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Here's the battle plan: 
 
 
 Write a function that can determine the angle between two points.
Use that function to determine the angle between the mouse and a particular ball.
Use the angle between the mouse and the ball to determine the components (x and y) of the acceleration of the ball.
Apply acceleration to velocity
Apply velocity to position
Repeat steps 2 - 5 for all the other balls.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| upthescale 
 
 
 
 
 | 
			
				|  Posted: Tue May 23, 2006 4:06 pm    Post subject: (No subject) |  |   
				| 
 |  
				| is this ok? the hit detection is off 
 
 	  | code: |  	  | 
setscreen ("offscreenonly;graphics:700;600;nobuttonbar;position:truemiddle;center;title:Round And Round")
 const playerSpeed := 4
 var tx : int := Rand.Int (30, 670)
 var ty : int := Rand.Int (30, 570)
 var d : int := 120
 type balls :
 record
 ballx : int
 bally : int
 xchange : int
 ychange : int
 size : int
 end record
 var ball : array 1 .. 10 of balls
 for i : 1 .. 10
 randint (ball (i).ballx, 20, 680)
 randint (ball (i).bally, 20, 580)
 ball (i).xchange := 3
 ball (i).ychange := 3
 ball (i).size := 30
 end for
 loop
 colorback (7)
 cls
 Draw.FillArc (round (tx - 15), round (ty - 15), 20, 20, 30, -30, yellow)
 var x, y, b : int
 mousewhere (x, y, b)
 if b = 1 and (x not= tx or y not= ty) then
 var dx : int := round ((x - tx) * playerSpeed / d)
 var dy : int := round ((y - ty) * playerSpeed / d)
 if abs (dx) > abs (x - tx) then
 tx := x
 else
 tx += dx
 end if
 if abs (dy) > abs (y - ty) then
 ty := +ty
 else
 ty += dy
 end if
 end if
 for i : 1 .. 10
 drawfilloval (ball (i).ballx, ball (i).bally, ball (i).size, ball (i).size, red)
 drawoval (ball (i).ballx, ball (i).bally, ball (i).size + 1, ball (i).size + 1, 9)
 ball (i).ballx += ball (i).xchange
 ball (i).bally += ball (i).ychange
 if ball (i).bally > 570 then
 ball (i).ychange := -ball (i).ychange
 end if
 if ball (i).bally < 30 then
 ball (i).ychange := -ball (i).ychange
 end if
 if ball (i).ballx > 670 then
 ball (i).xchange := -ball (i).xchange
 end if
 if ball (i).ballx < 30 then
 ball (i).xchange := -ball (i).xchange
 end if
 if Math.Distance (tx, ty, ball (i).ballx, ball (i).bally) < ball (i).size * 1 then
 break
 end if
 end for
 delay (10)
 View.Update
 end loop
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Clayton 
 
  
 
 
 | 
			
				|  Posted: Tue May 23, 2006 4:25 pm    Post subject: (No subject) |  |   
				| 
 |  
				| you know the funny thing upthescale, you are a fairly good programmer when you actually put your mind to it, all you have to learn to do is sit down and think about what you want to do before you run to the keyboard and type up what you want to do |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| upthescale 
 
 
 
 
 | 
			
				|  Posted: Tue May 23, 2006 4:30 pm    Post subject: (No subject) |  |   
				| 
 |  
				| i may be good but 1-i can program fine, just i dont no wut alot of the stuff means
 2- i copied that fum turing help and changed it up alot, by adding bouncing balls, the shape of the mosuewhere figure, and the speed
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| MysticVegeta 
 
  
 
 
 | 
			
				|  Posted: Tue May 23, 2006 7:11 pm    Post subject: (No subject) |  |   
				| 
 |  
				| if you are making a game in which there are obstructions like walls or something then the shortest route for the ball that is catching up to the original one wont be using trig ratios, you would have to use dfs or bfs algorithm for the shortest path. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Cervantes 
 
  
 
 
 | 
			
				|  Posted: Tue May 23, 2006 8:17 pm    Post subject: (No subject) |  |   
				| 
 |  
				| MysticVegeta wrote: you would have to use dfs or bfs algorithm for the shortest path. 
 That's, "Depth First Search" and "Breadth First Search".
 
 MysticVegeta, the point of posting in the help forum is not to show off, it's to offer help. To that end, it's a good idea to define acronyms.
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |