Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6025353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:17:19+00:00 2026-05-23T04:17:19+00:00

For my game, Everything inherits from Entity, then other things like Player, PhysicsObject, etc,

  • 0

For my game,

Everything inherits from Entity, then other things like Player, PhysicsObject, etc, inherit from Entity. The physics engine sends collision callbacks which has an Entity* to the B that A collided on. Then, lets say A is a Bullet, A tries to cast the entity as a player, if it succeeds, it reduces the player’s health.

Is this a good design?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:17:20+00:00Added an answer on May 23, 2026 at 4:17 am

    I believe that messaging system is somehow better suits your “world”.

    Entity* target = ...;
    bool    handled = target->send(M_COLLIDE, ...);
    

    In this case you will not need neither dynamic casts nor to check result of dynamic cast.

    Update, here is an example:

    target->send(M_COLLECT, pMushroom);
    ...
    
    Person::handle(uint message, Entity* the_thing)
    {
      switch(message) 
      {
        case M_COLLECT: this->things.push( the_thing ); 
                        the_thing->send(M_COLLECTED_BY, this); break;
      }
    }
    

    Entity::handle(uint message, Entity* the_thing) implementation can be wrapped into
    MSG_MAP_START, MSG_MAP_END and HANDLE_MSG(msg) macros so your code will look like:

    MSG_MAP_START
    
       HANDLE_MSG(M_COLLECT)
       {
         this->things.push( the_thing ); 
         the_thing->send(M_COLLECTED_BY, this);
       }
       HANDLE_MSG(M_COLLECTED_BY) 
       {
         ...
       }
       ...
    MSG_MAP_END
    

    Many variations of this are possible.

    By the way Objective-C has this kind of messaging built-in into the language. With extremely ugly notation but still.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a little game using Three.js and everything is going well apart from
I've written a Monte Carlo player for the board game Nine Men's Morris. Everything
I'm porting a game from WP7 XNA to Android; everything was working using Canvas
I've been writing a 2D basic game engine in OpenGL/C++ and learning everything as
i'm trying to make some sort of Business Simulation Game and everything is working
So I'm developing and iPhone game right now and everything has been working just
I am making a fighting game in Flash and while I have everything running,
Boy, I've got everything down-pat save the word referencing. The game crashes because of
I made a simple game for the iPhone using OpenGL ES. Everything works fine
I'm making a sort elements web game using jQuery, HTML & CSS. While everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.