How do you make objects move using the arrow keys and mouse?
Author |
Message |
Hopping
|
Posted: Fri Jan 27, 2012 7:07 pm Post subject: 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)
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
|
|
|
![](images/spacer.gif) |
Velocity
![](http://compsci.ca/v3/uploads/user_avatars/1809397984eb9e2888e99b.jpg)
|
Posted: Fri Jan 27, 2012 8:40 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Hopping
|
Posted: Fri Jan 27, 2012 9:34 pm Post subject: Re: RE:How do you make objects move using the arrow keys and mouse? |
|
|
Raknarg @ Fri Jan 27, 2012 7:11 pm wrote: 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[/url] |
|
|
|
|
![](images/spacer.gif) |
Aange10
![](http://compsci.ca/v3/uploads/user_avatars/19166165534f400d42de502.png)
|
Posted: Fri Jan 27, 2012 9:46 pm Post subject: RE:How do you make objects move using the arrow keys and mouse? |
|
|
Quote:
why does the previous position of the car stay?
because you never made it leave, you just drew it again in another spot.
Quote:
shouldn't it disappear
It will, if you erase it ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
|
|
|
|
![](images/spacer.gif) |
Beastinonyou
![](http://compsci.ca/v3/uploads/user_avatars/10820786614fe1f6d9ccbda.png)
|
Posted: Sat Jan 28, 2012 9:29 am Post subject: Re: How do you make objects move using the arrow keys and mouse? |
|
|
Basically, Something along these lines:
Turing: | 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
|
|
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sat Jan 28, 2012 10:29 am Post subject: 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? |
|
|
|
|
![](images/spacer.gif) |
Velocity
![](http://compsci.ca/v3/uploads/user_avatars/1809397984eb9e2888e99b.jpg)
|
Posted: Sat Jan 28, 2012 12:12 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Aange10
![](http://compsci.ca/v3/uploads/user_avatars/19166165534f400d42de502.png)
|
Posted: Sat Jan 28, 2012 12:59 pm Post subject: Re: RE:How do you make objects move using the arrow keys and mouse? |
|
|
Velocity @ 28/1/2012, 11:12 am wrote: 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.
Turing: |
%%% 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
|
|
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sat Jan 28, 2012 1:09 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
Hopping
|
Posted: Thu Feb 09, 2012 2:11 pm Post subject: 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_? |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu Feb 09, 2012 4:41 pm Post subject: RE:How do you make objects move using the arrow keys and mouse? |
|
|
if key ('w') then |
|
|
|
|
![](images/spacer.gif) |
|
|