I'll definitely give this a shot. But I'm still not content with the fact that calling this function from a separate class is not working.Bakkon wrote:hurstshifter wrote:
I was think this too. I'd try letting the player class hold an array of bullet objects. Then create a fireBullet function for the player. Just grab the first bullet in the array that's currently bDead and shift its properties around. You'll have access to private player variables and then adjust the bullet with mutator functions in its own class.
[Solved] Calling a class function from another class
Moderator: Coders of Rage
- hurstshifter
- ES Beta Backer
- Posts: 713
- Joined: Mon Jun 08, 2009 8:33 pm
- Favorite Gaming Platforms: SNES
- Programming Language of Choice: C/++
- Location: Boston, MA
- Contact:
Re: Calling a class function from another class
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
http://www.thenerdnight.com
- hurstshifter
- ES Beta Backer
- Posts: 713
- Joined: Mon Jun 08, 2009 8:33 pm
- Favorite Gaming Platforms: SNES
- Programming Language of Choice: C/++
- Location: Boston, MA
- Contact:
Re: Calling a class function from another class
And lo, on the 6th hour of coding there was triumph. Bullets flew over yonder with much speed and accuracy. And there was much rejoicing, yayyy.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
http://www.thenerdnight.com
- Innerscope
- Chaos Rift Junior
- Posts: 200
- Joined: Mon May 04, 2009 5:15 pm
- Current Project: Gridbug
- Favorite Gaming Platforms: NES, SNES
- Programming Language of Choice: Obj-C, C++
- Location: Emeryville, CA
- Contact:
Re: [Solved] Calling a class function from another class
Out of curiosity, did you end up changing your original design? Or did you stick with passing a player object?
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
Website (under construction) : http://www.timcool.me
- hurstshifter
- ES Beta Backer
- Posts: 713
- Joined: Mon Jun 08, 2009 8:33 pm
- Favorite Gaming Platforms: SNES
- Programming Language of Choice: C/++
- Location: Boston, MA
- Contact:
Re: [Solved] Calling a class function from another class
Innerscope wrote:Out of curiosity, did you end up changing your original design? Or did you stick with passing a player object?
I went with the array of bullet objects within the player class. Definitely a better way to go with a simple game such as this. I then created a shoot() function in player that is passed a reference to one of the elements of that array of bullets. The bullet class is now simply an SDL_Rect and 2 integer variables. Next step, collision detection & block removal. Thanks so much for everyone's help.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
http://www.thenerdnight.com
- Bakkon
- Chaos Rift Junior
- Posts: 384
- Joined: Wed May 20, 2009 2:38 pm
- Programming Language of Choice: C++
- Location: Indiana
Re: Calling a class function from another class
Awesome, man. I'm currently working on a schump myself and I'm around the same stage as you. Always feels good to see stuff moving around the way it should.hurstshifter wrote:And lo, on the 6th hour of coding there was triumph. Bullets flew over yonder with much speed and accuracy. And there was much rejoicing, yayyy.
- Innerscope
- Chaos Rift Junior
- Posts: 200
- Joined: Mon May 04, 2009 5:15 pm
- Current Project: Gridbug
- Favorite Gaming Platforms: NES, SNES
- Programming Language of Choice: Obj-C, C++
- Location: Emeryville, CA
- Contact:
Re: [Solved] Calling a class function from another class
Good move. Also I wouldn't consider this a hindrance to what you're learning. It's generally poor practice/design to call a function of a class from another class. Although, for that purpose you might want to look into delegation. (basically, using a contained instance of a class within a class, to do function calls)I went with the array of bullet objects within the player class. Definitely a better way to go with a simple game such as this.
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
Website (under construction) : http://www.timcool.me
Re: [Solved] Calling a class function from another class
If Player was a singleton you could have declared player::getprect() as static. Not a good design, though.