Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

129 Neutral

About Kaanin25

  • Rank
  1. Kaanin25

    Best way to design an object list

    Edit: I was able to resolve it by moving #include "Bullet.h" and #include "EnemyGuy.h" into the EntityFactory.cpp. I also moved #include "EntityFactory.h" into EnemyGuy.cpp Ok so I went and read up about the factory design pattern and I am trying to implement it and I have hit a roadblock. [source lang="cpp"]// in EnemyGuy.h #include "Entity.h" #include "EntityFactory.h" class EnemyGuy: public Entity { public: void update(); } [/source][source lang="cpp"]// in EnemyGuy.cpp #include "EnemyGuy.h" void EnemyGuy::update(){ if (you see player) Entity* shotFired = EntityFactory::create("bullet", params); } [/source][source lang="cpp"]// in EntityFactory.h class Entity #include "Bullet.h" #include "EnemyGuy.h" class EntityFactory{ public: static Entity* create(const std::string passed, params); } [/source][source lang="cpp"]// in EntityFactory.cpp #include "EntityFactory.h" static Entity* EntityFactory::create(const std::string passed, params){ if (passed == "bullet") return new Bullet(params); if (passed == "enemyguy") return new EnemyGuy(params); } [/source] I get a cyclic dependancy error because the factory needs to include EnemyGuy so it can create instances of it and then EnemyGuy needs to include the factory so it can call the create() method. Normally you would break a cyclic dependancy with a forward declare but in this case a forward declare won't do it. How can I resolve this issue?
  2. Kaanin25

    Best way to design an object list

    You guys are awesome. FleBlanc I want to have your babies. Thank you! Edit: Any reccomendations on design pattern books?
  3. For my current project I have an Entity class that all game objects are inherited from. I also have an EntityManager class that keeps a list of pointers to all the game objects created. The idea being that this list will be used for updating and drawing all game objects to the screen. I find myself struggling to find the best way to design all of this. How do I make sure all game objects are added to the EntityManager list? How do I make sure that when an object is deleted, all other game objects that might have a pointer to said object are not now referencing deallocated memory? During cleanup I delete all the Entity objects in EntityManager, and therefore they all need to be heap objects created with the new keyword. How do I make sure none of the pointers point to a stack object? Right now I am doing this project alone, and ultimately the easy way out to most of these questions is for me to just remember things and don't make mistakes. "Just dont forget that all entity objects need to be made using new." "Just dont forget to add all Entities you make to the EntityManager list." But that is bad programming right? What if I was on a development team...that wouldnt fly! The other devs would not know all the catch clauses of what not to do and what may cause a bug with my code. Thats the whole point of classes and privacy and encapsulation ect...to make code that is hard to break and easy to organize. I'm trying to improve my skill as a designer and programmer...am I overcomplicating this? Somebody help me.
  4. Kaanin25

    Open source code for a beginner

    Notice how I very specifically noted that I was not bashing your code...I understand it was a tutorial designed with the intent to show beginners how to handle the SDL library and setup a very simple game; and for that purpose you did a fantastic job, your tutorial has been very sucessfull and I myself thank you for making it. So you just assume that im sitting around all day just parusing through other people's code without writing any of my own? That I havn't already gotten "my hands dirty". I have been writing code on and off for some time now; I have a few past projects under my belt. I am not an infinite pool of resources unto myself and when I lack the skill and knowlege to solve a problem I seek out others who are better then me for answers. In my particular case I had a problem with the game I am developing right now and all the solutions I had come up with on my own have been unsatisfactory. I thought maybe I could get a look at few other open source projects made by better programmers to see how they did it. learning by example is a very valid form of education. If you don't want to help that is fine, then dont post, but please don't berate me as if im not trying. Sorry if that was a bit of a rant, but it really upset me. I came looking for help. Thank you very much for the resources Serapth, EnigmaticProgrammer, and Dejaime.
  5. I have a firm understanding of C++ beyond the beginner stuff; I know classes, polymorphism, templates, ect... What I am looking for is some example source code that is properly written to look at. Something small and simple like Tetris or Snake, not huge like the Doom 3 source code. I found this on LazyFoo's website. http://lazyfoo.net/g...locks/index.php and it's working code, but there are a lot of global variables, C style functions that should be part of a class object, and so forth. I'm not bashing his code, Ive written far worse myself. I don't need perfect, I just need something with a good format as a reference. Something I can use whenever I hit a roadblock to look and see "how they did it". Anyone know of or have any open source game code I can look at?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!