I’m trying to create a Tower Defense game where minions move through a labyrinth and you can build towers on top of the labyrinths’ walls to stop the minions. I’m personally using Python and pygame, but I’m looking for generic design answers that can be applied to any OOP language.
So, since both minions and towers have a size and a position, as well as a sprite image, I felt like it’d be appropriate to create a common base class:
class Entity: def __init__(self, image, size, position): self.image = image self.size = size self.position = position def draw(self, surface): surface.blit(self.image, self.position, self.size)
Alright so I want my game to work similar to Vector TD, where you have multiple different types of towers that can be build, but you can build multiple instances of each type, and each instance can then be upgraded individually. What this means is that I need some kind of generic way to explain how all towers of similar type work, yet I need each instance to be separated. So I began with a
Tower base class with all the properties I can think of:
class Tower(Entity): def __init__(self, image, size, position, attack_speed, attack_damage, attack_splash_radius, attack_range, cost): super().__init__(image, size, position) self.attack_speed = attack_speed self.attack_damage = attack_damage ... # etc
But the problem is, all turrets of the same type have same range, same attack speed, same cost, etc. but they’re still individual instances, so it would feel stupid to copy all of these common properties with the same values to every instance separately.
The reason I don’t just subclass
Tower to create my custom tower types is because they don’t really add anything to the class. Literally the only thing they would do is change the default values for the
__init__‘s arguments. Using subclasses like this would also lead into the common values being copied into every instance, so if my subclass
range=800 for all my turrets, it would mean that the value
800 would be stored separately into every instance (when they could just use a common value). I just feel like there’s a better way.
So my question is entirely about the design/architecture/structure of the system. How should I group these properties together while still allowing individual turrets to be upgraded separately? Ideally I could be able to design these tower types in something like JSON where I can dynamically load them to the game.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!