Jogar vector td online6/11/2023 Instead they get pointed to (referenced) by all the towers the user creates. They don't get instantiated for every single tower instance the user creates. In your case I would just use this Tower base class and subclass it with all the towers at every single level possible that you can instantiate as startup, like BlueTowerLv1, BlueTowerLv2, GreenTowerLv1, etc, with a reference from BlueTowerLv1 to BlueTowerLv2 so that it knows what tower to use when leveling up (a null/nil for next_tower could indicate that the tower has reached a maximum level). You'd want the factory to also handle permanent tower upgrades, as it will be the one to know what upgrades to what and how. It would go something like this (excuse the Java syntax): public static Tower makeGreenTower() Just make a class that knows about the various defaults, and ask it to make whatever flavour of tower you want at the time. You do have a valid point that making a subclass just to set some default values seems ridiculous. And if at some point in the future you want to make towers that give temporary bonuses to some other towers, wouldn't you want for each one to have their own stats fields? Why on Earth would it bother you that a range value is stored in every instance of a tower? Are you trying to save the extra 2 bytes per instance? If you're severely memory constrained in your game, that's a different matter, but that doesn't sound like the problem. 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. So my question is entirely about the design/architecture/structure of the system. Using subclasses like this would also lead into the common values being copied into every instance, so if my subclass GreenTower defaulted 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). Literally the only thing they would do is change the default values for the _init_'s arguments. 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. 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. So I began with a Tower base class with all the properties I can think of: class Tower(Entity):ĭef _init_(self, image, size, position, attack_speed, attack_damage, attack_splash_radius, attack_range, cost):īut the problem is, all turrets of the same type have same range, same attack speed, same cost, etc. 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. Surface.blit(self.image, self.position, self.size)Īlright 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. 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:ĭef _init_(self, image, size, position): I'm personally using Python and pygame, but I'm looking for generic design answers that can be applied to any OOP language. 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.
0 Comments
Leave a Reply. |