Make Your Own iPhone Game: Days 4 & 5


Day 5. 0:15. He floats as graceful as Tinkerbell in the night.

Conan. He doesn’t cry. He doesn’t even walk. He just floats everywhere but on top of rocks. Here’s a little bit of the code to implement the joystick-style movement pad:

if( isMovingJoybtn && joybtnDist > kMovementThreshold )
{
	CGPoint p = [joybtn position];
	CGPoint move = ccp(0,0);
	CGFloat speed = (500.0f * (joybtnDist / kMaxJoybtnDist));
	CGFloat step = delta * speed;
	NSLog(@"Delta=%.2f, speed=%.2f, step=%.2f",delta,speed,step);

	// test movement thresholds
	if( p.x < joypad.position.x )
		move.x -= step;
	else if( p.x > joypad.position.x )
		move.x += step;
	if( p.y < joypad.position.y )
		move.y -= step;
	else if( p.y > joypad.position.y )
		move.y += step;

	// move the player
	if(![self movePlayerBy:move])
	{
		if(![self movePlayerBy:ccp(move.x, 0)])
		{
			[self movePlayerBy:ccp(0, move.y)];
		}
	}
}


Day 4. 0:46. Conan remembers to walk.. Though he gets a bit dizzy when the world starts to shake.

Leave a Reply

Spam protection by WP Captcha-Free

Storyteller   .:.   Musician   .:.   Vagabond   .:.   Wizard