Jump to content
  • Advertisement

fshmt

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

117 Neutral

About fshmt

  • Rank
    Newbie
  1. fshmt

    Classes and header files mess

    Thanks so much everyone! I am indeed using #pragma once by the way. I noticed that when I'm creating a method which takes a reference of an object, I need a forward declaration for that object. But why use a forward declaration and create a pointer for an object?   like here: class Player; class Game { Player* m_Player; }; rather than: #include "Player.h" class Game { Player m_Player; }; is this done just to avoid header file problems?  
  2. Hello all!   I've been learning C++ for the past few months and lately I started messing around with SFML. I tried making some simple games but I always get to a point where I have 3 or 4 classes which always end up being a mess, and also I get header files compilation errors.   Question # 1 is, when dealing with OOP game programming, is there a general structure I should be aiming at? What I do is make a "game" class which creates and initializes the window, and it has a method with the game loop in it. in that method I create all instances of other classes, such as "eventHandler Event", and I pass a reference of the Window to a method in Event.. Same thing when rendering, I have a Graphics class which receives a reference of the Window(created in Game) and renders from there. Am I doing this right? I mean, it feels "right" to do but it gets messy very fast to the point that I'm struggling to understand my own code. Are there any recommended general guidelines for this?   Question # 2 - I seem to get header files errors quite a lot.. Say I have:   -Game class -Graphics class -Event handling class -Sprite class -Player class(inherited from sprite)   What I do is include all headers in Game.h, and include Game.h in all headers - does this means that if Graphics class needs to use something from Sprite class, Sprite.h won't be seen by Graphics.h? I get a lot of errors with this. I once was able to solve it with a forward declaration, "Class Sprite;" in Graphics.h but then other times this doesn't work. How do I avoid such errors?    Thanks so much! 
  3.   yep I this also sounds nice!  I really didn't get too much into lists so I guess it's time to do that.. thanks:D
  4. oh, I see.. so if I understand correctly, there's no way to do this without a list? i mean I guess i could do it with something like Bullets[99] but that would be pretty lame :P and pretty bad i guess if there were >99 bullets on the screen.   i guess for some reason I thought there was a dynamic way to do this using pointers only.   so saying that in my game status updating class i have a list of bullets, I would need for each game loop to check each bullet instance for coordinates and collision detection, etc, am i getting this?    thanks a lot!
  5. Hi everyone, I'm learning C++ and I have a question -    say i'm making an Invaders game, and if the user hits spacebar, a "fire weapon"  function (lets call it fireWeapon(); ) is called.   so I guess i'd have to use a new pointer here? say I have a bullet class with coordinates and other stuff, in the fireWeapon() i'd go:   Bullet bullet = new bullet,      my question is really simple, how to I handle this new bullet? i know that since it's new, it won't go out of scope when the function is ended, but should I be returning the pointer from fireWeapon? or passing it to a different function?    and say the bullet is not deleted, then i'm firing another bullet and there are 2 bullet objects - where should i "store" them after declaring them? i'm sure i'm missing something, its a bit confusing to me :P   thanks and sorry for the bad english
  • 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!