Thread: Object oriented SDL

  1. #1
    Registered User
    Join Date
    May 2009

    Object oriented SDL

    Another day. Another question.
    Alright guys I've successfully programmed a pong game in SDL and would like to now move on to making a pacman or something similar, but I have a question as to how to have a gamestate class that calls functions. I've thought about just having it contain the game state and having a pacman, ghost, and menu class take in the current state but having a get function in the game state class. But I'm afraid that then I will have a bunch of objects checking for updates and running a switch case.
    I also thought that it would be easier to run everything from one swtich-case statement in the gamestate class.. and have it seperated to do input, then logic, and finally rendering, but the only problem with this is I would have to either pass every object instance to the gamestate class or make them all global(I know REALLY bad). So I guess my question is what's the correct approach. I've seen a few that suggest creating a hierarchy does this method involve all objects to be parented by the gamestate class. Hope this is clear.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Lazy Foo' Productions

    Helpful article on State Machines, if you haven't already read it (considering you're talking about SDL, you probably have).

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Try one approach or the other and when you run into problems and have a specific question ask it here.

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Liverpool UK
    The Lazy Foo design example works really well, but before just diving in with it, take time to think your game design through and how it would be implemented with the State Machine shown in the tutorial, as it is only one way to do it, and does have some limitations.
    Last edited by rogster001; 01-31-2011 at 09:17 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Favourite program
    By progcomputeach in forum General Discussions
    Replies: 18
    Last Post: 08-04-2010, 05:27 AM
  2. Object Oriented Programming
    By obaid in forum C++ Programming
    Replies: 5
    Last Post: 08-22-2007, 05:31 AM
  3. Object Oriented Programming
    By eric123 in forum C++ Programming
    Replies: 6
    Last Post: 11-30-2005, 04:56 AM
  4. Object Oriented Cube
    By Ti22 in forum Game Programming
    Replies: 3
    Last Post: 01-11-2005, 08:18 PM
  5. Object Oriented - Funny story
    By MethodMan in forum A Brief History of
    Replies: 5
    Last Post: 09-26-2002, 02:21 PM