how to make a turn-based battle system
-
class BattleSystem { public: void turn() { /* implement */ } };
Sorry for being snarky, but there's probably a book to be written about the subject. What exactly do you have a problem with? Have you researched the subject or tried to implement anything?
-
@Chris-Kawa how to define player and enemy turns
-
@milhao If those are very different you can do something simple like
while(someBattleEndCondition()) { playerTurn(); enemyTurn(); }
or you can have a common interface for player and the enemy and do something like
class Unit { ... }; class Player : public Unit { ... }; class Enemy : public Unit { ... }; std::vector<Unit*> units { new Player(), new Enemy() , new Enemy(), new Enemy(), ... }; while(someBattleEndCondition()) { for (auto unit : units) turn(unit); }
You could also model your game as a state machine using
QStateMachine
and defineQState
s like battle start, player turn, enemy turn, player won, player lost etc. and define transitions between those states based on your game logic....and gazillion other possibilities. There's really no single right or wrong solution to this. It all depends on your game structure.
-
@milhao
So you could use QPainter to load and position images on screen, you can use this to hint to the customer what it is that your trying to convey through text/manuals, audio narration. I believe QPAinter has draw text and position options. Next you want to build a system by means of remembering to code in that style and or build a class that can have timers within them that will trigger displaying text and moving images in proper order.
QOpenGL can do what QPainter does although it will use the graphics card instead of the customers CPU -
You could have game elements proverbial “living” as a specific class, that class will emit an action Everytime the game changes.
You can have a
class character { Public: Int health = 100; Int aggression = 3; int magic_resistance = 2; Void apply_magic_attack_to_character(int attack_power, int mana) { //apply resistance subtract result Health = health - (attack_power * (mana / magic_resistance )); Emit character_health_result_affected(this) } }
-
The signal emitted can be caught by a class that controls the QPainter, the slot can be as such
Class visualizer { Public slot: Void character_health_affected { //show blood or shake effect styled images //timeout the blood, hide/delete blood effects after a few seconds } }