input from mouse and keyboard

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

input from mouse and keyboard

Ralph Boland
In a real time game I am creating I need to be able to get input from
both the keyboard and
the mouse (by player pressing buttons displayed on the screen).  The
game requires immediate responses to both.
If the user provides no input the game continues and actions occur
(eventually killing the player).

For the keyboard input I seem to be need to be in some kind of loop:
1)  sleep for some small amount of time; if during the sleep some
keyboard input arrives respond to the input and then  goto 1.
2)  Since there has been no keyboard input take any necessary game
actions and then goto 1.

If a button is pressed then take necessary game actions and then
ensure that the above loop is at the beginning of the sleep.

IS THERE ANY SAMPLES OF CODE SOMEWHERE THAT DOES THIS KIND OF THING?

I could figure this out eventually but it will take a while and I will
probably do a poor implementation.

Note:
There are many slow points in the game where a forced garbage
collection can be performed so garbage collection
delays should not be problem.



Thanks

Ralph Boland

Reply | Threaded
Open this post in threaded view
|

Re: input from mouse and keyboard

timrowledge
Ralph, pretty much the entire Morphic UI system does what you are asking about. The entire event loop mechanism is about getting key & mouse presses in and passed to whatever widget wants them.

Sounds to me that you just want some Morphs with #step methods setup to play your game along with event handling methods as appropriate. As long as I understood you correctly, that is...

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
How come it's 'Java One' every year? Aren't they making any progress?



Reply | Threaded
Open this post in threaded view
|

Re: input from mouse and keyboard

Stéphane Rollandin
In reply to this post by Ralph Boland
You can see how I managed event handling in my Saucers! game by looking
at the code, downloadable at the bottom of this page:

http://www.zogotounga.net/comp/saucers.htm


Stef