Jump to content

  • Log In with Google      Sign In   
  • Create Account

Melkon

Member Since 21 Sep 2013
Offline Last Active Today, 06:32 AM

Topics I've Started

(Tower Defense) Template metaprogramming or Factory functions to avoid class hierarchy?

09 September 2014 - 01:13 AM

Hello!

Currently i am working in a Tower Defense Game (C++, SFML), which i started like 2 years ago, and i stopped developing it since i have a job.

Now i started again to teach a friend about C++, and i should rewrite alot of part.

 

A key question is how  to store the Tower (and Minion) hierarchy.

 

Now i have a TowerBase class, which have the Derived types, like ArcherTower, MageTower etc.

 

This is pretty bad, because TowerBase have the values like Range, Damage etc, which should be initialized there. Now i reassign it in the derived constructor, and it seems like a  terrible pattern.

It's also bad, because in the game i use all towers as a TowerBase, so it doesn't make much sense to derive them just because they can attack differently.

 

Okay, so the attack part i will use lambdas as template parameters, which will define how should it fire. It's okay.

 

I like the idea to template the Tower class instead of the class hierarchy (it's also faster, because there will be no virtual calls etc).

 

The problem come when i should define the towers. They have different damage, range etc.

 

Solition 1.: I would like the idea to somehow make it possible to typedef the towers with different values.

So when i say:

ArcherTower archerTower;

and

MageTower mageTower;

 it would call a constructor, which will set different base values (like for archerTower, 30 damage, for mage, 40), while ArcherTower and MageTower are just different typedefs for the same templated class.

Okay so, that's  the first solution, writing a template metaprogrammed class, and typedef it for different towers.

In this case, i must use a TowerBase class, which will let me use containers that store Towers.

This TowerBase should have at least a virtual Attack() function, which is again, problematic. This is because different Towers attack differently, but i just store TowerBase ptr-s, so i can't call the derived functions. How can i solve this?

Solution 2.: The other solution that come to my mind is to make factory functions, like "MakeArcherTower ()", which will do the things for me. It's slower and a bit harder to use, but i am sure i can do this, the solution one is something i don't exactly know, because i don't really have experience in metaprogramming. In this case, i shouldn't use a base class.

 

What do you think, which is the better? (or is it a 3rd option?)

 

I would also use this pattern to minions, so it would possible used instead of more than a hundred class.

 

Thank you for help! smile.png


[C++] Forward declaration VS include in headers

06 January 2014 - 10:26 AM

Hello!

 

Is there any issue with using forward declaration in header files instead of includes when it's possible?

It will compile faster, however i am not entirely sure if it's a good idea. ohmy.png

 

Thank you for answers!

Melkon


Question about TD game's code design

21 December 2013 - 04:28 AM

Hello!

 

I have a half finished TD and i decided to finish it. When i did that project i used pretty bad design, and i had a circular dependency, now i want to fix that.

 

The idea is:

Make a GameController class, the event loop run here, but GC won't handle it, it just decide who should handle it (the User interface or the map), and convert the mouseclick coordinate depending on the view of the handling class.

 

If there is an actual command from the UI (like Build XY Tower) the gamecontroller get it and drop down to the map to execute it.

 

I am sure it can work, but i am not entirely sure that's the best solution i can do.

 

Any opinion is appreciated!

Melkon


What graphics API should i use for a Heroes 3 style game?

12 November 2013 - 11:10 AM

Hello!

 

I like to start a Heroes 3 style project with C++, i think about what API should i use for graphics?

Now i mostly think about SDL, i have no experience in it yet tho.

Is someone who have experience with it can tell me if there is any issue with SDL for a bigger project?

 

Thank you for answers!


C++ (SFML) and Flash player/Unity

02 November 2013 - 07:14 AM

Hello!

Is it possible (if yes, how?) for a c++ (sfml) game to make compatible with flash player OR unity?

It is important because i can reach much more people through fp or unity. (for example i can promo it on kongregate.com etc).

 

Thank you for answers!


PARTNERS