Comments (6)
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
Line 120 in b1d60fc
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.
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.
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.
Update: this was actually easier than I thought. Please try this unofficial v1.13
from dojs.
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.
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)
- Include() and Require() hide parse errors HOT 1
- include cURL option to set the supported ciphers HOT 1
- Can't use let or const HOT 1
- LoadLibrary does not work on 2nd run when using integrated editor HOT 3
- red/blue colors inverted HOT 7
- glide3x.DXE: module loading failed
- VSCode plugin is missing in the repository
- /examples/blendfx.js Missing "examples/rose.png" HOT 1
- Correct path structure for DOjS projects? HOT 2
- add tar support HOT 1
- add support for libdmk
- add support for D64 images
- add support for ADF files
- add DMS support
- try SMK support
- Update to zip 3.1
- add libFLAC decoding
- Support libexif
- Add (somewhat) Node.js compatibility
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dojs.