Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 checking arrows
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 1:51 pm   Post subject: checking arrows

aite got the attacks,, i got a quick question is there a way to check what key has been pressed last for example if i press the left arrow to move to knwo that and then to display the attack on the left side instead of the normal side?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jun 19, 2004 1:57 pm   Post subject: (No subject)

you keep a buffer, where you record the keys (or key if you just need one) pressed. So if you want to look up the history of input, you just check the buffer string
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
eNc




PostPosted: Sat Jun 19, 2004 2:30 pm   Post subject: (No subject)

tony wrote:
you keep a buffer, where you record the keys (or key if you just need one) pressed. So if you want to look up the history of input, you just check the buffer string



whats a buffer ? is it like an array or somthing ?
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 3:08 pm   Post subject: (No subject)

ya what is a buffer i never learned this in class lol
SuperGenius




PostPosted: Sat Jun 19, 2004 3:09 pm   Post subject: (No subject)

have a string var an everytime there is a keypress do this:

code:

if keypress then %there has been a keystroke
input:=input + keystroke
end if


everytime someone presses a key it is added to one long string var. Also you could make an elsif substructure to check if they press delete and tell the program to subtract the last character from your input string.
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 3:47 pm   Post subject: (No subject)

ok so for example now i want a picture display i can go liek

code:

if keypress then %there has been a keystroke
input:=input + keystroke
end if

if input = (KEY_RIGHT_ARROW) THEN
Pic.Draw (back,0,0,picCopy0
end if


something like that or do i instead of if input i put if keystroke? Embarassed
and do i put this in my input.keydown loop
SuperGenius




PostPosted: Sat Jun 19, 2004 6:07 pm   Post subject: (No subject)

if what you're trying to do is display a certain picture when the right arrow is pressed, you're off a bit, and I may have confused you earlier. If you want to display a picture at the exact time that the right arrow is pressed then you would do someting like option one. but to check if there has been a right key press in the past you would need to do something like option 2, and put the checking part at the end of my example where you want to check for a right arrow press.
code:

% use this to find ord codes for keys
% var a : string (1)
% loop
%     getch (a)
%     put ord (a)
% end loop
%
%
% %option 1
% var chars : array char of boolean
% loop
%     Input.KeyDown (chars)
%     if chars (KEY_RIGHT_ARROW) then
%         put "your code for a right arrow press here"
%         delay (100)
%     end if
% end loop

%option 2
var keystroke : string (1)
var input : string := ""
loop
    getch (keystroke)
    exit when ord (keystroke) = 207 %press end to exit
    if ord (keystroke) not= 8 then % 8 is the ord number of backspace key
        input := input + intstr (ord (keystroke)) + " "
    else
        if length (input) > 0 then
            input := input (1 .. * -1) %delets the last char if you pressed backspace
        end if
    end if
end loop
put input

%checker thing

if index (input, "205") not= 0 then
    put "they pressed the right arrow"
else
    put "they didnt press the right arrow"
end if


you can see all of the ord numbers that they pressed after you exit the loop.
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 7:17 pm   Post subject: (No subject)

ahem aite, yah i'm trying to display a certain picture when the character is facing right and certian picture when chracter is facing left and the only way i though of is to check what arrow has been pressed beofre the picture is dispalyed.. so ill give that thing a try and see if it works.
Sponsor
Sponsor
Sponsor
sponsor
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 7:32 pm   Post subject: (No subject)

hum yah it works ehe but it kidna gets stuck so when ever i press the rigth arrow it keeys applying that picture hum here i attached a file so u can see what i'm trying to do might explain a thing or two better Rolling Eyes


Global Warriors.zip
 Description:

Download
 Filename:  Global Warriors.zip
 Filesize:  1.52 MB
 Downloaded:  680 Time(s)

Tony




PostPosted: Sat Jun 19, 2004 7:43 pm   Post subject: (No subject)

can't you just have a variable for character's direction ?

whenever an arrow key is pressed, that direction is set to the new value. Then whenever you need to reference the direction that character is facing (such as to pick which picture to draw) you just take the value from that variable
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 8:35 pm   Post subject: (No subject)

hum, u eman liek a counter px :=px? or what lol and then if it is less then it was before put another pic ahem i guess i could try it :p
TrAnCeIn4LiFe




PostPosted: Sat Jun 19, 2004 8:46 pm   Post subject: (No subject)

ah woot got it working thx bro Laughing
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: