Shaking it up – Making your game’s screen shake

Hi everyone,

In this tutorial, I will be showing you my method for making a shaking screen effect in Cocod2D. This is a good effect to add some overall “feeling” to your game. It is like the vibration feature of an xbox controller. It’s not really needed, but adds ambience and “juice” to your games. It immerses the player more deeply into the game.

Here is how I go about doing it. All of the code should be written to affect a CCLayer, in my case, it is called GameWorld.h/.m

In your .h file, you will create three new variables:

@interface GameWorld : CCLayerColor {
BOOL shouldBeShaking;
int shakeLength;
int shakeIntensity;
}

shouldBeShaking is a boolean value that will let us know whether or not to shake the screen.
shakeLength and shakeIntensity will affect how long to shake the screen for and hard to shake the screen.

Now, in your .m file, schedule an update method like so (inside your init method!)

[self scheduleUpdate];

Next, setup that update method somewhere in your code

- (void)update:(ccTime)dt {

}

Before we go on, let me explain how this is going to work. Every frame, we will be checking whether or not shouldBeShaking is true. If it is true, then we will:

  1. offset the layer by some random amount
  2. decrement the shakeTime variable by one
  3. check if shakeTime is 0
  4. if it is, then set shouldBeShaking to false

Now, in code this looks like:

if (shouldBeShaking) {
float x = (arc4random() % shakeIntensity) - 0.5f; //Generate a random x coordinate
float y = (arc4random() % shakeIntensity) - 0.5f; //Do the same for the y coordinate
self.position = ccp(x,y); //Offset the layer's position by x and y
shakeLength--; //Subtract one from the length
if (shakeLength <= 0) { //Have we reached the end?
self.position = ccp(0,0); //Set us back to align with the screen
shouldBeShaking = NO; //Stop shaking
shakeLength = 0; //Reset shakeLength
shakeIntensity = 0; //Reset shakeIntensity
}
}

From there, you just need to set shouldBeShaking to true, set a length, and set an intensity, and your screen will be shaking accordingly.

I usually wrap those three steps up in a helper method to make things more organized.

Hope this tutorial helped someone.

Bit Fighter

Bit Fighter is coming along nicely:

This is what the main menu looks like so far! I’ll continue posting updates as time goes on.

App Update

Hi everyone,

In an attempt to keep this thing alive, I am going to talk about what’s going on with my apps.

Doodle OMG has been completely rewritten. It now contains no lag (or at least very small amounts), offline storage of scores and achievements for later use, and a faster, smoother user interface. Along with this, the file size of the app is greatly reduced. It is now a mere four megabytes. It used to be around 20mb I think. General enhancements have also been implemented, most of them taking advantage of new iOS 5 features. The game will still function properly even if you don’t have iOS 5.  Doodle OMG is currently being tested for bugs but will most likely be released soon.

The future:  In the next update, you will probably see multiplayer over Bluetooth and wifi (game center), as well as optional statistics data logging that will allow us to view the gameplay of players. It will let us know if most of the deaths caused were from ninja stars or that everybody dies at stage three. These statistics will help us make the game harder or easier where it needs to be, eventually (hopefully) leading to a more fair yet challenging game. Completely offline leader boards will also hopefully get implemented by then too.

The Present: 20 promo codes will be given out one of these days, so check back frequently to get a free copy of Doodle OMG.

Bit Fighter is a new, upcoming game that we have been working on. In this game, you are a pixelated little plane that must survive increasingly difficult waves of other pixelated planes, ships, bosses, and other enemies. You will be able to pick up power ups dropped from destroyed enemies as well as purchase “gadgets” that will greatly increase your chances of survival. These gadgets will be purchased with an in-game currency acquired by playing the game. There is a chance that you will be able to purchase more of this in-game currency through in-app purchases, but I am not a big fan of those, so we will see. Bit Fighter will of course feature game center managed leader boards and achievements. Due to Bit Fighter’s superior complexity to Doodle OMG, far more achievements can be implemented which will hopefully lead to more motivating gameplay. The aspect that I am most excited about though is multiplayer. We have planned to implement head to head multiplayer matches in which two or more players go head to head in a dogfight to the death! We also plan to include a multiplayer survival match where you work to keep not only yourself, but also your partner(s) alive by reviving them with your points received from blowing things up. Multiplayer will hopefully be available on Bluetooth as well as wifi (game center).

The Future: It is unknown when exactly Bit Fighter will be released, but it is hoped to be finished by the end of the summer. It will be free for the first 24 hours, and after that, it will cost $0.99. Promo codes will most likely be given out early to reviewers.

The Present: Bit Fighter is in pretty early stages of development and I will probably post updates on it, along with development tips that I have discovered along the way.

RPG/Adventure Game is something that I just randomly thought of while I probably should have been sleeping. That’s not the real name, but I don’t actually have a real name thought of yet, so that is what it shall be called until then. It is going to be a Zelda-esque RPG in which you (the character) wander around a massive world looting dungeons, caves, and castles, fulfilling quests, and defeating mighty monsters. (or burning down the local villages).  And when I say a “massive world”, I mean massive. I plan to make the maps completely procedural and nearly infinite so it will take a while to become boring.  Everything from the biomes to the locations of castles and caves will be randomly generated which will give players a new adventure every time they start a new game. A dynamic and random quest system will also be implemented.

I have no idea if this thing is going to get completed and become an actual game on the app store, but if it did, that would be awesome. I would also like your input on this game as well.

Anyways, there you go. Updates on all my games. I hope I can keep this blog going even longer 😛 Also, check out Apples-Genius as well as King Caesar Games.

AllTheWay Apps.

Programming Experience and Minecraft.

We all know and love Minecraft.  From it’s randomly generated worlds, to sandbox style gameplay, there is so much that you can do.  Now, what if I told you that it could help you become a better programmer.

Yes, I know, mind blown.  But really, modding Minecraft is a great way to become better at programming.  It lets you add things to an already built game, eliminating the need to write boilerplate code (love it already).  Minecraft is written in Java, which has a similar syntax to C/C++.

I have been messing around in the Minecraft source code (from MCP) for a little bit now, and it has taught me and clarified many things.  Know that I started modding the game with very minimal Java knowledge and experience. It definitely takes some getting used to, but is really simple once you get the hang of it.

I highly suggest you give this a try, both for fun and for experience.

Networking Engine

Yesterday I made a good amount of progress on the networking engine, as well as the server software.  Here’s a little snapshot of the server code:

Now, a word about how multiplayer is going to work: There is going to be the simple software that you will have to download, which is the server.  Much like Minecraft, you will be able to host your own servers!  Multiplayer will also be intertwined with Apple’s GameCenter!

In other words, I’ll be posting a tutorial on how to make a simple server in python later. It will show how I am making my server (but simpler of course!)

Thats all for now, thanks, and I’ll see you all tomorrow!

Getting up to speed

I decided to kick this blog off by showing everyone where I am in the development stage of the mining/building game I am making. I have to warn you though, the games currently not pretty. I have a ton of work to do still, so don’t judge it too much as of now. So far, I have a nice little tile based map that randomly generates every time. I also took a stab at procedural trees to populate the landscape. (They need a lot of work 😉 ). Finally, began the development of the player, which is coming along nicely. Heres a current screenshot zoomed out to about 60%.

Now, the graphics you see here aren’t going to be in the actual game, I simply made those in about two minutes for the purpose of testing. Next, here is a picture of the current map zoomed out to 10%.

Some things that need to be changed, based off of this picture,

– less dense rock layer

– BIGGER WORLD!

– Less derpy trees

-Etc, etc, etc…

Hope that got you all up to speed! I’ll see ya tomorrow. Feel free to leave any comments, suggestions, etc, below!

-Tate