GDevelopApp / GDevelop-examples

Repository of examples and templates for GDevelop - the open-source, no-code game engine
https://gdevelop.io
51 stars 18 forks source link

turned based fighting example #121

Closed shadow00dev closed 2 years ago

shadow00dev commented 2 years ago

Describe the example

this is a turned based fighting example game with 1 player and enemy with 2 ability(fireball and summon zombie) also i made the art myself

heres a link to play it: https://shadow001.itch.io/turned-based-fighting-example

Checklist

(the project folder is in comments)

D8H commented 2 years ago

I added TODO comments in the project file. I didn't modify any event. If you didn't modify it since 2 hours, please use this file instead and remove a TODO only if the modification is done. It will be easier to follow if another reviewer check it. https://www.dropbox.com/s/a7d0ytmxro5k18k/TurnedBasedFightingTODO.zip?dl=1

shadow00dev commented 2 years ago

before i upload a file i will do all todos anyway so i could use my own file then right?

shadow00dev commented 2 years ago

Screenshot 2021-10-21 195618

the ones in red square makes no sense todo, cuz the the ennitiys one would be for both player and enemy states(so i would have to put them in a state for not gameover which would be variable state not game over right, and for the beginning of scene one thats like that to, cuz its for the group it in, it would make no sense to put it in scene group, right?

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

anyway ive done almost all of them(if i rember correctly just the move health stuff i didnt change(though that one makes no sense to me)

D8H commented 2 years ago

the ones in red square makes no sense todo, cuz the the ennitiys one would be for both player and enemy states(so i would have to put them in a state for not gameover which would be variable state not game over right.

You are right that reducing the number of events can be a good thing, but this is not the only thing that make good events. Clarity, bug proofness, performances are important too.

On the clarity part:

On the bug proofness part:

On the performance part:

For the beginning of scene one thats like that to, cuz its for the group it in, it would make no sense to put it in scene group, right?

When the event groups follow the stats there won't be any "Scene" or "Entry" groups. It should be something like this:

The health bar events are not in the right state. The player health changes during the the EnemyTurn state.

You didn't do the TODO in the middle of the screenshot.

I may not be reachable Saturday. So, I give you additional suggestions. The "PlayerTurn" and EnemeyTurn" can be split into 2 states:

The objects used to do the animation must be created and destroyed inside the PlayerAttack/EnemyAttack state (aiming for clarity once again).

FiniteStateMachineSplit

shadow00dev commented 2 years ago

The health bar events are not in the right state. The player health changes during the the EnemyTurn state.

health bar event for player is in player state, it prob wont work if i put player in enemy, also duh player health changes during enemy cuz its happens at their state plus well i dont know how else i could do it for it kinda, also the health bar events should be all right there right?

shadow00dev commented 2 years ago

also moving the health id stuff were giving bugs so i decided i would put it back to where it was

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

fixed the health bar bug and the flip events are at the beginning of the scene

D8H commented 2 years ago

The health bar events are not in the right state. The player health changes during the the EnemyTurn state.

health bar event for player is in player state, it prob wont work if i put player in enemy, also duh player health changes during enemy cuz its happens at their state plus well i dont know how else i could do it for it kinda, also the health bar events should be all right there right?

also moving the health id stuff were giving bugs so i decided i would put it back to where it was

This is what I was telling you. You put the player health bar event inside the PlayerTurn state which can't work because the player health change during EnemyTurn state so it must be inside the EnemyTurn state. Do you understand?

shadow00dev commented 2 years ago

The health bar events are not in the right state. The player health changes during the the EnemyTurn state.

health bar event for player is in player state, it prob wont work if i put player in enemy, also duh player health changes during enemy cuz its happens at their state plus well i dont know how else i could do it for it kinda, also the health bar events should be all right there right? also moving the health id stuff were giving bugs so i decided i would put it back to where it was

This is what I was telling you. You put the player health bar event inside the PlayerTurn state which can't work because the player health change during EnemyTurn state so it must be inside the EnemyTurn state. Do you understand?

the bug was happening when the player healthbar was in enemyturn(i did a test for it)

shadow00dev commented 2 years ago

also it has the least bugs when the health bar was not in any states so i feel like that's the best

shadow00dev commented 2 years ago

https://youtu.be/EvKN9YRTLzM made a video explaining stuff

D8H commented 2 years ago
  • The reader will see the event that make damages and then the one that checks the game over.

Thanks for the video. I think I understand the issue. The order of the events inside a state also mater. My sentence wasn't clear because I made it look like it was just to help the reader, but it's also important for the game.

For it to works, it should follow this order:

I'm sorry I forgot to say that after seeing your previous version.

The solution that you talked about in your video to put it as a sub event is a good solution. I was thinking of suggesting it when we do the polish because to do hit animation like a screen shake or something it will need to happen only when the health is changing. An event link can be used to avoid to copy past it 6 times.

About making health bars disappearing at the end, it sounds good.

shadow00dev commented 2 years ago

An event link can be used to avoid to copy past it 6 times.

event link?, i heard of link but thats for external events and stuff like that but a event link i i never heard of

D8H commented 2 years ago

An event link can be used to avoid to copy past it 6 times.

event link?, i heard of link but thats for external events and stuff like that but a event link i i never heard of

Yes, that's what I meant.

shadow00dev commented 2 years ago

An event link can be used to avoid to copy past it 6 times.

event link?, i heard of link but thats for external events and stuff like that but a event link i i never heard of

Yes, that's what I meant. but wont i then be repeating the link event?(cuz its only 1 sub event)

D8H commented 2 years ago

but wont i then be repeating the link event?(cuz its only 1 sub event)

Yes, that why I said I was keeping it for the polishing where they might be more actions.

It' s ok to keep it in an event below for now.

shadow00dev commented 2 years ago

oh okay

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

in this update i changed how healthbar gets updated

also im assuming in the polish stage there would need to be sounds right?, cuz im not good at making sounds(my music isnt good and well the best way ik how to make sounds is using bfxr and well would they fit the game, cuz i dont think they would)

D8H commented 2 years ago

TurnedBasedFighting.zip

in this update i changed how healthbar gets updated

Ok

also im assuming in the polish stage there would need to be sounds right?, cuz im not good at making sounds(my music isnt good and well the best way ik how to make sounds is using bfxr and well would they fit the game, cuz i dont think they would)

I've never used sounds in GDevelop. I can't help, but that's probably not a must (none of my examples have sounds).

shadow00dev commented 2 years ago

I've never used sounds in GDevelop. I can't help, but that's probably not a must (none of my examples have sounds).

:) ive used sounds before so ik how it works in the events side just im not good at making them lol , anyway what else i need to fix/change?

D8H commented 2 years ago

what else i need to fix/change?

shadow00dev commented 2 years ago

what else i need to fix/change?

  • The transition to the "GameOver" state need to be inside the states it happens.
  • Use one event groups per state, for instance:

    • Beginning
    • Always
    • Player Turn
    • Enemy Turn
    • Game Over
  • Try to spit PlayerTurn and EnemyTurn (see the drawing and explanation above)

so like new states?

D8H commented 2 years ago
  • Try to spit PlayerTurn and EnemyTurn (see the drawing and explanation above)

so like new states?

Yes, it's at the end of this message: https://github.com/GDevelopApp/GDevelop-examples/issues/121#issuecomment-949091777

shadow00dev commented 2 years ago

okay

shadow00dev commented 2 years ago
  • Use one event groups per state, for instance:

    • Beginning
    • Always
    • Player Turn
    • Enemy Turn
    • Game Over

Beginning isnt a state its a on beggining of scene(right?) and always isnt a state to right?

shadow00dev commented 2 years ago

anyway ig ill do it tomorrow since its a bit late rn(but it still makes no sense for me to do dis in my opinion cuz it works and its has a order(like the comments and the groups gives it order))

D8H commented 2 years ago
  • Use one event groups per state, for instance:

    • Beginning
    • Always
    • Player Turn
    • Enemy Turn
    • Game Over

Beginning isnt a state its a on beggining of scene(right?) and always isnt a state to right?

The beginning of scene is the initial state in some way, but yes. Yes, "Always" is like a factorization (instead of copy pasting it in each state). It's just to make it clear when the events can happen.

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

there are now attack states(well there's a fireball attack state and zombie attack state for player and enemy)

D8H commented 2 years ago

Good, it's starting to have a good structure. Can you sort the events inside a state by chronological order?

I agree with Bhou:

Flip variable, and Flip events are not all neccesary, you can remove it, this dosen't add value in this example. You need it once at begnning of the scene for flipping the animations of the Enemy, no more. For the Fireball and the Monster you have to keep one action in one direction, no need to handle -180 and 180 angle for Fireball and force -100 and 100 for Monster, This way there is no need to adds conditions for checking if an object is flipped. You have just Turn enemy = true, AbilityUse = Fireball, then create Fireball, and add a force toward Player position. (or -180 angle if you prefer)

It can be something intelligent to do on a complex project, but that's not what the example is about. Let's keep it simple for that part.

shadow00dev commented 2 years ago

Good, it's starting to have a good structure. Can you sort the events inside a state by chronological order?

i dont know how sorry

I agree with Bhou:

Flip variable, and Flip events are not all neccesary, you can remove it, this dosen't add value in this example. You need it once at begnning of the scene for flipping the animations of the Enemy, no more. For the Fireball and the Monster you have to keep one action in one direction, no need to handle -180 and 180 angle for Fireball and force -100 and 100 for Monster, This way there is no need to adds conditions for checking if an object is flipped. You have just Turn enemy = true, AbilityUse = Fireball, then create Fireball, and add a force toward Player position. (or -180 angle if you prefer)

It can be something intelligent to do on a complex project, but that's not what the example is about. Let's keep it simple for that part.

but what if somone wants to change if the enemy or player is flipped or not?, but okay

D8H commented 2 years ago

but what if somone wants to change if the enemy or player is flipped or not?, but okay

They do it them-self?

shadow00dev commented 2 years ago

but what if somone wants to change if the enemy or player is flipped or not?, but okay

They do it them-self?

i mean like in the scene editor(the flip event allows the developer to flip the stuff inside the group and has the flip var to flip stuff inside the scene editor which i feel like its useful), but if it isnt then ill remove it)

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

ive removed flip variable(but i didnt do the chronological order thing cuz idk what it is mainly google didnt help me with telling me what it is to as far as i understand)

D8H commented 2 years ago

ive removed flip variable(but i didnt do the chronological order thing cuz idk what it is mainly google didnt help me with telling me what it is to as far as i understand)

It means to sort thing by the order of happening. For instance, a trigger one alone is what happens 1st in a state so it should be the 1st sub-event of the state.

shadow00dev commented 2 years ago

will I have to do it for events and the action and conditions inside them?

D8H commented 2 years ago

will I have to do it for events and the action and conditions inside them?

Just the events.

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

maybe hard to see the change but it was almost like that so i just changed events around to make it more like that(by that i mean chronological order also im not 100% sure if im right either)

shadow00dev commented 2 years ago

also before its finished I need to add a visual way to tell who's turn it is to, because well the state text don't look the nicest, tell me if wrong

D8H commented 2 years ago

There is still a few things to change to have a good FSM.

shadow00dev commented 2 years ago

There is still a few things to change to have a good FSM.

  • Move the tint of the buttons in the events that press them (it's easier to follow and it factorizes a bit).

okay

  • Use a variable for the chosen attack and makes the 2 attacks in one "PlayerAttack" state (all attacks have the same transition in and out, so only one state is needed. Unnecessary states make the states harder to understand).

i personally think putting under state var is easior to understand than adding a new variable(so if i still need to then i will)

  • Use a boolean variable to know if damages where taken to factorize the damage handling, but keep them in there "PlayerAttack" and "EnemyAttack" states.

sorry i dont understand, why would i need a boolean to say if dmg dealt were taken or not?

  • Move the game over transitions in "PlayerAttack" and "EnemyAttack"

that cant happen cuz im checking if health is 0 then do it so i would have move the entire system for that wouldnt i?, or i could jsut check if health <= 0 then do that i guess but them it would be a repeat of events which you normally tell me to combine

D8H commented 2 years ago
  • Use a variable for the chosen attack and makes the 2 attacks in one "PlayerAttack" state (all attacks have the same transition in and out, so only one state is needed. Unnecessary states make the states harder to understand).

i personally think putting under state var is easior to understand than adding a new variable(so if i still need to then i will)

  • Use a boolean variable to know if damages where taken to factorize the damage handling, but keep them in there "PlayerAttack" and "EnemyAttack" states.

sorry i dont understand, why would i need a boolean to say if dmg dealt were taken or not?

  • Move the game over transitions in "PlayerAttack" and "EnemyAttack"

that cant happen cuz im checking if health is 0 then do it so i would have move the entire system for that wouldnt i?, or i could jsut check if health <= 0 then do that i guess but them it would be a repeat of events which you normally tell me to combine

At the end of "PlayerAttack" state, there will be something like this:

and same for "EnemyAttack" state

It does more events but it is a lot easier to understand and less bug prone. This is how FSM works.

shadow00dev commented 2 years ago

At the end of "PlayerAttack" state, there will be something like this:

  • condition: Damage is taken | action: Update the bar
    • condition health less or equal 0 | action: transition to GameOver

and same for "EnemyAttack" state

It does more events but it is a lot easier to understand and less bug prone. This is how FSM works.

okay

but how do i check if dmg has been taken?, i guess i could get old health var and check if health is lower than it then update it every time but still, and yes i could just put it in the same event thing as when dmg is taken

shadow00dev commented 2 years ago

also could you pls say why making a new var for checking the attack instead of making it a state would be better(cuz i think making it a state would be better), well i guess the system you told me for the dmg is taken would mainly only work with 1 check if attack i guess unless i copied and paste the events for it but i still think it makes no sense for a second var for checking a attack when a attack is a state, right?

D8H commented 2 years ago

but how do i check if dmg has been taken?, i guess i could get old health var and check if health is lower than it then update it every time but still, and yes i could just put it in the same event thing as when dmg is taken

Yes, comparing the old health works too but it needs to initialize it at the beginning of the scene or in the instance editor which make it far from where it used. With a boolean, the variable is:

also could you pls say why making a new var for checking the attack instead of making it a state would be better(cuz i think making it a state would be better)

Doing a good code is like explaining something to a friend.

The states are useful when it helps to understand how transitions from one state to another are done. If I had to explain to some friends how a turn based game works, I would say: "The player choses an attack and the attack start with an animation. When the animation is done, it's to the enemy to chose an attack." Or in term of transition: "PlayerChoice" --> "PlayerAttack" --> "EnemyChoice"

If I had to explain this:

I will probably loose them under details and they won't understand it.

As you can see the there is the same transitions in (from PlayerChoice) and out (to EnemyChoice). So, it's not relevant to repeat ourselves.

shadow00dev commented 2 years ago

Doing a good code is like explaining something to a friend.

The states are useful when it helps to understand how transitions from one state to another are done. If I had to explain to some friends how a turn based game works, I would say: "The player choses an attack and the attack start with an animation. When the animation is done, it's to the enemy to chose an attack." Or in term of transition: "PlayerChoice" --> "PlayerAttack" --> "EnemyChoice"

If I had to explain this:

  • "PlayerChoice" --> "PlayerFireBallAttack" --> "EnemyChoice"
  • "PlayerChoice" --> "PlayerZombiesAttack" --> "EnemyChoice"

I will probably loose them under details and they won't understand it.

As you can see the there is the same transitions in (from PlayerChoice) and out (to EnemyChoice). So, it's not relevant to repeat ourselves.

okay(sorry for late aswer, ill get to trying to do it i guess)

shadow00dev commented 2 years ago

TurnedBasedFighting.zip heres what i think ive done: Screenshot 2021-10-24 165650

the one in todo/doing is becuase im not 100% sure how i can make that work with the events right now so im gonna not do that until well idk, also i think it would be better to have it how it is since well it doesnt have any bugs and i think its easy to understand

shadow00dev commented 2 years ago

TurnedBasedFighting.zip

found a bug which wasnt really a bug but annoyed me so i fixed it(i didnt reset attack when game over and it annoyed me cuz well of the the stat text says the attack being in use)

D8H commented 2 years ago
shadow00dev commented 2 years ago
  • Moving the game over transitions in "PlayerAttack" can be done like this: image

okay

  • If you want to set BeenDamaged to false where you did that fine to me, but then remove the "Trigger Once" as the health changes twice with the zombie.

huh wont that bug it?(im prob wrong?)

  • Don't forget to set BeenDamaged to true every time the health change (each time for zombie)

okay i thought it wasnt needed(well it isnt for cuz it works but okay)

  • Make an event group by state

for the attack states?

  • Factorize the set to "AbilityUse" animation at the start of the "PlayerAttack" state.

may i ask what Factorize means?

  • Move the event that set the animation back to "Idle" in the "PlayerAttack" state (because the animation ends during this state).

okay

  • Remove "Trigger one" when the conditions will no longer be fulfill after the actions are executed

okay(if i can find them i will)

  • Remove "PlayerUsedAbility" variable actions as it is never read.

ooh i thought i did lol