<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: iPhone Game Programming Tutorial Part 2- User Interaction, Simple AI, Game Logic</title>
	<atom:link href="http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/</link>
	<description>iPhone Programming Tutorials</description>
	<lastBuildDate>Tue, 07 Sep 2010 14:34:04 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: App development per iOS, i tutorial - TheAppleLounge</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-6286</link>
		<dc:creator>App development per iOS, i tutorial - TheAppleLounge</dc:creator>
		<pubDate>Tue, 24 Aug 2010 10:33:27 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-6286</guid>
		<description>[...] di un videogioco per iPhone. Un semplice Pong style che ci consente di apprendere di più sulla collisione di oggetti, Ai, processi di interazione degli utenti (parte 2), creazione di splash page [...]</description>
		<content:encoded><![CDATA[<p>[...] di un videogioco per iPhone. Un semplice Pong style che ci consente di apprendere di più sulla collisione di oggetti, Ai, processi di interazione degli utenti (parte 2), creazione di splash page [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harrison</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-6278</link>
		<dc:creator>Harrison</dc:creator>
		<pubDate>Mon, 23 Aug 2010 15:28:08 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-6278</guid>
		<description>On collision compare the ball.center.x to the racquets.center.x and change the deflection and speed based on difference between them</description>
		<content:encoded><![CDATA[<p>On collision compare the ball.center.x to the racquets.center.x and change the deflection and speed based on difference between them</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noah</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-6254</link>
		<dc:creator>Noah</dc:creator>
		<pubDate>Fri, 20 Aug 2010 20:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-6254</guid>
		<description>I&#039;m having the same problem here. I have no idea what is causing this. When I run debugging, it says &quot;GDB: Program received signal SIGABRT.&quot;</description>
		<content:encoded><![CDATA[<p>I&#8217;m having the same problem here. I have no idea what is causing this. When I run debugging, it says &#8220;GDB: Program received signal SIGABRT.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jorge</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-6251</link>
		<dc:creator>jorge</dc:creator>
		<pubDate>Fri, 20 Aug 2010 15:57:38 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-6251</guid>
		<description>hi me puedes enseñar a como poner el score cuando el personaje del juego se mueve tiene que dar puntos en el escore deacuerdo  a cuanto se mueve puede obtener un puntaje 
GRacias 
espero tu respuesta</description>
		<content:encoded><![CDATA[<p>hi me puedes enseñar a como poner el score cuando el personaje del juego se mueve tiene que dar puntos en el escore deacuerdo  a cuanto se mueve puede obtener un puntaje<br />
GRacias<br />
espero tu respuesta</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gio</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-6094</link>
		<dc:creator>Gio</dc:creator>
		<pubDate>Mon, 02 Aug 2010 14:28:54 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-6094</guid>
		<description>There is an error I&#039;m getting with the player movement, it says &quot;Request of member &quot;view&quot; in something not a structure or union&quot; on the line with CGPoint location. can anyone help?</description>
		<content:encoded><![CDATA[<p>There is an error I&#8217;m getting with the player movement, it says &#8220;Request of member &#8220;view&#8221; in something not a structure or union&#8221; on the line with CGPoint location. can anyone help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TessoMC</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5997</link>
		<dc:creator>TessoMC</dc:creator>
		<pubDate>Wed, 28 Jul 2010 20:26:58 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5997</guid>
		<description>Im having the strangest problem..
When i hit build and go, it all works fine, till the simulator launches the app, it show the itennis loading screen, and then... just quits the game.

Any thoughts?</description>
		<content:encoded><![CDATA[<p>Im having the strangest problem..<br />
When i hit build and go, it all works fine, till the simulator launches the app, it show the itennis loading screen, and then&#8230; just quits the game.</p>
<p>Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iTennis &#8211; iPhone Game Tutorials &#8211; iPhone App Academy</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5790</link>
		<dc:creator>iTennis &#8211; iPhone Game Tutorials &#8211; iPhone App Academy</dc:creator>
		<pubDate>Fri, 09 Jul 2010 07:46:41 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5790</guid>
		<description>[...] iTennis iPhone Game Tutorial &#8211; Lesson 02 [...]</description>
		<content:encoded><![CDATA[<p>[...] iTennis iPhone Game Tutorial &#8211; Lesson 02 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5626</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Thu, 17 Jun 2010 15:11:55 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5626</guid>
		<description>to sort out your problems with collision detection: if speed of ball is greater than ballsize+paddlesize it will not detect collision.

solution:
check for collisions along the _path_ of the ball from current position to next position. if collision happens set ball to point of collision and change velocity.</description>
		<content:encoded><![CDATA[<p>to sort out your problems with collision detection: if speed of ball is greater than ballsize+paddlesize it will not detect collision.</p>
<p>solution:<br />
check for collisions along the _path_ of the ball from current position to next position. if collision happens set ball to point of collision and change velocity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MAT</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5610</link>
		<dc:creator>MAT</dc:creator>
		<pubDate>Tue, 15 Jun 2010 02:55:50 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5610</guid>
		<description>Just something I noticed with the initial code. While the collision with green racquet works, yellow one always misses the ball. By decreasing kBallSpeedY constant from 15 to 10, then the skipped pixels are caught with the ball&#039;s and racquet&#039;s boundary every time.</description>
		<content:encoded><![CDATA[<p>Just something I noticed with the initial code. While the collision with green racquet works, yellow one always misses the ball. By decreasing kBallSpeedY constant from 15 to 10, then the skipped pixels are caught with the ball&#8217;s and racquet&#8217;s boundary every time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shus</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5575</link>
		<dc:creator>shus</dc:creator>
		<pubDate>Sun, 06 Jun 2010 02:59:51 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5575</guid>
		<description>how do i get the exact dimensions of the object other then a square.</description>
		<content:encoded><![CDATA[<p>how do i get the exact dimensions of the object other then a square.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ehab Amer</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5509</link>
		<dc:creator>Ehab Amer</dc:creator>
		<pubDate>Sun, 23 May 2010 12:44:50 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5509</guid>
		<description>I&#039;ve figured out why sometimes the ball would fall through the paddle, its not that the intersection doesn&#039;t happen but its because that sometimes the first intersection happens WHEN the ball&#039;s center is already behind the paddle.

there r 3 ways to fix this :)

1- increase the size of the ball, as already mentioned by &quot;J. Cohen&quot;
2- slow down the ball on the Y axis

(those 2 solutions make the intersection happen before the ball&#039;s  center passes the paddle)

3- just remove the center checking condition and change the direction directly on collision (which i don&#039;t prefer)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve figured out why sometimes the ball would fall through the paddle, its not that the intersection doesn&#8217;t happen but its because that sometimes the first intersection happens WHEN the ball&#8217;s center is already behind the paddle.</p>
<p>there r 3 ways to fix this <img src='http://icodeblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>1- increase the size of the ball, as already mentioned by &#8220;J. Cohen&#8221;<br />
2- slow down the ball on the Y axis</p>
<p>(those 2 solutions make the intersection happen before the ball&#8217;s  center passes the paddle)</p>
<p>3- just remove the center checking condition and change the direction directly on collision (which i don&#8217;t prefer)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5506</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Sun, 23 May 2010 07:57:31 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5506</guid>
		<description>Buru, what was the solution to the final 
@end 
warning message, I am getting the same error, 

I am also getting a &#039;touchesMoved&#039; undeclared error, ( whatever I place as the second section gets this undeclared error)

Thank you so much, I would be very grateful if you could help with these problems,


The Code is below,

#import &quot;iTennisViewController.h&quot;
#define kCompMoveSpeed 15
#define kGameStateRunning 1
#define kGameStatePaused  2

#define kScoreToWin 5
		
#define kBallSpeedX 10
#define kBallSpeedY 15



@implementation iTennisViewController
@synthesize ball,racquet_yellow,racquet_green,player_score,computer_score,gameState,ballVelocity,tapToBegin;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	if(gameState == kGameStatePaused) {
		tapToBegin.hidden = YES;
		gameState = kGameStateRunning;
	} else if(gameState == kGameStateRunning) {
		[self touchesMoved:touches withEvent:event];
	}

	-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
		UITouch *touch = [[event allTouches] anyObject];
		CGPoint location = [touch locationInView:touch.view];
		CGPoint xLocation = CGPointMake(Location.x.racquet_yellow.center.y);
		racquet_yellow.center = xLocation;
	}
	
-(void) gameLoop {
	if(gameState == kGameStateRunning) {

		ball.center = CGPointMake(ball.center.x + ballVelocity.x , ball.center.y + ballVelocity.y);
		
		if(ball.center.x &gt; self.view.bounds.size.width &#124;&#124; ball.center.x  self.view.bounds.size.height &#124;&#124; ball.center.y &lt; 0) {
			ballVelocity.y = -ballVelocity.y;
		}
		// Crash detection  CGRectIntersectsRect. 
		
		if(CGRectIntersectsRect(ball.frame,racquet_yellow.frame)){
			if(ball.center.y &lt; racquet_yellow.center.y) {
				ballVelocity.Y = -ballVelocity.y;
			
			}
		}
		if(CGRectIntersectsRect(ball.frame,racquet_green.frame)){
			if(ball.center.y &lt; racquet_green.center.y) {
				ballVelocity.Y = -ballVelocity.y;
			} else {
				if(tapToBegin.hidden) {
					tapToBegin.hidden = NO;
				}
			}
		
			// Begin Simple AI}
			if(ball.center.y &lt;= self.view.center.y){
				if(ball.center.x  racquet_green.center.x){
					CGPoint compLocation = CGPointMake(racquet_green.center.x + kCompMoveSpeed, racquet_green.center.y);
					racquet_green.center = compLocation;
				}
			}
		// Begin Scoring Game Logic}
			if(ball.center.y =  &gt;= kScoreToWin)]:
	}

			if(ball.center.y &gt; self.view.bounds.size.height) {
	computer_score_value++;
	[self reset:(computer_score_value &gt;= kScoreToWin)];
	}
	
			-(void)reset:(BOOL)newGame{
				self.gameState = kGameStatePaused;
				ball.center = self.view.center;
				if(newGame) {
					If (computer_score_value &gt; player_score_value) {
						tapToBegin.text =@&quot;Computer Wins&quot;;
					} else {
						tapToBegin.text =@&quot;Player Wins!&quot;;
						
					}
					computer_score_value = 0;
					player_score_value = 0;

				} else {
					tapToBegin.text = @&quot;Tap to Begin&quot;;
				}
				player_score.text = [NSString stringWithFromat:@&quot;%d&quot;, player_score_value];
				computer_score.text = [NssString stringWithFromat:@&quot;%d&quot;,computer_score_value];
			}
			
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.gameState = kGameStatePaused;
	ballVelocity = CGPointMake(kBallSpeedX,kBallSpeedY);
	[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn&#039;t have a superview
    // Release anything that&#039;s not essential, such as cached data
}

- (void)dealloc {
    [super dealloc];
	[ball release];
	[racquet_green release];
	[racquet_yellow release];
	[player_score release];
	[computer_score release];
	[tapToBegin release];
}
			
		}
	}
}
}


@end</description>
		<content:encoded><![CDATA[<p>Buru, what was the solution to the final<br />
@end<br />
warning message, I am getting the same error, </p>
<p>I am also getting a &#8216;touchesMoved&#8217; undeclared error, ( whatever I place as the second section gets this undeclared error)</p>
<p>Thank you so much, I would be very grateful if you could help with these problems,</p>
<p>The Code is below,</p>
<p>#import &#8220;iTennisViewController.h&#8221;<br />
#define kCompMoveSpeed 15<br />
#define kGameStateRunning 1<br />
#define kGameStatePaused  2</p>
<p>#define kScoreToWin 5</p>
<p>#define kBallSpeedX 10<br />
#define kBallSpeedY 15</p>
<p>@implementation iTennisViewController<br />
@synthesize ball,racquet_yellow,racquet_green,player_score,computer_score,gameState,ballVelocity,tapToBegin;</p>
<p>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {<br />
	if(gameState == kGameStatePaused) {<br />
		tapToBegin.hidden = YES;<br />
		gameState = kGameStateRunning;<br />
	} else if(gameState == kGameStateRunning) {<br />
		[self touchesMoved:touches withEvent:event];<br />
	}</p>
<p>	-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{<br />
		UITouch *touch = [[event allTouches] anyObject];<br />
		CGPoint location = [touch locationInView:touch.view];<br />
		CGPoint xLocation = CGPointMake(Location.x.racquet_yellow.center.y);<br />
		racquet_yellow.center = xLocation;<br />
	}</p>
<p>-(void) gameLoop {<br />
	if(gameState == kGameStateRunning) {</p>
<p>		ball.center = CGPointMake(ball.center.x + ballVelocity.x , ball.center.y + ballVelocity.y);</p>
<p>		if(ball.center.x &gt; self.view.bounds.size.width || ball.center.x  self.view.bounds.size.height || ball.center.y &lt; 0) {<br />
			ballVelocity.y = -ballVelocity.y;<br />
		}<br />
		// Crash detection  CGRectIntersectsRect. </p>
<p>		if(CGRectIntersectsRect(ball.frame,racquet_yellow.frame)){<br />
			if(ball.center.y &lt; racquet_yellow.center.y) {<br />
				ballVelocity.Y = -ballVelocity.y;</p>
<p>			}<br />
		}<br />
		if(CGRectIntersectsRect(ball.frame,racquet_green.frame)){<br />
			if(ball.center.y &lt; racquet_green.center.y) {<br />
				ballVelocity.Y = -ballVelocity.y;<br />
			} else {<br />
				if(tapToBegin.hidden) {<br />
					tapToBegin.hidden = NO;<br />
				}<br />
			}</p>
<p>			// Begin Simple AI}<br />
			if(ball.center.y &lt;= self.view.center.y){<br />
				if(ball.center.x  racquet_green.center.x){<br />
					CGPoint compLocation = CGPointMake(racquet_green.center.x + kCompMoveSpeed, racquet_green.center.y);<br />
					racquet_green.center = compLocation;<br />
				}<br />
			}<br />
		// Begin Scoring Game Logic}<br />
			if(ball.center.y =  &gt;= kScoreToWin)]:<br />
	}</p>
<p>			if(ball.center.y &gt; self.view.bounds.size.height) {<br />
	computer_score_value++;<br />
	[self reset:(computer_score_value &gt;= kScoreToWin)];<br />
	}</p>
<p>			-(void)reset:(BOOL)newGame{<br />
				self.gameState = kGameStatePaused;<br />
				ball.center = self.view.center;<br />
				if(newGame) {<br />
					If (computer_score_value &gt; player_score_value) {<br />
						tapToBegin.text =@&#8221;Computer Wins&#8221;;<br />
					} else {<br />
						tapToBegin.text =@&#8221;Player Wins!&#8221;;</p>
<p>					}<br />
					computer_score_value = 0;<br />
					player_score_value = 0;</p>
<p>				} else {<br />
					tapToBegin.text = @&#8221;Tap to Begin&#8221;;<br />
				}<br />
				player_score.text = [NSString stringWithFromat:@"%d", player_score_value];<br />
				computer_score.text = [NssString stringWithFromat:@"%d",computer_score_value];<br />
			}</p>
<p>// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.<br />
- (void)viewDidLoad {<br />
    [super viewDidLoad];<br />
	self.gameState = kGameStatePaused;<br />
	ballVelocity = CGPointMake(kBallSpeedX,kBallSpeedY);<br />
	[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];<br />
}</p>
<p>/*<br />
// Override to allow orientations other than the default portrait orientation.<br />
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {<br />
    // Return YES for supported orientations<br />
    return (interfaceOrientation == UIInterfaceOrientationPortrait);<br />
}<br />
*/</p>
<p>- (void)didReceiveMemoryWarning {<br />
    [super didReceiveMemoryWarning]; // Releases the view if it doesn&#8217;t have a superview<br />
    // Release anything that&#8217;s not essential, such as cached data<br />
}</p>
<p>- (void)dealloc {<br />
    [super dealloc];<br />
	[ball release];<br />
	[racquet_green release];<br />
	[racquet_yellow release];<br />
	[player_score release];<br />
	[computer_score release];<br />
	[tapToBegin release];<br />
}</p>
<p>		}<br />
	}<br />
}<br />
}</p>
<p>@end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Buru</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5344</link>
		<dc:creator>Buru</dc:creator>
		<pubDate>Sun, 02 May 2010 09:45:04 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5344</guid>
		<description>ok! I&#039;ve sloved the problem ^^ I had to change the &#039;order&#039;</description>
		<content:encoded><![CDATA[<p>ok! I&#8217;ve sloved the problem ^^ I had to change the &#8216;order&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Buru</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5341</link>
		<dc:creator>Buru</dc:creator>
		<pubDate>Sat, 01 May 2010 18:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5341</guid>
		<description>Hi, I&#039;m having som toubles when trying to make the Game Mechanics: Scoring part.
When I click &#039;build&#039;, en error appears in the line : (iTennisViewController.m)
- (void) reset:(BOOL) newGame {            (!) &#039;RESET&#039; UNDECLARED (2)
    self.gameState = kGameStatePaused;
        .....................

and at the end of the code, at the last line after all the dealloc part :
....
}
@end    /!\ Incomplete implementation of class &#039;ItennisViewController&#039; (2)

Can somebody help me? Thanks all and thanks for the tutorial!</description>
		<content:encoded><![CDATA[<p>Hi, I&#8217;m having som toubles when trying to make the Game Mechanics: Scoring part.<br />
When I click &#8216;build&#8217;, en error appears in the line : (iTennisViewController.m)<br />
- (void) reset:(BOOL) newGame {            (!) &#8216;RESET&#8217; UNDECLARED (2)<br />
    self.gameState = kGameStatePaused;<br />
        &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;</p>
<p>and at the end of the code, at the last line after all the dealloc part :<br />
&#8230;.<br />
}<br />
@end    /!\ Incomplete implementation of class &#8216;ItennisViewController&#8217; (2)</p>
<p>Can somebody help me? Thanks all and thanks for the tutorial!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Balloonboy</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5294</link>
		<dc:creator>Balloonboy</dc:creator>
		<pubDate>Sat, 24 Apr 2010 06:05:34 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5294</guid>
		<description>I am having problem with:

Improve collision detection – When the ball hits the paddle, use some simple physics to make the speed of the paddle affect the speed (and direction) of the ball.

What I&#039;m trying to do is to make it so that:
- Every time the ball hits the paddle it increases the speed a little.
- The ball&#039;s deflection angle determined by how far is the ball from the center of the paddle when it hits. 

Can anyone help me on these?</description>
		<content:encoded><![CDATA[<p>I am having problem with:</p>
<p>Improve collision detection – When the ball hits the paddle, use some simple physics to make the speed of the paddle affect the speed (and direction) of the ball.</p>
<p>What I&#8217;m trying to do is to make it so that:<br />
- Every time the ball hits the paddle it increases the speed a little.<br />
- The ball&#8217;s deflection angle determined by how far is the ball from the center of the paddle when it hits. </p>
<p>Can anyone help me on these?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: belbelts</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5241</link>
		<dc:creator>belbelts</dc:creator>
		<pubDate>Tue, 20 Apr 2010 00:41:10 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5241</guid>
		<description>what do I do? please comment</description>
		<content:encoded><![CDATA[<p>what do I do? please comment</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: belbelts</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5239</link>
		<dc:creator>belbelts</dc:creator>
		<pubDate>Mon, 19 Apr 2010 21:41:03 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5239</guid>
		<description>I think that this tutorial was very great. I&#039;m now trying to make a game because of this tutorial, but I have a problem. In my game I need a lot of walls, so I made an array inside the game loop that creates the walls. I then ran the app and after a few minutes the game started to slow down.</description>
		<content:encoded><![CDATA[<p>I think that this tutorial was very great. I&#8217;m now trying to make a game because of this tutorial, but I have a problem. In my game I need a lot of walls, so I made an array inside the game loop that creates the walls. I then ran the app and after a few minutes the game started to slow down.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edmond</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5198</link>
		<dc:creator>Edmond</dc:creator>
		<pubDate>Wed, 14 Apr 2010 19:32:10 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5198</guid>
		<description>Hi, i got an error &quot;Method definition not in @implementation context&quot;, and I&#039;m new to programming and i don&#039;t know what that means.   Also u spelled racquet_yellow and raquet_yellow is there a difference. I&#039;m not sure what i did wrong so i posted most of my coding from the &quot;iTennisViewController.m&quot;. Can you please help me out?

//
//  iTennisViewController.m
//  iTennis
//
//  Created by ed on 4/5/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import &quot;iTennisViewController.h&quot;

#define kScoreToWin 5
-(void) gameLoop{// Begin Scoring Game Logic}
if(ball.center.y = kScoreToWin)];
	}
}
	if(ball.center.y &gt; self.view.bounds.size.height) {
		computer_score_value++;
		[self reset:(player_score_value &gt;= kScoreToWin)];

#define kCompMoveSpeed 15
- (void) gameLoop{ // Begin Simple AI}
if(ball.center.y &lt;= self.view.center.y){
	if(ball.center.x  racquet_green.center.x){
		CGPoint compLocation = CGPointMake(racquet_green.center.x + kCompMoveSpeed, racquet_green.center.y);
		racquet_green.center = compLocation;
	}
}

#define kGameStateRunning 1
#define kGameStatePaused  2

#define kBallSpeedX 10
#define kBallSpeedY 15





@implementation iTennisViewController
@synthesize ball,raquet_yellow,raquet_green,player_score,computer_score,gameState,ballVelocity,tapToBegin;

-(void) gameLoop {
	if(gameState == kGameStateRunning) {
		
		ball.center = CGPointMake(ball.center.x + ballVelocity.x , ball.center.y +ballVelocity.y);
		
		if(ball.center.x &gt; self.view.bounds.size.width &#124;&#124; ball.center.x  self.view.bounds.size.height &#124;&#124; ball.center.y &lt;0){
			ballVelocity.y = -ballVelocity.y;
		}
	} else {
		if(tapToBegin.hidden){
			tapToBegin.hidden = NO;
		}
	}
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	if(gameState == kGameStatePaused) {
		tapToBegin.hidden = YES;
		gameState = kGameStateRunning;
	}
}

- (void)dealloc {
	[super dealloc];
	[ball release];
	[raquet_green release];
	[raquet_yellow release];
	[player_score release];
	[computer_score release];
	[tapToBegin release];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	if(gameState == kGameStatePaused) {
		tapToBegin.hidden = YES;
		gameState = kGameStateRunning;
	} else if(gameState == kGameStateRunning) {
		[self touchesMoved:touches withEvent:event];
	}
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [[event allTouches] anyObject];
	CGPoint location = [touch locationInView:touch.view];
	CGPoint xLocation = CGPointMake(location.x,raquet_yellow.center.y);
	racquet_yellow.center = xLocation;
}</description>
		<content:encoded><![CDATA[<p>Hi, i got an error &#8220;Method definition not in @implementation context&#8221;, and I&#8217;m new to programming and i don&#8217;t know what that means.   Also u spelled racquet_yellow and raquet_yellow is there a difference. I&#8217;m not sure what i did wrong so i posted most of my coding from the &#8220;iTennisViewController.m&#8221;. Can you please help me out?</p>
<p>//<br />
//  iTennisViewController.m<br />
//  iTennis<br />
//<br />
//  Created by ed on 4/5/10.<br />
//  Copyright __MyCompanyName__ 2010. All rights reserved.<br />
//</p>
<p>#import &#8220;iTennisViewController.h&#8221;</p>
<p>#define kScoreToWin 5<br />
-(void) gameLoop{// Begin Scoring Game Logic}<br />
if(ball.center.y = kScoreToWin)];<br />
	}<br />
}<br />
	if(ball.center.y &gt; self.view.bounds.size.height) {<br />
		computer_score_value++;<br />
		[self reset:(player_score_value &gt;= kScoreToWin)];</p>
<p>#define kCompMoveSpeed 15<br />
- (void) gameLoop{ // Begin Simple AI}<br />
if(ball.center.y &lt;= self.view.center.y){<br />
	if(ball.center.x  racquet_green.center.x){<br />
		CGPoint compLocation = CGPointMake(racquet_green.center.x + kCompMoveSpeed, racquet_green.center.y);<br />
		racquet_green.center = compLocation;<br />
	}<br />
}</p>
<p>#define kGameStateRunning 1<br />
#define kGameStatePaused  2</p>
<p>#define kBallSpeedX 10<br />
#define kBallSpeedY 15</p>
<p>@implementation iTennisViewController<br />
@synthesize ball,raquet_yellow,raquet_green,player_score,computer_score,gameState,ballVelocity,tapToBegin;</p>
<p>-(void) gameLoop {<br />
	if(gameState == kGameStateRunning) {</p>
<p>		ball.center = CGPointMake(ball.center.x + ballVelocity.x , ball.center.y +ballVelocity.y);</p>
<p>		if(ball.center.x &gt; self.view.bounds.size.width || ball.center.x  self.view.bounds.size.height || ball.center.y &lt;0){<br />
			ballVelocity.y = -ballVelocity.y;<br />
		}<br />
	} else {<br />
		if(tapToBegin.hidden){<br />
			tapToBegin.hidden = NO;<br />
		}<br />
	}<br />
}</p>
<p>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {<br />
	if(gameState == kGameStatePaused) {<br />
		tapToBegin.hidden = YES;<br />
		gameState = kGameStateRunning;<br />
	}<br />
}</p>
<p>- (void)dealloc {<br />
	[super dealloc];<br />
	[ball release];<br />
	[raquet_green release];<br />
	[raquet_yellow release];<br />
	[player_score release];<br />
	[computer_score release];<br />
	[tapToBegin release];<br />
}</p>
<p>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {<br />
	if(gameState == kGameStatePaused) {<br />
		tapToBegin.hidden = YES;<br />
		gameState = kGameStateRunning;<br />
	} else if(gameState == kGameStateRunning) {<br />
		[self touchesMoved:touches withEvent:event];<br />
	}<br />
}</p>
<p>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {<br />
	UITouch *touch = [[event allTouches] anyObject];<br />
	CGPoint location = [touch locationInView:touch.view];<br />
	CGPoint xLocation = CGPointMake(location.x,raquet_yellow.center.y);<br />
	racquet_yellow.center = xLocation;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arndt Bieberstein</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5196</link>
		<dc:creator>Arndt Bieberstein</dc:creator>
		<pubDate>Wed, 14 Apr 2010 16:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5196</guid>
		<description>I just found a Bug in my Code.

When you make the racquet too small the interaction method (CGRectInteractsRect...) never
gets an intersection between racquet and ball.

Buuuuut
Very very very nice tutorial :)</description>
		<content:encoded><![CDATA[<p>I just found a Bug in my Code.</p>
<p>When you make the racquet too small the interaction method (CGRectInteractsRect&#8230;) never<br />
gets an intersection between racquet and ball.</p>
<p>Buuuuut<br />
Very very very nice tutorial <img src='http://icodeblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafael</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-2/#comment-5101</link>
		<dc:creator>Rafael</dc:creator>
		<pubDate>Sun, 11 Apr 2010 18:37:19 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5101</guid>
		<description>Hello ZOT,

I had the same problem, so instead of using the &quot;self.view.center&quot; I used the actual values...

&lt;i&gt;ball.center = CGPointMake(160,230);&lt;/i&gt;

That way the ball is properly centered...

Best,
Rfl</description>
		<content:encoded><![CDATA[<p>Hello ZOT,</p>
<p>I had the same problem, so instead of using the &#8220;self.view.center&#8221; I used the actual values&#8230;</p>
<p><i>ball.center = CGPointMake(160,230);</i></p>
<p>That way the ball is properly centered&#8230;</p>
<p>Best,<br />
Rfl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5067</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Thu, 08 Apr 2010 18:22:12 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5067</guid>
		<description>Is it possible to create a link to tutorial part 1-4 so I can easily navigate thru this tutorial?</description>
		<content:encoded><![CDATA[<p>Is it possible to create a link to tutorial part 1-4 so I can easily navigate thru this tutorial?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5065</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Thu, 08 Apr 2010 17:52:58 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5065</guid>
		<description>Most games now have the ability to use tilt instead of touch screen. Is there an easy way to incorporate this so when I tilt my iPhone the paddles move?</description>
		<content:encoded><![CDATA[<p>Most games now have the ability to use tilt instead of touch screen. Is there an easy way to incorporate this so when I tilt my iPhone the paddles move?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wesley</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-2/#comment-5016</link>
		<dc:creator>Wesley</dc:creator>
		<pubDate>Sun, 04 Apr 2010 08:32:03 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5016</guid>
		<description>Well that code failed to display properly...

Anyway, the point was to say check if the gesture&#039;s y location is below or above the net, then move the according paddle.</description>
		<content:encoded><![CDATA[<p>Well that code failed to display properly&#8230;</p>
<p>Anyway, the point was to say check if the gesture&#8217;s y location is below or above the net, then move the according paddle.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wesley</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-2/#comment-5015</link>
		<dc:creator>Wesley</dc:creator>
		<pubDate>Sun, 04 Apr 2010 08:29:51 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5015</guid>
		<description>This answers seems to be a solution, but a players figner would have to be one the racquet view. Another solution allowing each user more freedom may be:
&lt;code&gt;
if (location.y  self.view.bounds.size.height / 2) {
	// move the image view
}
&lt;/code&gt;
Something like this may allow the yellow player to make gestures below the net, and the green player to make gestures above the net. Each gesture moving the paddle on the side of the net the gesture was made.

I have not tried this. I&#039;m busy looking for an answer to my won problem :-D</description>
		<content:encoded><![CDATA[<p>This answers seems to be a solution, but a players figner would have to be one the racquet view. Another solution allowing each user more freedom may be:<br />
<code><br />
if (location.y  self.view.bounds.size.height / 2) {<br />
	// move the image view<br />
}<br />
</code><br />
Something like this may allow the yellow player to make gestures below the net, and the green player to make gestures above the net. Each gesture moving the paddle on the side of the net the gesture was made.</p>
<p>I have not tried this. I&#8217;m busy looking for an answer to my won problem <img src='http://icodeblog.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J. Cohen</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-5005</link>
		<dc:creator>J. Cohen</dc:creator>
		<pubDate>Thu, 01 Apr 2010 20:56:40 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-5005</guid>
		<description>If the ball is 16x16 it won&#039;t work. It took me an hour to figure out why the ball kept falling through my paddle, and after trying about 40 things, it turned out that resizing the ball to 18x18 fixed it. Strange, because the .png image is 16x16 in size.

I wish I understood why. Strangest thing is it worked off the computer&#039;s paddle, but just went right through mine.</description>
		<content:encoded><![CDATA[<p>If the ball is 16&#215;16 it won&#8217;t work. It took me an hour to figure out why the ball kept falling through my paddle, and after trying about 40 things, it turned out that resizing the ball to 18&#215;18 fixed it. Strange, because the .png image is 16&#215;16 in size.</p>
<p>I wish I understood why. Strangest thing is it worked off the computer&#8217;s paddle, but just went right through mine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregory Ellis</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-2/#comment-4963</link>
		<dc:creator>Gregory Ellis</dc:creator>
		<pubDate>Wed, 24 Mar 2010 08:34:21 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-4963</guid>
		<description>use this in touches began and it should allow you to use both paddles by dragging them. I&#039;ve never tested it outside a simulator so not 100% sure how well it would work on an iphone

	 UITouch *touch = [[event allTouches] anyObject];
	 CGPoint location = [touch locationInView:self.view];
	 if ([touch view] == racquet_green) {
	 // move the image view
	 racquet_green.center = location;
	 }
	 if ([touch view] == racquet_yellow) {
	 // move the image view
	 
	 racquet_yellow.center = location;
	 }</description>
		<content:encoded><![CDATA[<p>use this in touches began and it should allow you to use both paddles by dragging them. I&#8217;ve never tested it outside a simulator so not 100% sure how well it would work on an iphone</p>
<p>	 UITouch *touch = [[event allTouches] anyObject];<br />
	 CGPoint location = [touch locationInView:self.view];<br />
	 if ([touch view] == racquet_green) {<br />
	 // move the image view<br />
	 racquet_green.center = location;<br />
	 }<br />
	 if ([touch view] == racquet_yellow) {<br />
	 // move the image view</p>
<p>	 racquet_yellow.center = location;<br />
	 }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iPhone Dev.</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-4922</link>
		<dc:creator>iPhone Dev.</dc:creator>
		<pubDate>Wed, 17 Mar 2010 18:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-4922</guid>
		<description>Same problem again!</description>
		<content:encoded><![CDATA[<p>Same problem again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iPhone Dev.</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-4921</link>
		<dc:creator>iPhone Dev.</dc:creator>
		<pubDate>Wed, 17 Mar 2010 18:48:39 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-4921</guid>
		<description>// Begin Simple AI
if(ball.center.y &lt;= self.view.center.y) {
	if(ball.center.x &lt; racquet_green.center.x) {
		CGPoint compLocation = CGPointMake(racquet_green.center.x - kCompMoveSpeed, racquet_green.center.y):
		racquet_green.center = compLocation;
	}</description>
		<content:encoded><![CDATA[<p>// Begin Simple AI<br />
if(ball.center.y &lt;= self.view.center.y) {<br />
	if(ball.center.x &lt; racquet_green.center.x) {<br />
		CGPoint compLocation = CGPointMake(racquet_green.center.x &#8211; kCompMoveSpeed, racquet_green.center.y):<br />
		racquet_green.center = compLocation;<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shubhojit</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-4898</link>
		<dc:creator>Shubhojit</dc:creator>
		<pubDate>Sun, 14 Mar 2010 06:09:24 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-4898</guid>
		<description>I believe by now you would have sorted the mystery

but still 

you need to put the 

//Begin Simple AI 
if stmt inside the -(void) gameLoop {  }
method

then its all good</description>
		<content:encoded><![CDATA[<p>I believe by now you would have sorted the mystery</p>
<p>but still </p>
<p>you need to put the </p>
<p>//Begin Simple AI<br />
if stmt inside the -(void) gameLoop {  }<br />
method</p>
<p>then its all good</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shubhojit</title>
		<link>http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/comment-page-3/#comment-4886</link>
		<dc:creator>Shubhojit</dc:creator>
		<pubDate>Sat, 13 Mar 2010 03:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://icodeblog.com/?p=656#comment-4886</guid>
		<description>Hi! i am also getting the error


Xcode says: error: expected identifier or ‘(‘ before ‘if’ in: ViewController.m

// Begin Simple AI

if(ball.center.y &lt;= self.view.center.y) {

What&#039;s wrong?

plz reply</description>
		<content:encoded><![CDATA[<p>Hi! i am also getting the error</p>
<p>Xcode says: error: expected identifier or ‘(‘ before ‘if’ in: ViewController.m</p>
<p>// Begin Simple AI</p>
<p>if(ball.center.y &lt;= self.view.center.y) {</p>
<p>What&#039;s wrong?</p>
<p>plz reply</p>
]]></content:encoded>
	</item>
</channel>
</rss>
