
-----------------------------------
Hopping
Fri Jan 27, 2012 7:07 pm

How do you make objects move using the arrow keys and mouse?
-----------------------------------
What is it you are trying to achieve?
I am trying to make a car (just a box -- drawfillbox) move around (right, left, front, back) using the keyboard arrow keys. And also just using the mouse as well (follow cursor).


What is the problem you are having?
Do not know where to start...What code...Any help is much appreciated.


Describe what you have tried to solve this problem
Searched on Google.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



drawfillbox (50, 50, 100, 100, blue)



Please specify what version of Turing you are using
Turing 4.1.1

-----------------------------------
Raknarg
Fri Jan 27, 2012 7:11 pm

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
http://compsci.ca/v3/viewtopic.php?t=114

-----------------------------------
Velocity
Fri Jan 27, 2012 8:40 pm

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
well for arrow keys you would do 
%%% just an example, its not a real box im just showing you how to do it
var box_x1, box_x2 : int
box_x1 := 100
box_x2 := 200
drawfillbox (box_x1, 50, box_x2, 100, red)

var keys : array char of boolean

if keys (RIGHT_ARROW_KEY) then %%% the caps are a must
box_x1 += 1
box _x2 += 1
end if
if keys (LEFT_ARROW_KEY) then
box_x1 -= 1
box_x2 -= 1
end if

%note this isnt my true coding, else it would be more organized, just wrote for you in a minute

-----------------------------------
Hopping
Fri Jan 27, 2012 9:34 pm

Re: RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
http://compsci.ca/v3/viewtopic.php?t=114
Thank you, that was very helpful.

Just one problem with it...I'm making a traffic lights project and I made the car a box as you can see in this picture: http://i40.tinypic.com/2v0fviw.png

but when I move it using the keyboard arrow keys (i went up and then took a right), this happens: http://i44.tinypic.com/23gz888.png

why does the previous position of the car stay? shouldn't it disappear when it gets to a new position. like a normal car moving instead of leaving this trail like it is in the pic, lol...

can anyone help me with that?

thnxx

-----------------------------------
Aange10
Fri Jan 27, 2012 9:46 pm

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------

why does the previous position of the car stay?


because you never made it leave, you just drew it again in another spot.


shouldn't it disappear


It will, if you erase it ;)

-----------------------------------
Beastinonyou
Sat Jan 28, 2012 9:29 am

Re: How do you make objects move using the arrow keys and mouse?
-----------------------------------
Basically, Something along these lines:

View.Set ("offscreenonly")
loop
     % Draw your Background, etc
     % Draw your Car
     % Do whatever else you need
     View.UpdateArea (0, 0, maxx, maxy) % Alternatively, View.Update
     cls
     % Optional delay (time in Milliseconds)
end loop


-----------------------------------
Raknarg
Sat Jan 28, 2012 10:29 am

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
Lets saw in this program, you had a oaintbrush. You paint the backround, and then you plaint a red box on to it. Now you devide that the box should be somewhere else, so you paint it there. What happens now? Has the box moved? No, you've just painted it somewhere else, so you have two boxes. What can you do instead? If you want it to move, you can paint everything white, then the background, then paint the new box.

Getting the idea?

-----------------------------------
Velocity
Sat Jan 28, 2012 12:12 pm

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
does no one ever look at my code? 
T
You need a  cls at the bottom so it erases the previous pos like beastinonyou said

-----------------------------------
Aange10
Sat Jan 28, 2012 12:59 pm

Re: RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
does no one ever look at my code? 
You need a  cls at the bottom so it erases the previous pos like beastinonyou said

Your code doesn't have a cls in it.


%%% just an example, its not a real box im just showing you how to do it
var box_x1, box_x2 : int
box_x1 := 100
box_x2 := 200
drawfillbox (box_x1, 50, box_x2, 100, red)

var keys : array char of boolean

if keys (RIGHT_ARROW_KEY) then %%% the caps are a must
box_x1 += 1
box _x2 += 1
end if
if keys (LEFT_ARROW_KEY) then
box_x1 -= 1
box_x2 -= 1
end if

%note this isnt my true coding, else it would be more organized, just wrote for you in a minute


-----------------------------------
Raknarg
Sat Jan 28, 2012 1:09 pm

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
If we're having a trollfest here, then you also didn't include Input.KeyDown.

-----------------------------------
Hopping
Thu Feb 09, 2012 2:11 pm

Re: How do you make objects move using the arrow keys and mouse?
-----------------------------------
Ok, got that, how do you make the arrow keys with the a, s, d, and w letters.

w= up
d=right
a=left
s=down

KEY_?

-----------------------------------
Raknarg
Thu Feb 09, 2012 4:41 pm

RE:How do you make objects move using the arrow keys and mouse?
-----------------------------------
if key ('w') then
