Bag It!

Bag It! is a light and fun mobile game that puts your grocery bagging skills to the test!

Bag It Promo Art

It may seem easy to bag your groceries, but there’s more to it than meets the eye. Avoid crushing fragile items, group related groceries for bonus points, complete challenges, and manage the personalities of an array of temperamental groceries. Become the ultimate grocery bagger through six modes of play and 100+ levels!

Bag It! is available on the Apple App Store, Google Play.

Development

Bag It! was the first commercial game I contributed to, so it holds a special place in my heart. Though I was originally hired at Hidden Variable as an intern, I acted as the de facto lead programmer on this project, handling code architecture and programming for the majority of the game. By the time we hired a second programmer, we were about to ship!

The game was built in Unity, and development took place from about February to November of 2011. We then continued to support the game with updates through 2012. I worked with one designer and one artist to implement the game from start to finish.

I coded many systems for this game: gameplay logic, touch input, progression and level unlock logic, audio playback, UI elements, menu flow, and an achievement system, to name a few. Below, I’ll highlight a few particularly interesting systems I worked on.

Gameplay Screenshot As you play Bag It!, your goal is to maneuver a variety of groceries in a tight space without breaking anything. It was very important to get the input and placement of groceries correct, or else the game was liable to be more frustrating than fun.

Since this is a mobile game, touch inputs are used. When you drag a grocery, it’s “picked up” and should follow your finger until you drop it. It was quite tricky to get the dragged grocery to behave as the player expected when dragging their finger. With all the various grocery sizes and orientations, it was easy for the dragged grocery to get stuck or end up in an unexpected location.

After trying several iterations, the solution I found was this:

  1. Treat the grocery bag as a grid of squares. Based on a grocery’s position and orientation, it always takes up a set number of squares.

  2. Every frame, re-evaluate what squares were occupied and by who.

  3. When dragging a grocery, iterate the grid and find the nearest location to the touch that had enough space to hold the current grocery. If there’s a clear path to this spot, smoothly move over a couple frames. If the path is blocked, teleport instantaneously.

This approach worked well in playtesting, and players felt that they could execute their moves with a lot of precision.

Grocery Weight

One of the main challenges in the game is to move groceries into the bag without breaking anything. Consider the classic real-world example: you put your eggs in the bottom of the bag, and heavier things crush them (poor things).

In Bag It!, each grocery has a weight as well as a weight limit. You want to avoid putting too many objects on top of fragile items like eggs, bread, or cereal!

The grid structure described above helped with the weight system. If a grocery comes to rest, and there are one or more groceries beneath it, its weight is evenly distributed between all groceries below. This is even recursive, with the item on the bottom of the bag absorbing the weight of all items above.

Grocery Groups

To spice up gameplay, we decided to add the idea that grouping related groceries would give you a score bonus. For example, putting milk, cereal, eggs, and OJ near one another would give a “balanced breakfast” score bump.

The systems and data structures used for grocery navigation and grocery weight actually came in handy here. Because we had a grid of occupied cells in the bag, I was able to generate a graph from the groceries in the bag at any one time. From there, a breadth first search could be done, starting at any grocery, to see if a grocery group was detected.

Build System

Beyond programming the game itself, building and distributing the game for playtests was another challenge. I was responsible for getting Hidden Variable’s build and deployment infrastructure up and running in an early state.

I developed a Unity build system that allowed us to build 10+ separate SKUs across iOS, Android, Windows, and macOS from a single codebase.

Each SKU was configurable with a wide variety of options. The most basic one was build platform, but arbitrary ones could be added. For example, we experimented with many mobile game economy paradigms at this time (premium, iPad-only “HD” SKUs, free trial versions, full “free-to-play” versions, China-specific versions, etc), and the build system allowed us to support all of them.

This was also my first foray into CD/CI. We used Jenkins to create builds, and a combination of Google Drive and HockeyApp to distribute builds. This allowed builds to be created automatically without my intervention, which allowed me to focus on other things.

Plugins and SDKs

This game was also my first taste of integrating A LOT of different SDKs as Unity plugins. By the end of this project, I was pretty adept at it. A few we used across many SKUs:

  • GameCenter Achievements and Leaderboards
  • Facebook Login and Leaderboards
  • Apple and Google In-App Purchases
  • Flurry Analytics and Game Analytics
  • Chartboost

Conclusion

Bag It! was a critical and commercial success, which helped Hidden Variable keep the lights on in the early days and provided me with a lot of positive reinforcement and motivation.

It was a great first game to work on. The work required matched my entry skill level nicely. The game was excellent initial exposure (and “trial by fire”) in commercial game development.

Not only did I gain a ton of experience in gameplay programming and Unity development, I also learned a lot about build systems, integrating SDKs as Unity plugins, and various mobile game business models.