[Tutorial] Character control on screen (Input.KeyDown)
Author |
Message |
Tony
|
Posted: Wed Aug 27, 2003 5:52 pm Post subject: (No subject) |
|
|
chars (chr (ORD_SPACE)) should return the correct value for you to use with chars array.
I sujest making your own constant and assigning it that value so that it is not calculated each time you check |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Jonny Tight Lips
|
Posted: Thu Feb 12, 2004 4:05 pm Post subject: question |
|
|
Quote:
if ch = chr (num of key) then
some of the nums for the keys are: 208 (down), 200 (up), 203 (left), 205 (right)
I was wondering what the number would be 4 the space bar and the enter keys?? |
|
|
|
|
|
recneps
|
Posted: Thu Feb 12, 2004 4:15 pm Post subject: (No subject) |
|
|
Its in the Turing Referance, on the first page, i believe and if you have the Turing textbook (which covers next to nothing ;p) its in there.... and if you looked up you would've seen in the examples, "chr(ORD_SPACE)" and enter is just enter i believe...? |
|
|
|
|
|
shorthair
|
Posted: Thu Feb 12, 2004 4:29 pm Post subject: (No subject) |
|
|
ummm if you seach compsci ( i dont know where it is ) i wrote an app ,that tells you the ord of every button on the ascii keyboard , so you just run itand press a key and the number of that key pops up ( sorry to plug the tutorial ) but it would just be a good thing to have while making a game |
|
|
|
|
|
Cervantes
|
Posted: Thu Feb 12, 2004 4:29 pm Post subject: (No subject) |
|
|
for enter just use
KEY_ENTER
so in the code
code: | if chars (KEY_ENTER) then
%bla bla bla
end if |
|
|
|
|
|
|
Jonny Tight Lips
|
Posted: Thu Feb 12, 2004 4:31 pm Post subject: (No subject) |
|
|
it didn't work for some reason?
code: | if chars = chr (ORD_SPACE) then
end if
|
I dunno if I did something wrong or what?? PLease help. Oh and just so U know I'm using dos turing so the (KEY_ENTER) stuff doesn't work. |
|
|
|
|
|
Jonny Tight Lips
|
|
|
|
|
santabruzer
|
Posted: Thu Feb 12, 2004 6:00 pm Post subject: (No subject) |
|
|
err.. it should be:
chars (chr (ORD_SPACE)) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Jonny Tight Lips
|
Posted: Mon Feb 16, 2004 5:15 pm Post subject: (No subject) |
|
|
ummm I'm pritty sure I got it right ....
code: | if hasch then
getch (chars)
end if
if chars = chr (200) and flagd = 0 then
y3 := y3 + 10
end if
if chars = chr (205) and flagc = 0 then
x3 := x3 + 10
end if
if chars = chr (203) and flaga = 0 then
x3 := x3 - 10
end if
if chars = chr (208) and flagb = 0 then
y3 := y3 - 10
end if
if chars = chr (32)
%Do w/e
end if |
as you can see thats they way I did it becasue I was using dos turing and I don't think it would work the other way so thats the way I did it and it works so w/e. |
|
|
|
|
|
mapleleafs
|
Posted: Thu Feb 19, 2004 7:56 pm Post subject: (No subject) |
|
|
hey, can sumone tell me a way of achieving a 'magnetic' sort of effect. For example, I have a object/picture which is under the control of the user, and when the user presses a certain button, i want the object/picture to automatically move to a set area, say one side of the screen. |
|
|
|
|
|
Cervantes
|
Posted: Thu Feb 19, 2004 8:49 pm Post subject: (No subject) |
|
|
huh? you mean this?
code: |
var objx, objy : int := 200
var keys : array char of boolean
loop
Input.KeyDown (keys)
if keys (KEY_ENTER) then
objx := 50
objy := 50
end if
drawfilloval (objx, objy, 20,20, black)
delay (10)
drawfilloval (objx, objy, 20,20, white)
end loop
|
|
|
|
|
|
|
mapleleafs
|
Posted: Thu Feb 19, 2004 9:15 pm Post subject: (No subject) |
|
|
no, not like that. I want the ball to flow to the other area, not just instantaneosly appear there. |
|
|
|
|
|
Tony
|
|
|
|
|
mapleleafs
|
Posted: Thu Feb 19, 2004 9:42 pm Post subject: (No subject) |
|
|
i know that's how you move an object, but i'm asking how you would apply that pixel-by-pixel theory if the object was human controlled(hence, moving at unknown/random positions) , and then at a certain point in time (eg. a button is pressed) , you would get that object to flow to a certain area.
cuz i can't just use a for loop and then increment the coordinates because since the object is being moved around by the user, it would be impossible (i think) for the program to know which coordinates to increase to get to the set area.
sorry if this is really confusing, but help is much appreciated |
|
|
|
|
|
beard0
|
Posted: Fri May 28, 2004 12:11 pm Post subject: (No subject) |
|
|
say you want it to flow to (px,py) and it's at (x,y):
code: | var steps := round (sqrt ((px - x) ** 2 + (px - y) ** 2)) %this makes steps of 1 pixel each
var xreal : real := x
var yreal : real := y
for i : 1 .. steps
xreal += (px - x) / (steps - (i - 1))
yreal += (py - y) / (steps - (i - 1))
x := round (xreal)
y := round (yreal)
%code for erasing old pic, and drawing new
delay (50) %change this to change speed
end for
|
|
|
|
|
|
|
|
|