Thread: SDL game engine - fireshot

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    103

    SDL game engine - fireshot

    I wrote a game engine this weekend. Its 2d, extremely easy to use, event based and cross platform. The main benefit is clean code, combined with the ability for complete control over the internals. It doesn't do much yet (https://sourceforge.net/projects/seefour/), has squat for documentation, but, its nice to write code for, so developers are very much welcome. I intend to add features such as:

    Object collision
    object events (tell a function when an image is moved to specific/range of coordinates).
    Default keys (moveUp, moveDown, etc.)

    Tell me what you think.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    A few suggestions:
    • Standard practice is to use class names beginning with an uppercase letter, e.g. C4. You can decide if you want to do this or not.
    • If you want to have keys repeat the easiest way is to use something like this:
      Code:
          SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
              SDL_DEFAULT_REPEAT_INTERVAL);
    • I think your code is currently running as fast as it can, using 100% of the CPU. Some users (including me ...) don't like this very much, so you could try limiting the game loop to say 60 or 30 FPS. I had a really good link that describes this in detail, but I can't find it now, unfortunately.
    • If you want to be more object-oriented, instead of using callbacks you could use the observer design pattern. Say you have this:
      Code:
      class Observer {
      public:
          virtual ~Observer() {}  // virtual destructor
          virtual void notify(int key) = 0;
      };
      
      class KeyRegistrar {
      public:
          virtual void addObserver(int key, Observer *x);
          virtual void notifyOfKey(int key);
      };
      I haven't supplied the code for KeyRegistrar, but it basically remembers a list of which observers are interested in which key events. Then when a key event comes in, the observers are notify()'d and can deal with it appropriately. The user of your code can just subclass Observer to deal with keypresses.

      This is a bit more advanced stuff and if you don't want to do it, that's fine, it's just a thought I had when I was reading your code. Other references for the Observer design pattern:
      Observer Design Pattern
      Observer Design Pattern in C++
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    103
    Thanks for the suggestions.

    As for the classname, originally the project was called C64, which was changed cause of the commodore 64 thing, then it was e64 which was obvious why it was changed and then c4 and now fireshot cause c4 is a commercial game engine.

    I have started researching the observer design pattern, and I probably will incorporate it into the design.


    Consider joining, if you like.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 10-20-2009, 09:39 AM
  2. Possibility to create a good game engine
    By sarah22 in forum Tech Board
    Replies: 8
    Last Post: 06-13-2009, 01:04 AM
  3. Game Engine
    By Hugo716 in forum Game Programming
    Replies: 21
    Last Post: 06-14-2006, 01:09 PM
  4. SDL Game Menu
    By Sentral in forum Game Programming
    Replies: 7
    Last Post: 05-29-2006, 10:22 AM
  5. Game Engine Q
    By Lurker in forum Game Programming
    Replies: 6
    Last Post: 03-29-2003, 11:05 AM