GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 10:41 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Polymorphism in games
PostPosted: Mon Mar 28, 2011 1:56 am 
Rookie

Joined: Mon Mar 28, 2011 1:18 am
Posts: 1
I've tried hard to think on how polymorphism might be used effectively in a game. I just can't figure it out.

It's easy to find out how components help on quickly adding new functionality to entities, thus improving flexibilty and code reuse. But polymorphism seems useless to me.

I'm asking before starting a new project, cause I might be missing some important issues regarding polymorphism and regret it later...


Top
 Profile  
 
PostPosted: Mon Mar 28, 2011 4:32 am 
P2k
User avatar

Joined: Tue Aug 23, 2005 5:11 am
Posts: 2145
If you don't need it, don't use it. It depends on the type of game you are making as well as the way you design your engine. Just because the language you are using supports it, doesn't mean it is necessary.


Top
 Profile  
 
PostPosted: Sat Apr 23, 2011 5:31 pm 
My first battleship game in Java used polymorphism quite heavily.

All the naval boats had a common super class named "Boat_Hull" which contained the general properties and behaviors such as length, hp, resistance and position.

When the game loaded I simply generated x number of boats for each window and placed them in a "Boat_Hull" array even if the objects had specific types such as "Renegade" or "SubMarine".
Code:
HullBoat $boatArr[x];
for(i++) {
 $boatArr[i] = new SpecificBoat();
}


This allowed me to easily keep track of the boats inside an array and if I ever needed to call a specific function I just casted into it's primitive type(Such as a radarscan method for a Scout boat).


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group