wyrmmage
2006.08.21, 03:52 PM
First off: sorry about posting two threads about different things.
Anyway: I've been trying to program "pong" on my mac, and I've gotten to the stage where I have two rectangles up on the screen, but now I need to be able to move them. I've been using code from nehe's site (nehe.gamedev.net), so I have a basic for handling user input, it looks like this:
- (void) keyDown:(NSEvent *)theEvent
{
unichar unicodeKey;
unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
switch( unicodeKey )
{
case 0xF700:
[glView moveHleft];
break;
case 0xF701:
[glView moveHright];
break;
case 0x0077:
[glView moveYleft];
break;
case 0x0073:
[glView moveYright];
break;
default:
break;
}
}
obviously I'm using carbon and Objective-C to program this; the file that that piece of code ^^^^^ resides in is an extension of NSResponder. If a user presses the up or down arrow, it moves one paddle, if it presses the "w" or "s" key, it moves the other paddle; this would be fine if I were going to use AI for one of the paddles, but I'm trying to make the game two-player.
Therefore I need to know: how do I handle more than one key being pressed, so I can tell if one off the (w or s) keys is being pressed and if one of the (up or down arrow keys) is being pressed at the same time?
Thank you for your help :)
-wyrmmage
Anyway: I've been trying to program "pong" on my mac, and I've gotten to the stage where I have two rectangles up on the screen, but now I need to be able to move them. I've been using code from nehe's site (nehe.gamedev.net), so I have a basic for handling user input, it looks like this:
- (void) keyDown:(NSEvent *)theEvent
{
unichar unicodeKey;
unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
switch( unicodeKey )
{
case 0xF700:
[glView moveHleft];
break;
case 0xF701:
[glView moveHright];
break;
case 0x0077:
[glView moveYleft];
break;
case 0x0073:
[glView moveYright];
break;
default:
break;
}
}
obviously I'm using carbon and Objective-C to program this; the file that that piece of code ^^^^^ resides in is an extension of NSResponder. If a user presses the up or down arrow, it moves one paddle, if it presses the "w" or "s" key, it moves the other paddle; this would be fine if I were going to use AI for one of the paddles, but I'm trying to make the game two-player.
Therefore I need to know: how do I handle more than one key being pressed, so I can tell if one off the (w or s) keys is being pressed and if one of the (up or down arrow keys) is being pressed at the same time?
Thank you for your help :)
-wyrmmage