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

Username:   Password: 
 RegisterRegister   
 getting a character without having to stop the program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
superman500




PostPosted: Tue Nov 14, 2006 11:55 pm   Post subject: getting a character without having to stop the program

hey guys...im trying to make a DDR program for my g11 final game project and right now im trying to see how im gonna make the program detect keys without stopping the arrows....


%//////////////////////////////////////////////////////////////////////////////
procedure start
setscreen ("graphics:800;800")
colorback (red)
cls
var x : array 1 .. 7 of int := init (180, 180, 80, 80,
30, 80, 80)
var y : array 1 .. 7 of int := init (740, 710, 700, 675,
725, 775, 750)
Draw.FillPolygon (x, y, 7, brightblue)
Draw.Polygon (x, y, 7, cyan)
end start

procedure sety (num : int, var y : array 1 .. 7 of int)
y (1) := num + 15
y (2) := num - 15
y (3) := num - 25
y (4) := num - 50
y (5) := num
y (6) := num + 50
y (7) := num + 25
end sety

procedure leftarrow
var x : array 1 .. 7 of int := init (180, 180, 80, 80,
30, 80, 80)
var y : array 1 .. 7 of int
var key : string (1)

for i : 1 .. 800
start
View.Set ("offscreenonly")
sety (i, y)
Draw.FillPolygon (x, y, 7, brightred)
Draw.Polygon (x, y, 7, red)
View.Update
delay (1)
Draw.FillPolygon (x, y, 7, colorbg)
Draw.Polygon (x, y, 7, colorbg)

locate (50, 1)


end for

end leftarrow

start
leftarrow
%//////////////////////////////////////////////////////////////////////////////


thats my program so far...just really basic......theres an arrow at the top of the screen and another arrow is coming upwards from the bottom. Im gonna decide to score by the difference between the one of the y values of the arrow compared to a constant so i have that covered. I just need to figure out how to get a character and make sure its the Left Arrow Key (using ord) without stopping the program (because im gonna have a lot more arrows running at the same time and on the same screen). i need a way to detect what keys the user hits without stopping the program basically. Any suggestions?
Sponsor
Sponsor
Sponsor
sponsor
superman500




PostPosted: Tue Nov 14, 2006 11:57 pm   Post subject: (No subject)

wow nvm i just found the answer in another topic XD

Input.Keydown

now i just have to learn how to use it =\
ericfourfour




PostPosted: Wed Nov 15, 2006 12:18 am   Post subject: (No subject)

Try this one instead.

code:
var input : string
loop
    if Input.hasch () then
        input = Input.getchar ()
    end if
end loop


That one only gets a character only when there is one in the keyboard buffer. Input.hasch () returns false if no keys are pressed, however if a key is pressed it returns true. Input.getchar () returns the character representing the key being pressed. Plus it handles shift+letter (for capitals) and does not crash with ctrl+z. The only down side is it cannot handle multiple keys at once.
Andy




PostPosted: Wed Nov 15, 2006 1:54 am   Post subject: (No subject)

Input.Keydown is the way you should do it, but getch would work just fine
superman500




PostPosted: Wed Nov 15, 2006 10:45 pm   Post subject: (No subject)

i've been playing around with it...i realized using Input.Keydown won't work cuz they can just hold the arrow key down and they would still get the points...anyone have a way to bypass this? ><...
NikG




PostPosted: Thu Nov 16, 2006 10:49 am   Post subject: (No subject)

I've had this problem b4 too and I'm not sure there's a really good solution.

But for a ddr game, this shouldn't be a problem.
If the player is pressing the key when he shouldn't be, shouldn't his points be decreasing?
Also, I'm assuming you're gonna have input for all 4 arrow keys, so how exactly is the player getting all the points for holding just one of them down?
Wolf_Destiny




PostPosted: Fri Nov 17, 2006 10:58 pm   Post subject: (No subject)

If the problem is that they can just hold down the key and rack up the points, then after you check to see if the key is pressed, create a loop that only exits when the key is released.
Turing:
var chars : array char of boolean
loop
Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
put "You pressed the UP ARROW!"
loop
Input.KeyDown (chars)
exit when not chars (KEY_UP_ARROW)
end loop
put "You released the UP ARROW!"
end if
end loop

Same thing works with any key, and the mouse, and even a joystick! Just think about the principle, You pressed the key, now let it go, okay now you can press it again!

~Wolf_Destiny
ericfourfour




PostPosted: Fri Nov 17, 2006 11:39 pm   Post subject: (No subject)

Wolf_Destiny wrote:
create a loop that only exits when the key is released

You can do that but I would not suggest it. That way will basically stop your program until the key is released. Instead have a flag that is true when the key is pressed and false when it is released. That way you could do what you want and stay in the main loop.

code:
var input : string

%key status from last frame
var key_down : boolean := false
loop

   %check for input
    if Input.hasch () then

        %if the key was not down last frame
        if not key_down then

            %do action(s) using input
            input = Input.getchar ()

            %make it so the next frame knows the key was down this frame
            key_down = true
        end if

    %there was no input
    else

        %make it so the next frame knows the key was not down this frame
        key_down = false
    end if
end loop


This one is only for the Input.hasch ()/Input.getchar () way. The way you need to do it for DDR is the Input.KeyDown way. I'll let you figure out that one.
Sponsor
Sponsor
Sponsor
sponsor
Chrisd534




PostPosted: Wed Nov 29, 2006 9:37 pm   Post subject: (No subject)

yo so did u get the game finished i wanna play it lol
PiGuy




PostPosted: Wed Nov 29, 2006 10:04 pm   Post subject: (No subject)

Just like what NikG say, why don't you just subtract points if they hold
down the key when they shouldn't?

If, for example, they press the key when the arrow is, say, 50 pixels or
more away from the top, subtract points. Also, as soon as you evaluate
the player's correct input and add points to their total, you can set flag so
that any more input after that will result in point subtraction.

Of course, this may get somewhat messy for multiple arrows, but can
probably be solved by focusing on the arrow closest to the top.
superman500




PostPosted: Fri Dec 01, 2006 8:39 am   Post subject: (No subject)

hey guys..just an update on the program...me and my partner are pretty much done now and it works fine cept it might be laggy on slow computers....the only thing that we couldnt do is make the arrows match up with the beats of the song..i guess we could manually do it but it would change on each computer depending on the computer speed..=\....but yeah....measure bar works..scoring works..everything works cept the arrows matching with the song...right now its random...
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  [ 11 Posts ]
Jump to:   


Style:  
Search: