• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
  • comments
  • views

Station 6 + Box2D physics

Sign in to follow this  
Followers 0


Welcome back!

In this week's post I'll be talking about the Box2D physics engine, why I've used it and how I've used it. I'm not going to go into the specifics of how to set it up and use it, though. This isn't a tutorial. For that I recommend you check out the Box2D manual.

So the game is about rewiring things. You run up to an object, pick up a cable, run up to something else, plug in the cable, and then hopefully something exciting will happen. One small but important feature is that the cable you pick up should snake behind you over the floor and on top of obstacles as you carry it around. It's something that will (hopefully) give the wiring-while-platforming experience a little bit more substance.

Initially, I used this algorithm to model the wires. It seemed to work quite well, until I got to the 'snake on top of obstacles' bit, and started to scratch my head as to how it could be achieved. Then I thought "I know! I'll be lazy and use a physics engine to take care of it for me!"

Soon afterward, but before I actually got started with including a physics engine, I played the game LIMBO. It's a fantastic game by the way, I highly recommend it. The realistic physics it has really enhances the puzzles and I think it made the game much more enjoyable than it would have been if it hadn't used some sort of physics engine. It inspired me to try and implement physics in not just the wires, but in the entire world as well. It uses Box2D. I read about Box2D a little bit and it seemed quite good, so I decided to go ahead with it.

I had to think about how on earth I was going to overhaul the entire engine to make it work with Box2D. It seemed like a bit of a mammoth task initially. But wait! I thought of the perfect solution. Why don't I use my existing component based entity system? I could make a specific physics component that, when attached to an entity, would simulate physics on it using Box2D. And that's exactly what I did. The component system made implementing Box2D extremely easy.

Here's the (slightly reduced) class declaration for my physics component:

class Physics : public Component {
static std::vector instances;
static b2World * world_; // The Box2D physics world that simulates physics

entityComponentTypeEnum type() {
return PHYSICS;

b2Body * body; // The physics body that is simulated in Box2D
// Constructor for polygon shaped physics bodies
Physics(iVec2 position, unsigned vertexCount, iVec2 * vertices, b2BodyType bodyType = b2_dynamicBody,
float density = 1.0f, float friction = 0.0f);

// Constructor that generates a rectangle shape physics body based on the sprite passed to it
Physics(iVec2 position, SuperMaximo::Sprite * sprite, b2BodyType bodyType = b2_dynamicBody, float density = 1.0f,
float friction = 0.0f);

// Constructor that generates a circular physics body
Physics(iVec2 position, float radius, b2BodyType bodyType = b2_dynamicBody, float density = 1.0f, float friction = 0.0f);

// Updates the Box2D physics world, and then moves all of the relevant entities accordingly
static void update();

// Functions for dealing with Box2D initialisation and finalisation
static void init();
static void free();

static b2World & world(); // In case other classes need to access the physics world

// Game measurements and coordinates need to be converted to ones that work well with Box2D (SI units, i.e. metres, kilograms, etc.)
static float toWorldScale(float number);
static float toBox2dScale(float number);
// And other scale conversion functions for different types...

I'll be adding more constructors and functions for more complex systems as and when I need them, for instance if I need to attach two physics components together with a joint.

For the floors, I simply needed to change my Flash level exporter so that it exports the four corners of each floor block, which is then loaded into the game so that floor polygons can be created and put into the Box2D world. It works perfectly with various floor shapes, not just rectangles, but I still need to work out a good method of drawing out these shapes in Flash to be exported.

I've also rigged up the player to use physics. Player movement definitely isn't perfect at the moment, but it's getting there.

As for the wires, I've made it so that they are made up of many small physics bodies joined together. It works brilliantly! They're basically the same as the chain example in the Box2D Testbed program. Here's a video of said program (not by me). Skip to 4:15:

That's all for this week, thank you for reading! We'd really like to hear your comments, so please feel free to use the comment box below or send me a message.

See you next week!

Sign in to follow this  
Followers 0


There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now