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.

Advertisements

Kobold2D

I just recently came across kobold2d and have been using it instead of cocos2d. It has ARC enabled, without having to do anything, and has third-party libraries ready to use. One of the best features, though is that it has a class to handle all the input in your game, such as touches, pinches, and swipes, without having to use long methods.  One interesting thing about it is that it actually uses lua. It isn’t written in lua, but it has a config file where a bunch of settings, such as iad display and the first scene to run can be easily edited. You can also add your own properties, and add them into your game via a method. This can be useful for editing different game properties, without having to go through source code. Overall, I gladly prefer it to cocos2d. The only thing I don’t like about it is that it uses the workspace feature, but I can get used to that

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.

Radial Collision Checking

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 maxCollisionDistance = ballCollisionRadius + playerCollisionRadius;

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.