Fork me on GitHub

Tagged: gaming RSS

  • britg 9:27 am on January 7, 2012 Permalink | Log in to leave a Comment
    Tags: , , gaming, mongodb, postgres   

    Forging Forgecraft: A Hybrid SQL MongoDB Data Solution 

    Forgecraft is a game currently in development using Ruby on Rails, Backbone.js, and all sorts of HTML5 buzzwords. Read an introduction here, and play the demo here.

    One of my primary goals while building Forgecraft is to learn as many new technologies as possible. I’ve learned the hard way that it’s better to leave this kind of exploration in your hobby projects and out of your production “for real” stuff. And, seeing as how there are so many emergent technologies right now in web development there’s a lot to explore!

    Whole Hog is Too Much Hog

    MongoDB has quite a bit of steam behind it in the Rails/Ruby community (and plenty of other places too), and with projects like Mongoid and MongoMapper (I went with Mongoid) it’s an easy drop-in replacement for Active Record that maintains all those ORM conventions you know and love. I decided against the replacement approach for one primary reason: I wanted to use existing, robust, and actively developed libraries that rely on Active Record.

    Example: There’s no reason to roll your own authentication/user system when there are insanely popular and feature-full libraries already in place for them like Devise and authlogic (I went with Devise).

    Fortunately combining Active Record with Mongoid and getting the best of both worlds proved to be easy and painless.

    The Set Up

    The instructions for Mongoid include a step to remove the Active Record libraries from being loaded and delete your database.yml. Simply skip that step and both systems will run in conjunction.

    One small operational change you’ll have to make during development is explicitly defining when your rails generators should use Active Record. If you want to make an AR-driven model, your generators will look like:

    rails g active_record:model Player … produces a model the extends from ActiveRecord::Base.

    And by default, the data generators will use Mongoid:

    rails g model Skill … produces a model that includes Mongoid::Document.

    The Implementation

    Here’s how this combo system really shines in my opinion: get all the great features of gems built on AR with all the schema less features of Mongo. I’ll walk through an example:

    In Forgecraft, the authenticating object is the Player and players have many Skills which, right now, are Accuracy, Craftsmanship, and Perception. But, the skill list will likely grow and change over time as the game evolves. A typical AR/SQL based approach would be to create a skills table and a join table between players and skills resulting in a complex multi-table query to get a player’s complete skills.

    It’s clear here that the Player and Skills would fit well together as a single document in Mongo, queried all at once in one tidy object. But, since the Player is also our authentication model, using Mongo would prevent us from using Devise to handle all of that boring and complex auth stuff for us.

    Enter Hybridization. Forgecraft’s implementation uses the typical Devise set up around the Player object (again all on top of AR). All of a player’s skills go into a single document with a reference to the player, like so:


    class Skill
      include Mongoid::Document
      field :player_id, :type => Integer
    
      field :accuracy, :type => Integer, :default => 0
      field :craftsmanship, :type => Integer, :default => 0
      field :perception, :type => Integer, :default => 0
    
      index :player_id, :unique => true
    
      def player
        Player.find_by_id(player_id)
      end
    end

    To set up the relationships like one would expect with Active Record is a simple method on your Player object:


    class Player < ActiveRecord::Base
    
      # ...
    
      def skills
        @skills ||= (Skill.where(:player_id => self.id).first || \
                     Skill.create(:player_id => self.id))
      end
    
    end

    Bam! Now we can retrieve our skills as a single document (fast), and add new skills with ease (easy). Since Mongo is schema less, you could even have a different set of skills per player. Again, all of this is achievable through SQL — it’s been done for decades — but it just makes more conceptual sense to treat these as a single document.

    Querying and working with these objects and their relationships looks and feels just like active record:

    player.skills
    player.skills.accuracy
    player.skills.update_attributes(:accuracy => 5)
    player.skills.inc(:accuracy, 1)

    Benefits Outweight the Consequences

    I know, I know — any time you introduce an additional system, especially a datastore, you introduce a lot of complexity, failure modes, testing, etc. But, I honestly think the benefits are worth this extra complexity. Speed, ease of development, and the potential for less schema-driven growth make this an ideal environment for me. I highly recommend it, and will be using it in the future!


    More Forging Forgecraft:

     
    • Paweł Neubauer 12:47 pm on May 4, 2012 Permalink

      Thank you very much for this post :)

    • intelekshual 1:58 pm on May 23, 2012 Permalink

      FYI, Devise supports both ActiveRecord and Mongoid out-of-the-box. You could have chosen either, instead of both.

    • David Lowenfels 5:56 pm on January 9, 2013 Permalink

      I’m confused, so where/how does your application still use SQL?

    • james 10:33 am on November 23, 2013 Permalink

      great post. How did you handle N+1 queries between activerecord and mongoid. When you are
      loading the Player, how do you include the associated skills.

  • britg 6:50 pm on December 29, 2011 Permalink | Log in to leave a Comment
    Tags: coffeescript, , , gaming, html5,   

    Forging Forgecraft Part 1: Introduction 

    For the past few months I’ve been hacking away at a game partly, well, to make a game, and partly to play with a bunch of web technologies I’ve been interested in. That game is Forgecraft! Check it out and tell me what you think.

    What is Forgecraft?

    If you’ve played bejeweled you’ve got an idea of the primary game mechanic: move gems into patterns. If you’ve played Minecraft you’ve got an idea of the gameplay twist: patterns. You’re not just matching 3, but moving ores into patterns that resemble weapons and armor. And finally, if you’ve played any loot-based game ever you’ve got an idea of reward structure: loot!

    The target player is the casual player, but the game may also appeal to people who just like loot. And the target platforms are any modern web browser. Right now things are working ok in Chrome, Firefox, and Safari. Oh, and the game plays well as an installable web app on the iPad. In fact, all of the design decisions were made with this play mode in mind. Go ahead and save-to-homescreen on your iPad!

    Warning: It’s rough around the edges. There’s no tutorial and there may be bugs/features just flat out missing. I consider the game’s state as ‘playable demo.’ But do let me know if you run into any bugs.

    The Tech

    Over the next few months I hope to put together a series of posts on the different technologies I played with while making Forgecraft. You know, go in-depth on each of them and all that jazz. For now, here’s just a run-down of the fun stuff I used:

    Back End

    Front End

    HTML5 Buzzwords

    • CSS3 Animations
    • Web Audio API
    • History API / Pushstate API
    • iOS web-app installable

    My plan is to continue developing Forgecraft, expanding the items, mines, etc. and digging further into these emergent HTML5 technologies. I also would like to continue improving performance across the board. Things can get pretty choppy on the iPad when there are a lot of animations running at the same time.

    Please, give Forgecraft a try and let me know how you like it and if you have any suggestions. The number one question I have is, is it fun? A game should be fun, I’m told.


    More Forging Forgecraft:

     
  • britg 9:39 am on October 29, 2011 Permalink | Log in to leave a Comment
    Tags: gaming   

    IGF Pirate Kart Pack 1 

    If you’re unfamiliar with the IGF Pirate kart, it’s a neat collection of over 300 indie video games:

    a FREE and LEGAL compilation of over 300 games by over 100 developers! It was put together at the last minute for entry into the 2012 Independent Games Festival Main Competition.

    I’ll be honest, it’s pretty dense and the fun-to-meh ratio is pretty low, haha. But, there are a few games I’ve stumbled upon in there that have neat concepts or neat execution. Here’s a package of 4 that I thought were playable at least. Grab the full torrent if you want to check them all out, otherwise grab this pack:

    IGF Pirate Kart Pack 1

    Perhaps my favorite of the bunch is “A Friendship in 4 Colours” by Damian Sommer. I may try to cull a few more gems out of the pack if I can find the time. Enjoy!

     
  • britg 8:00 pm on August 30, 2011 Permalink | Log in to leave a Comment
    Tags: , gaming, , math   

    Linear Algebra, I am in You 

    Speaking of coordinate systems, the following 3 part primer from the Wolfire Dev Team is an excellent refresher on linear algebra. I studied this in school, but having been out of the engineering game for a while I find my “bow staff skillz” are shamefully rusty.

    Fortunately, Cocos2d takes care of a lot of this for you with their CGPoint Extensions. But, it’s still good to understand the basics.

     
  • britg 6:13 pm on August 29, 2011 Permalink | Log in to leave a Comment
    Tags: , gaming,   

    Working with the Myriad Coordinate Systems Available in Cocos2d 

    Lately, I find myself spending more of my free time working on a little game using Cocos2d. One of the things I was surprised to discover is that there’s not just a single coordinate system — there are four (that I know of — please correct me if I’m wrong).

    The four I know of:

    • Core Graphics space
    • Open GL space
    • Node space
    • Node space relative to anchor point

    I wasn’t totally clear on these going in, and I regret it. I ended up writing a lot of code that mish-mashed these and had to refactor it all.

    Most likely you’re going to be processing a touch input on an iOS device and translating that to a coordinate system inside of a Cocos2d node (most likely a CCLayer) as such:


    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView: [touch view]];
    CGPoint glPoint = [[CCDirector sharedDirector] convertToGL:point];
    CGPoint nodePoint = [self convertTouchToNodeSpace:touch];
    CGPoint nodePointAR = [self convertTouchToNodeSpaceAR:touch];

    With that in mind, here’s how I understand them:

    Core Graphics (point) — This is what you normally work in if you’re accustomed to iOS development with UIKit and similar APIs. CGPoint(0, 0) is in the top left corner of the screen and ascending Y values go down towards the bottom of the screen.

    Open GL (glPoint) — This coordinate system has (0, 0) in the bottom left of the screen, and ascending Y values go up towards the top of the screen.

    Node space (nodePoint) — This space is relative to the origin of the reference node with which you are observing the point, and follows the same rules as the Open GL system. If your node is full-screen and unshifted (e.g. a default CCLayer), this coordinate system is exactly the same as the Open GL system.

    Node space relative to anchor point (nodePointAR) — In Cocos2d, the default anchor point of any node is its center point. This coordinate system is relative to that center point. If you redefine the anchor point, this system is adjusted.

    The big gotcha that I ran into was that I was doing something frowned upon in Cocos2d: shifting Layers! I was then using the Node space throughout my code but expecting points to resolve to Open GL space. So, word to wise: understand these coordinate systems going in, and don’t shift the position of your Layers!

     
    • Web design London 7:42 pm on December 29, 2011 Permalink

      Cocos2D has an inverted coordinate system to what you’re used to – the … Now before we can see this running, we first need to tell Cocos2D to run our …..the entire game scene, more information is available in this thread.

    • Lulubysg 9:05 am on March 1, 2012 Permalink

       Many thanks regarding an additional helpful site.

    • Anonymous 9:06 am on March 1, 2012 Permalink

       Its like you examine my thoughts! You appear to understand so a lot about this, like you wrote the book in it or anything.

  • britg 9:14 am on May 22, 2011 Permalink | Log in to leave a Comment
    Tags: gaming   

    Minecraft 

    So much has been written about Minecraft that anything I say is just superfluous, but I will recount a chat with a friend.

    Magrath: man, Minecraft

    Magrath: so nice and relaxing

    Magrath: just put a game or some music on in the background and I can play for hours

    Yeah, that about sums it up. There’s so much value in being able to enter that ‘zone’ that I’d gladly pay a monthly fee for it. Fortunately, we don’t have to.

    Oh, and if you find yourself liking Minecraft definitely follow its creator, @notch, on Twitter. You’ll get the inside perspective on development (like this tweet about the upcoming sky dimension) as well as the random thoughts of a humble and passionate gamer.


    Some pics of the sky dimension thing I was working on last night: http://imgur.com/a/cvsYWless than a minute ago via web

     
    • website coder 7:25 am on May 23, 2011 Permalink

       I will also twitt this information.. Very entertaining this game.. 

    • website coder 7:25 am on May 23, 2011 Permalink

       I will also twitt this information.. Very entertaining this game.. 

  • britg 10:15 am on September 9, 2008 Permalink | Log in to leave a Comment
    Tags: , gaming, spore   

    Revolt Against Spore’s DRM On Amazon – I Love It! 

    Right now there is a revolt going on in the gaming world.  Literally thousands of people have given Spore a 1 star rating on Amazon because of the DRM it carries.  I love it!  

    But, I also hate it.  Spore is the type of game the industry needs – innovative, fresh, and well polished.  It’s a damn shame that publishers care more about pirating software than the fidelity of the gaming experience.

    I hope this revolt affects EA’s bottom dollar so much that they realize that pissing off your customers with computer-destroying DRM is much, much more damaging than underground software pirating.  I personally will never install this game on my computer – I can’t stand hidden processes, can’t stand spyware, and can’t stand the audacity of some publisher who thinks they can get away with this trash on my computer.

    Sorry to all the people who poured their creative effort into what appears to be an amazing game.

     
    • gishdog 1:10 pm on September 9, 2008 Permalink

      Well… I'm such a Will Wright fanboy that I went ahead and purchased (rented…) Spore. I'll let you know if it's worth the bullshit DRM or not. My bet is that the game doesn't deliver on it's potential… but we'll see.

    • gishdog 1:10 pm on September 9, 2008 Permalink

      Well… I'm such a Will Wright fanboy that I went ahead and purchased (rented…) Spore. I'll let you know if it's worth the bullshit DRM or not. My bet is that the game doesn't deliver on it's potential… but we'll see.

    • MattB 5:26 pm on September 10, 2008 Permalink

      I really wanted to buy this game when walking through Best Buy yesterday. I am very lucky I read this before I bought. It drives me crazy that an otherwise quality game would be destroyed by some greedy bastards…. on both sides of the situation.

    • MattB 5:26 pm on September 10, 2008 Permalink

      I really wanted to buy this game when walking through Best Buy yesterday. I am very lucky I read this before I bought. It drives me crazy that an otherwise quality game would be destroyed by some greedy bastards…. on both sides of the situation.

    • MattB 12:26 am on September 11, 2008 Permalink

      I really wanted to buy this game when walking through Best Buy yesterday. I am very lucky I read this before I bought. It drives me crazy that an otherwise quality game would be destroyed by some greedy bastards…. on both sides of the situation.

  • britg 9:13 pm on May 21, 2008 Permalink | Log in to leave a Comment
    Tags: gaming, greenhouse games, penny arcade   

    On the Rain Slick Precipice of Darkness 

    Just grabbed the new Penny Arcade game off xbox live and I have to say that it’s a lot better than I though it would be. The animation and asthetics are great, the dialog is witty, just as you’d expect from PA, and the pacing seems nice a quick so far. I look forward to playing the rest of it.

    If you’re not an xbox live-er, you go grab the game at greenhouse games. I want to say they have it available for PC, Mac, and Linux but I’m not sure and too lazy to follow my own link.

    I highly recommend checking this out. On XBLA it’s 1600 points but well worth it.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel