Battle Engine design.

So, it’s turn based. The enemy will slide to the player, attack, and he will be knocked back and health will be shaved. Problem is, I don’t know how to go about it. The engine has a stats class, a player class, and the enemy classes. Right now, they will slide to the player when it’s their turn, but I don’t know if I should make an object that collides with the player and triggers the knock back and stat editing, or what. I also considered editing his stats directly from the enemy, and turning a boolean on in the player object to knock back, but then again, that’s sketchy too.

All entities are managed by a list in another class called EntityManager.

Any advice would be fantastic.

It really is your call.

The direct manipulation from the enemy would be easiest, however the object-event based method is more extensible.

I would suggest doing the easiest way first for the following reasons:

  1. To keep momentum / motivation… dont underestimate this for hobby game development
  2. This is a game, that most likely you are not collaboratively programming so you dont have to have the best / well understood solution to help others understand
  3. Normally the easiest/ simplest method is good enough

however if you start to feel restricted by the direct manipulation then you can probably reconsider at that point.

For changing the stats and knockback:


--------------Enemy Class---------------------
public void attack(Player p){
p.health = p.health - damage; //damage is an Enemy class variable(integer)
knockBackPlayer(p);
}

public void knockBackPlayer(Player p){
int deltaX = x - p.x; //class variable x and player variable x
int deltaY = y - p.y; //same as above but w/y
//do stuff w/deltaX and deltaY to animate knocking back



}

If you have only one player character/sprite, then the attack and knockbackplayer methods probably don’t need a parameter.
This is just a rough template, do whatever you want with it to fit your needs.

bad idea the knockback done this way. just apply a force on the body, that way you don’t break physics and different mass can respond in different way

right, it’s an engine. forgot about that. thx lesto.

There is no real physics, it’s really just an aesthetic. So he just slides back, since every “Living Entity” in my game has a simple directional movement base in it’s parent class. I just set the waypoint 5 units behind where he is, and he slides there with the sprite set up.

Sorry to necro, but I didn’t feel it neccesary to make another post for what I’m about to ask.

I can’t for the life of me get a smooth fighting engine going, it’s just…jumpy. Can I have some design advice please? Thank you.

Jumpy? Is it a lag problem or algorithm problem? For algorithm problems I would look into excessive use of the EDT thread.

And also you should post some code.