# Game Design

I’ve learned something about game design recently: plan out what you want to do ahead of time.  I decided to make what started out as a simple game: a ball rolling around. You control it with the accelerometer, and have to dodge various obstacles to make it to a designated area. Easy, right? I thought that I could just use cocos2d, and wouldn’t have to use a physics engine. As I added more and more features, though, my focus shifted from using cocos2d to using a physics engine. Now I have to make many more decisions, like what physics engine I am going to use, and how I can use it with cocos2d. When I make another game, I’ll be sure to plan out most of what I want ahead of time. I say most, because there’s always things to add or take out when you are in the middle of developing the game.

# Collision Detection

As I’m learning more and more about cocos2d, I’m realizing that there are a lot of different things that should be simple, but there are many ways to do. One of these is collision detection. There are many ways to perform this, and I’ll list some of the most common.

This type of collision checking works best if both images are circles or at least circular. It works by checking the radius around the images. If the actual distance between them is less than the allowed distance, the collision is triggered.

My check for collision method:

```
-(void) checkForCollision{

float playerImageSize = [player texture].contentSize.width;

float ballImageSize = [ball texture].contentSize.width;

float playerCollisionRadius = playerImageSize * 0.4f;

float ballCollisionRadius = ballImageSize * 0.4f;

float actualDistance = ccpDistance(player.position, ball.position);

if (actualDistance < maxCollisionDistance) {

[self triggerCollision];

}

}

```

Rectangle Collision checking

This kind of collision checking is very simple and works best if the images are rectangular. It works by defining a rectangle around the images going to collide. If the rectangles intersect, the collision is triggered.

My rectangular collision method:

```
-(void) checkForCollision{

CGRect playerRect = [player boundingBox];

CGRect ballRect = [ball boundingBox];

if (CGRectIntersectsRect(playerRect, ballRect)) {

[self triggerCollision];

}

```

While there are a lot more different collision detection methods, these are the most common, short of using a physics engine.

# The beginning

I just recently began learning cocos2d-iphone, and making iphone games. I have no programming experience, so I’ll just update this blog with some stuff related to my experience going through this.