Good afternoon,
as the title already has stated, I am trying to handle a large variety of spells (and/or weapons). Because weapons are basically the same idea as spells we will not talk about them. Basically I am new in handling large amount of objects which are almost the same. The only problem is that I do not know, where I need to start. I’ve searched online and found some decent tutorials about oop and Multiple Inheritance. But I’ve not become much smarter after reading that. The only thing I’ve learned is that you need to use Interfaces. But I believe that Interfaces are not that usefull, because you still need to write and copy all the code to do the same thing.
Interfaces
Java Multiple Inheritance
My Current setup is as following:
- EntitySpell extends Sprite
- SpellCaster (*)
- Spell (**)
- SpellFireBall extends Spell (***)
*SpellCaster:
This class is basically just a timer of the spell it is ‘holding’. It is also holding the level of the spell (but I’ve not implemented the leveling system yet).
[quote]public class SpellCaster {
private float timer;
Spell spell;
public SpellCaster(Spell spell, int level){
this.spell = spell;
this.timer = spell.getCooldown();
}
public void update(float dt){
if(timer < spell.getCooldown())
timer+=dt;
}
public float getMana(){
return spell.getMana();
}
public boolean castSpell(float x, float y){
if(timer >= spell.getCooldown()){
spell.castSpell(x, y);
timer = 0;
return true;
} else {
return false;
}
}
}
The castSpell is a boolean, if it get casted, then the mana of the player will be reduced by the manaCost which is located in the SpellCaster
**Spell:
Just a simple abstract class that contains some information about the spell i.e. mana/cooldown (and it passes the castSpell event).
***SpellFireBall:
This is the real problem, I am trying to solve the issues it is providing me with, I don’t want to write the code twice on multiple Spells like i.e. SpellLightningBolt. It is just a waste of space and time, at this moment it is still a small class without many lines of code in it, but when this class is completed it will be filled with information which is on many spells the same (but remember, not all the spells will be the same, i.e. buffs will be targeted to player instead of target to the cursor. These buffs will only work on the player and not on the enemy unlike the spell FireBall).
Because of this I cannot create a superclass Spell that is extended by SpellFireBall. So what is the best way of creating classes like Spells and or Weapons.
Please, if you have dealt with this issue on your project(s), can you tell me what you’ve done? I am not seeking for your codes or whatever, just a summary of what you’ve done or what you think that is the correct way.
If you have any question about the script, what I am doing etcetera, just post a comment to ask
As always, thanks for reading the post
-RoseSlayer