CodingTrain / Directional-Boring

Horizontal Directional Drilling Simulation
MIT License
44 stars 20 forks source link

Keyboard controls #23

Closed frnco closed 1 year ago

frnco commented 2 years ago

After seeing this in Grady's video I, being programmer, just had to take a look. First of all, congrats on a great job, the game is really fun, and I'm still quite shocked how adequate the value 0.01 is for the const angle, I've experimented with different values and the range from 0.005 up to 0.02 is playable (And may be interestring to explore it as part of the difficulty settings), but 0.01 is by far the value that fits the largest range of possible scenarios.

That, however, aggravated my issue with the controls. Clicking depends on targeting the right element, which has nothing to do with the game, and playing in a laptop with a high DPI touchscreen makes it worse as the high DPI makes things smaller and it's noticeably hard to hit the button on the touchscreen.

I made a small addition to the code which fixed most of my issues:

function keyTyped() {
  console.log("J=Key typed: ["+key+"]")
  if (key === " ") {
    if (state == 'PAUSED') {
      state = 'DRILLING';
    } else if (state == 'DRILLING') {
      bias *= -1;
    } else if (state == 'WIN' || state == 'LOSE') {
      startDrill();
    }
  }
}

I put it right above // Draw loop, but it's my first time writing anything related to p5.js so that's probably not the best place to put it.

The angle experimentation also made me realize the steering limits shift ever so slightly, no idea whether it'd be easy to fix or not (It occurs to me that it may, for whatever reason, depend on the draw function and the time it takes to run, in which case it would be a very demanding issue and definitely not worth the trouble, but most likely that's not the case).

Again, congrats on the game and the channel, really happy to see such an amazing approach to spreading programming literacy, I'll be sure to spread the word.

ArztKlein commented 2 years ago

Hi, feel free to leave a pull request and Shiffman will review it if you are wanting to contribute. If not, I am happy to reformat your code and will submit a pull request myself, but it is up to you.

shiffman commented 2 years ago

I really like the idea of having keyboard controls. @alin256 do you have any suggestions on how to integrate this with your latest enhancements to the game? Should we have multiple options for controls? This seems related to #26

alin256 commented 2 years ago

@shiffman I did several modifications which were ultimately scraped.

In summary, for the game to be fun we need to embrace its original simplicity.

Thus for the keyboard controls, I would have 2 buttons mapped

  1. toggle bias to a large key such as the space key
  2. pause action for e.g. the escape key.

All the other actions including continue can be conveniently done with clicking the UI while paused.

PS: I will not have time to do any of that during the next few days.

alin256 commented 2 years ago

Let's keep this one open for further discussion