Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > communication b...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 9514 of 9592
Post > Topic >>

communication between classes

by carvalho.miguel@[EMAIL PROTECTED] Apr 17, 2008 at 11:42 AM

hi there,

i'll try to keep this as short as possible to avoid a wall of text.
for my CG class in college i have to build an asteroids clone using an
opengl c++ wrapper provided. the way this wrapper works is fairly
simple, it provides a serie of interfaces that we have to inherit from
(and we inherit the ones needed for the class we're building, like
inherit Draw if we're drawing or Keyboard if we want input), and it
setups glut and opengl and also manages the game loop. theres one main
application class (that inherits from Application interface) that
manages all entitys in the game, basically works like this (quick
example):

class Ship : public cg::Entity, public cg::IDraw
{
(...)
void draw() //implemets abstract method inherited from IDraw
{
//draw ship here
}
};

class MainApp : public cg::Application
{
void init() //implements abstract method inherited from
cg::Application
{
this->AddEntity( new Ship );
}
};

int main( int argc, char** argv )
{
cg::Run( new MainApp );
return 0;
}

thats pretty much how it works. the way ive been doing to process
input for the ship is to also inherit the IKeyboard interface and
implement the onKeyboardInput() abstract method on the ship. thing is
i would like to make a seperate input class that would process the
input for the entire game (would be more elegant i think, not only
that but also imagine i have a class Stars and want to change the
color of the stars whenever i move the ship, i cant make the Stars and
Ship on the same class). how would i in that case and using this
wrapper communicate between the input class and the ship class?
example:

class ManageInput : public cg::Entity, public cg::IKeyboard
{
void onKeyboardInput( char key ) //implements abstract method
inherited from IKeyboard
{
//change ship X and Y position here, but how? the ship is another
class.
}
};

i want to avoid public variables and static variables/methods.
basically i want a dynamic model to communicate between all the
classes.
thanks in advance =)

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]




 4 Posts in Topic:
communication between classes
carvalho.miguel@[EMAIL PR  2008-04-17 11:42:38 
Re: communication between classes
Christopher <cpisz@[EM  2008-04-18 06:13:19 
Re: communication between classes
Tony Delroy <tony_in_d  2008-04-18 17:15:17 
Re: communication between classes
Lance Diduck <lancedid  2008-04-18 17:18:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 8:01:35 CDT 2008.