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

Author Topic: Project_battleship: question about events  (Read 1445 times)

0 Members and 1 Guest are viewing this topic.

luca.94.gallo

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Project_battleship: question about events
« on: March 24, 2016, 09:52:24 am »
Hi everyone, I'm new in this community!  :)

With a group of friends I'm trying to make a game for an exam. We are projecting battleship and my task is to mange graphics and the main.
I want to set a combination of key which determines an action. For example, if the player presses, in this order, F1, H and then he presses the left button on a chessboard he will place a ship named F1, horizontally in the slot chosen with the click.

I tried to do that many times but I failed!  ::)

Can you help me?  ;D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Project_battleship: question about events
« Reply #1 on: March 24, 2016, 10:11:36 am »
What do you need help with exactly? We won't just write the code for you. ;)

You basically just have to save the buttons that have been pressed and check them when you click on a slot or so.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

bitano

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Project_battleship: question about events
« Reply #2 on: March 24, 2016, 10:18:50 am »
I tried to do that many times but I failed!  ::)
Success is stumbling from failure to failure with no loss of enthusiasm!
Go go fail again until you succeed :D

Good luck!

luca.94.gallo

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Project_battleship: question about events
« Reply #3 on: March 24, 2016, 10:23:26 am »
What do you need help with exactly? We won't just write the code for you. ;)

You basically just have to save the buttons that have been pressed and check them when you click on a slot or so.

Of course you won't and I don't want you to do it  ;)
I don't know how to "save" this buttons! I tried with nested if statements in the window.pollEvent but I think it does not work like that!

nicox11

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: Project_battleship: question about events
« Reply #4 on: March 24, 2016, 10:25:59 am »
Here is an idea of mine (maybe not the best) :

Use like a kind of cyclic container :
http://stackoverflow.com/questions/1863597/c-scrolling-through-items-in-an-stlmap

Everytime a key is pressed, you store it with the time in the "cyclic" container. You then have to check every frame if combo of key is pressed in the right order within a timerange (ie: if the combo is right but took too long, don't register it as right combo).

I don't know if it's clear. But you should find something seeking for fighting game combo programming.
« Last Edit: March 24, 2016, 10:29:22 am by nicox11 »

 

anything