Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Waiting for a Key  (Read 1563 times)

0 Members and 1 Guest are viewing this topic.

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Waiting for a Key
« on: October 06, 2015, 08:30:32 pm »
I've done some research through the forums and google and I've been unable to find much about the topic.

Essentially, the type of thing I'm trying to do is draw a tilemap of x,y. Some tiles will be basic grass, others will be walls, and the third type of tile will be a "battle tile". I'm going to use a
int battle = rand () % 100;
and take if (battle >=90)
DrawBattleSequence();

the one problem i'm finding with this, and with the constant frame refresh of SFML windows is that if I do this type of method, as soon as the battle is over, the window will begin refreshing and realize the character is on a battle tile and start calculating whether to go to the battle sequence or not. How could I set this to essentially force the program to wait for a move after the battle sequence? If you're having trouble imagining what I'm trying to do, think Pokemon. You get into a battle and regardless of how long you stand in that tilespot after the battle, you WILL NOT get into another battle.

As I said, I've been trying to research this but I can't seem to come up with anything. Anybody have any ideas or things I could do to achieve my desired outcome of the window waiting for a move after the battle sequence?
« Last Edit: October 06, 2015, 08:32:06 pm by DuvnjakA »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Waiting for a Key
« Reply #1 on: October 06, 2015, 09:36:24 pm »
It's very simple: you check every frame whether a move was done (key press) and set a bool variable accordingly. If there was no move, don't start a battle.

To avoid repeating battles on the same tile, you can mark that tile somehow. For example, set a flag in the Tile object that represents tiles in your code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Waiting for a Key
« Reply #2 on: October 07, 2015, 01:20:26 am »
I understand the first part but what I'm saying is that like... I don't want a battle to occur again on that tile again immediately after that battle. So if the character moves left and then back right, that tile can generate another battle. I'm just having trouble thinking about how to mark that tile for that single turn if that makes sense?

AFS

  • Full Member
  • ***
  • Posts: 115
    • View Profile
Re: Waiting for a Key
« Reply #3 on: October 07, 2015, 03:13:04 am »
You could store in a variable the location of the last battle generated. Then you make it so a battle is generated if the rand value is over 90 (or whatever number you use) AND if the location is different than the one from the last battle.

Then, to make it so you can have battles in the same location only after moving, you clean the variable everytime you make a move to a different tile, so when you come back to the same tile the condition can be true again.

Hopefully that makes sense.

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Waiting for a Key
« Reply #4 on: October 07, 2015, 03:37:00 am »
Yeah, so when a button is hit it essentially clears the variable and then when a battle starts, it creates a variable saying that a battle took place and if that variable isn't 0 then it won't run the battle sequence again

 

anything