Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-24-2010, 05:08 PM   #1 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 119
Whitehk is on a distinguished road
Default Making a multiplayer pong-style game?

Hi. I am 13 years-old and new to iphone development. I created my first app successfully and now I'm adding "the bells and whistles". I am trying to make a multiplayer option. Oh and by the way, the app is a pong-like game.(where you hit the ball back and forth and try to get it past your opponent) I need a way to compare where the user's touch is on the screen in relation to his half of the screen. So lets say on the bottom half we have player one and on the top half we have player 2. Player 1 is able to move there paddle without effecting player 2's paddle, and player 2 is able to move their paddle without effecting player 1's paddle. So basically there would be two people touching the screen at once and at a certain point, such as the center line dividing the two sides (think tennis as in the net dividing the two sides), you're not able to move the paddle that is on your half of the screen anymore. I have no idea how i'm gonna go about doing this. Any ideas? A great example of what I'm trying to accomplish would be the 2 player option on the glow hockey app on the app store. Sorry it's worded weirdly. I did the best I could to explain it. Thanks for helping. I appreciate it!
Whitehk is offline   Reply With Quote
Old 02-24-2010, 06:23 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

When a player (either player) touches the screen or moves their finger, you'll get the x and y positions of the touch. Assuming the screen is 480 pixels high, you know that a touch between 0 and 240 is in the top half, and a touch between 240 and 480 is in the lower half. You should be able to do something like this:

Code:
if (touchPosition.y < 240)
   // move player1puck to touchPosition.x
else
  // move player2puck to touchPosition.x
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-24-2010, 07:46 PM   #3 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 119
Whitehk is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
When a player (either player) touches the screen or moves their finger, you'll get the x and y positions of the touch. Assuming the screen is 480 pixels high, you know that a touch between 0 and 240 is in the top half, and a touch between 240 and 480 is in the lower half. You should be able to do something like this:

Code:
if (touchPosition.y < 240)
   // move player1puck to touchPosition.x
else
  // move player2puck to touchPosition.x
The only problem with this is that both user's touches interfere with one another. I want to make it to where it does what you said, but Player 1 and Player 2 are able to move their paddles separately and at the same time. If I did it like you said, Player 1 would have to start the game, hit the ball, then release his finger in order for player 2 to be able to move their paddle. I do appreciate the reply though. It was definitely on the right track. Now, I just need to figure out how to make two separate touches on each half of the court. Anyone got any ideas?
Whitehk is offline   Reply With Quote
Old 02-24-2010, 11:08 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Player 1 does not have to release their finger - you'll get the touches for player 2 just fine, assuming you've enabled multi-touch and you're looping through all of the touches in the event. Check this thread.

http://www.iphonedevsdk.com/forum/ip...html#post89851

I bet you're only checking the first touch, no matter how many touches there are.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 03-01-2010, 12:33 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 12
romeorx2 is on a distinguished road
Default

Quote:
Originally Posted by Whitehk View Post
The only problem with this is that both user's touches interfere with one another. I want to make it to where it does what you said, but Player 1 and Player 2 are able to move their paddles separately and at the same time. If I did it like you said, Player 1 would have to start the game, hit the ball, then release his finger in order for player 2 to be able to move their paddle. I do appreciate the reply though. It was definitely on the right track. Now, I just need to figure out how to make two separate touches on each half of the court. Anyone got any ideas?

Maybe You Can try this:


CGPoint touchPoint = [touch locationInView:self.view];
CGPoint location = [touch locationInView:touch.view];
//if (CGRectContainsPoint([paddle frame], touchPoint)) {
if (location.y >= 241){
[UIView beginAnimations:@"Move Paddle" context:nil];
CGPoint xtouchPoint = CGPointMake(touchPoint.x,paddle.center.y);
paddle.center = xtouchPoint;
[UIView commitAnimations];
}

//if (CGRectContainsPoint([paddle2 frame], touchPoint)) {
if (location.y <= 240){
[UIView beginAnimations:@"Move Paddle" context:nil];
CGPoint xtouchPoint = CGPointMake(touchPoint.x,paddle2.center.y);
paddle2.center = xtouchPoint;
[UIView commitAnimations];
}

}


}

thats the code i used,

I Have a game similar to what you are trying to do in the App Store it's called "Star Tennis"

Hope this helps
romeorx2 is offline   Reply With Quote
Reply

Bookmarks

Tags
2 player, glow hockey, multiplayer, multitouch, touch location

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 400
8 members and 392 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:45 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0