Git Product home page Git Product logo

Comments (6)

SuperIlu avatar SuperIlu commented on September 28, 2024

Hi,

sorry, I completely missed this ticket, seems like I didn't get an eMail for it :(

The long answer first:
DOjS is based on Allegro and all the native APi is directly implemented on top of Allegro functions.
p5js support is a (thin?) layer of Javascript on top of the native DOjS API.

When DOjS is running it calls Setup() once, then it does something similiar to this in a loop:

while(keepRunning) {
  Loop();
  if(Input) {
    Input(currentEvents);
  }
}

The Input() function is called with the current input state as an object:

/**
 * @typedef {object} Event
 * @property {number} x mouse X coordinate.
 * @property {number} y mouse X coordinate.
 * @property {number} buttons mouse buttons, see {@link MOUSE}
 * @property {number} key key code, see {@link KEY}
 * @property {number} ticks event time.
 */
class Event { }

This object is assembled by querying the current Allegro state:

    if (keypressed()) {
        key = readkey();
        ret = ((key >> 8) == DOjS.exit_key);
    } else {
        key = -1;
        ret = false;
    }

So key will be -1 if there is no key pressed or the Allegro key code if a key is pressed (if the key was the "exit key" DOjS will terminate).

p5js has the keyPressed() and keyReleased(), but as you can see above DOjS does not really have a "key release" event. That's why I try to simulate something similar in the Input() and Loop() functions provided by the p5js emulation. See here

exports.Loop = function () {

In short:
I'm not sure if the behavior you describe is caused by p5js-emulation, DOjS, Allegro or MS-DOS.
You seem to run DOjS in a DOSBox on Windows? This adds two more layers of uncertainty :)

I have two suggestions:

  • Try to give me a better explanation on what you want to achieve, maybe a short test program in the p5js editor that works well and where the behavior between p5js and DOjS is different?
  • Check out the native DOjS API and event system and check if it suits your needs better?

from dojs.

Sinfis avatar Sinfis commented on September 28, 2024

Thank you for your comprehensive response!

Here's a simple p5js editor script: https://editor.p5js.org/mikkos.koiranen/sketches/HlYKJ3-5v that shows the result I'm after: when holding down arrow keys, the yellow pixel immediately moves as it should do in a game. Also, two arrow keys can be pressed simultaneously, and the pixel moves diagonally.

Here's the same thing executed with a DOjS script, in which when the keys are held down, the movement is done like typing text: first one "step" is taken, then pause, then there are multiple steps as long as the key is held down; that's not an ideal way to move in a game. :) I maybe could avoid this with some coding, but that would need a way to detect the key release. And, it's not possible to press two letters at the same time and move the pixel diagonally.
movepix.zip

from dojs.

SuperIlu avatar SuperIlu commented on September 28, 2024

Right, now I'm getting what you are aiming at.

I tested some stuff and (right now), there is really no way of doing that with DOjS. Neither the native API, nor the p5js emulation are able to provide the info of multiple keypresses.

However: the functionality is available in Allegro: https://liballeg.org/stabledocs/en/alleg006.html#key

I will make this array available in the Javascript world with the next release.

My Idea would be to provide an array with boolean values and you can take the KEY-definitions from func.js to check if a given key is currently down.
I'd update that array every frame, but I have to check how much of a speed impact that would make.
I guess it would be feasible to switch that feature on/off on demand...

I can't really make promises on when I'll manage to try that, but I can give you a test version as soon as I have one if you are interested...

from dojs.

SuperIlu avatar SuperIlu commented on September 28, 2024

Update: this was actually easier than I thought. Please try this unofficial v1.13

DOjS-pre113.zip

from dojs.

Sinfis avatar Sinfis commented on September 28, 2024

Hello and thank you very much for your effort!

With the script "keytest.js" the unofficial patch works exactly as it should: the keys can be held down now and they even can be pressed simultaneously allowing diagonal movement.

I'm waiting for the official release, but take your time; at the moment I'm also investigating C programming with the Allegro library and DJGPP for developing DOS games. :)

from dojs.

SuperIlu avatar SuperIlu commented on September 28, 2024

I'll try to make smaller, but more frequent DOjS releases in the future. V1.10 and v1.11 took way too long.

Feel free to contact me on Mastodon or in Discord (see DOjS README.md) if you have questions regarding DJGPP and/or Allegro.

from dojs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.