Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - dbox

Pages: [1]
1
Programs / QBJS - Import code from external .bas files
« on: April 15, 2022, 04:43:54 pm »
Hi All,

I wanted to share the latest feature I've been working on for QBJS to solicit some input from the community.  I've implemented the ability to include "modules" from external source files into your program.  This concept is similar to include from c/c++ and import from javascript.  The idea here is to make it easy to create reusable libraries that can be shared between projects.  Here's an example:

Code: QB64: [Select]
  1. Import MyLib From "https://raw.githubusercontent.com/boxgaming/qbjs/main/samples/include/test.bas"
  2. Import Maths From "https://raw.githubusercontent.com/boxgaming/qbjs/main/samples/include/maths.bas"
  3.  
  4. MyLib.DoStuff          ' Call exported sub
  5. Print MyLib.GetThings  ' Call exported function
  6.  
  7. Print Maths.Factorial(10)
  8. Print Maths.Plus1(11)
  9.  

Try it on QBJS-Dev

Any imports must be the first statements in your program.  In this example we've imported functionality from two different external source files.  Any methods exported from those libraries can be accessed in your program by prefixing them with the alias specified after the import statement.

Only the content specified for export will be available in the calling program.  This lets us have "private" shared variables and helper functions in our included modules.

Here's what the library files look like:

test.bas
Code: QB64: [Select]
  1. Export GetStuff As GetThings
  2. Export DoStuff
  3.  
  4. Dim foo
  5. foo = "somthing"
  6.  
  7. Function GetStuff
  8.     GetStuff = "got the stuff"
  9.  
  10. Sub DoStuff
  11.     Print "do the stuff"
  12.  

maths.bas
Code: QB64: [Select]
  1. Export increment As Plus1
  2. Export factorial AS Factorial
  3.  
  4. Function increment (num)
  5.     increment = num + 1
  6.  
  7. Function factorial (num)
  8.     Dim res
  9.     $If Javascript Then
  10.         if (num === 0 || num === 1) {
  11.             num = 1;
  12.         }
  13.         else {
  14.             for (var i = num - 1; i >= 1; i--) {
  15.                 num *= i;
  16.             }
  17.        }
  18.     $End If
  19.     factorial = num
  20.  

Export statements must appear at the top of your module code.  If you want to have a different name for the exported method from it's internal name you can use the "As Alias" syntax as shown above.

Import Entire Programs
Another benefit of this feature is that you can import entire programs from an external source file to make it easier to share large programs. Here are a couple of examples:

QBJS Paint
Code: QB64: [Select]
  1. Import QBJSPaint From "https://raw.githubusercontent.com/boxgaming/qbjs/main/samples/apps/paint.bas"
  2.  
Try it on QBJS-Dev


Terry Ritchie's Excellent Flappy Bird Clone
Ported from QB64
Code: QB64: [Select]
  1. Import FlappyBird From "https://raw.githubusercontent.com/boxgaming/qbjs/main/samples/games/trfbird.bas"
  2.  
Try it on QBJS-Dev

I'd be very interested to hear your thoughts.

2
Programs / Finger Painting in QBJS
« on: April 09, 2022, 06:18:56 pm »
Hi All,

One of the features I'm working on for the next QBJS is support for touch events and more dynamic scaling/sizing when viewing QBJS programs on mobile.  I'd be very curious to hear your experience with the following example.  I've adapted a drawing program I shared earlier.  With this version you should be able to draw now with your finger on your mobile (or otherwise touch-enabled) device.

Click here to try it out!

I'd be very curious to know your experience and what kind of device you tried it on.  Were you able to draw with the various tools and change colors?  Did the scaling look appropriate for your device?

If you want to see the code you can click here.   (This is still in development so some of the syntax may change slightly.)

3
Programs / QBJS - QBasic for the Web
« on: February 18, 2022, 09:58:59 am »
Update 30-Mar-2022
New beta release v0.3.0
https://qb64forum.alephc.xyz/index.php?topic=4670.msg141653#msg141653



Hi All,

I've decided to spin off QBJS into it's own project.  This started as a feature of the GX game engine https://qb64forum.alephc.xyz/index.php?topic=4481.0 that allows you to publish games built in QB64 for the web.  Based on the interest in this feature I've created a new stand-alone project: QBJS.

 
qbjs-screenshot.png


The goal here is to recreate the feel and accessibility of programming in QBasic/QB64 in the browser.  You can try it out here:

https://boxgm.itch.io/qbjs

This is still a work-in-progress, but it is pretty functional at this point so I thought I would share with a wider audience to get some additional feedback.  I've tried to document what is currently supported here:
https://github.com/boxgaming/qbjs/wiki/QBasic-Language-Support
https://github.com/boxgaming/qbjs/wiki/Supported-Keywords


4
Programs / Simple, Consolidated Game Device Input
« on: January 11, 2022, 01:02:54 am »
Hi All,

I put a good deal of work into a simple, consolidated game input API that allows for simple detection and testing of input from keyboard, mouse or game controller devices and thought I would share as there have been recent discussions on this topic.

With this approach device input can be detected with the following:

Code: QB64: [Select]
  1. Dim Shared diMoveLeft As GXDeviceInput
  2. GXDeviceInputDetect diMoveLeft
  3.  

The program will wait until a keyboard key, mouse button, or game controller button or axis movement has been detected.  Then later in your code when you want to test for that device input, simply do this:

Code: QB64: [Select]
  1. If GXDeviceInputTest(diMoveLeft) Then
  2.    ' Do your move left logic here
  3.  

I've added specific logic for linux and maxos to handle the fact that keyboard button presses are not returned by the _DEVICEINPUT method on those environments so that the behavior can be consistent cross-platform.  This is actually related to my very first post on the forum: https://qb64forum.alephc.xyz/index.php?topic=4448.msg138691#msg138691.

I've included a few demonstration programs in the attached zip.

1) The detect.bas program will display the last detected input and print information about the device input:
Code: QB64: [Select]
  1. '$Include:'gx/gx.bi'
  2. _Title "Detect Device Input"
  3.  
  4. Print "Waiting for input..."
  5.     Dim di As GXDeviceInput
  6.     GXDeviceInputDetect di
  7.     Cls
  8.     Print "Device #:    " + Str$(di.deviceId)
  9.     Print "Device Name: " + GXDeviceName(di.deviceId)
  10.     Print "Device Type: " + GXDeviceTypeName(di.deviceType)
  11.     Print "Input Type:  " + GXInputTypeName(di.inputType)
  12.     Print "Input Id:    " + Str$(di.inputId)
  13.     If di.deviceType = GXDEVICE_KEYBOARD Then
  14.         Print "Key Name: " + GXKeyButtonName(di.inputId)
  15.     End If
  16.     Print "Input Value: " + Str$(di.inputValue)
  17.     Print
  18.  
  19. Sub GXOnGameEvent (e As GXEvent): End Sub
  20. '$Include:'gx/gx.bm'
  21.  

detect.png


2) The input.bas demonstrates detecting input for certain actions and then testing for those inputs in a game loop:
Code: QB64: [Select]
  1. '$Include:'gx/gx.bi'
  2. _Title "Test Device Input"
  3.  
  4. GXSceneCreate 500, 300
  5. GXFrameRate 10
  6.  
  7. Dim Shared dleft As GXDeviceInput
  8. Print "Press Left... ";
  9. GXDeviceInputDetect dleft
  10. PrintDeviceInput dleft
  11.  
  12. Dim Shared dright As GXDeviceInput
  13. Print "Press Right...";
  14. GXDeviceInputDetect dright
  15. PrintDeviceInput dright
  16.  
  17. Dim Shared djump As GXDeviceInput
  18. Print "Press Jump...";
  19. GXDeviceInputDetect djump
  20. PrintDeviceInput djump
  21.  
  22.  
  23. GXSceneStart
  24.  
  25. Sub GXOnGameEvent (e As GXEvent)
  26.     Dim ldown As Integer
  27.     Select Case e.event
  28.         Case GXEVENT_UPDATE
  29.             If GXKeyDown(GXKEY_ESC) Then GXSceneStop
  30.  
  31.         Case GXEVENT_DRAWSCREEN
  32.             GXDrawText GXFONT_DEFAULT, 10, 10, "Press one or more mapped inputs:"
  33.             If GXDeviceInputTest(dleft) Then
  34.                 GXDrawText GXFONT_DEFAULT, 100, 100, "Left"
  35.             End If
  36.             If GXDeviceInputTest(dright) Then
  37.                 GXDrawText GXFONT_DEFAULT, 150, 100, "Right"
  38.             End If
  39.             If GXDeviceInputTest(djump) Then
  40.                 GXDrawText GXFONT_DEFAULT, 125, 125, "Jump"
  41.             End If
  42.     End Select
  43.  
  44.  
  45. Sub PrintDeviceInput (di As GXDeviceInput)
  46.     Print GXDeviceName(di.deviceId) + " : ";
  47.     Print GXInputTypeName(di.inputType) + " : ";
  48.     Print Str$(di.inputId) + " : ";
  49.     If di.deviceType = GXDEVICE_KEYBOARD Then
  50.         Print " [ "; GXKeyButtonName(di.inputId); " ]";
  51.     Else
  52.         Print ;
  53.     End If
  54.     Print " : "; di.inputValue
  55.     Print
  56.  
  57. '$Include:'gx/gx.bm'
  58.  

3) The nes-config.bas program is an example of using the API in a device setup screen with the ability to save the config:
Code: QB64: [Select]
  1. '$INCLUDE:'gx/gx.bi'
  2. '$INCLUDE:'control-config.bi'
  3.  
  4. GXSceneCreate 256, 240
  5. GXSceneScale 2
  6.  
  7. ControlConfigInit
  8. ControlConfigShow
  9.  
  10. GXSceneStart
  11.  
  12. Sub GXOnGameEvent (e As GXEvent)
  13.     OnControlConfigEvent e
  14.  
  15. '$INCLUDE:'gx/gx.bm'
  16. '$INCLUDE:'control-config.bm'
  17.  

nes-config.png


Feel free to use any of the examples in your own projects.  I would be very interested in any feedback you have.

5
Programs / Zelda - The Legend of GX
« on: December 27, 2021, 05:43:53 pm »
Since there are a number of zelda projects currently in-progress, I thought I'd put together a little version as a shameless plug for GX.  One of my current game projects is actually a NES mashup that will have crossover from a number of titles.  So I already had the map built using the GX map editor.  This version will let you walk the entire overworld map.  As an example I've also implemented the lost woods maze.  There are triggers on the map for all of the cave and dungeon entrances.  At the moment this will take you to an empty cave map.  (I haven't built any dungeon maps.)  If you exit the cave it reloads the overworld map and puts you back in the right spot.

Use the arrow keys to walk around.  You can press F1 to toggle debug mode.

I'd be interested in any feedback.  If you'd like to use this in your own projects, you are more than welcome.

6
Programs / GX - A QB64 Game Engine
« on: December 14, 2021, 01:28:12 pm »
Hi All, I wanted to share a project I've been working on for a bit.  I know there are several folks here with a lot of gaming experience and I would love some feedback.

In the process of working on several 2d game projects I was noticing that I was needing to write a lot of game "plumbing" for each project.  I wanted to see if it would be possible to create a generic game API and engine for QB64 that could support a number of different types of 2D games (platformers, top down, isometric strategy, etc.).  GX is the result of this effort so far.

The goal here is to create a flexible, event-based game engine. Based on your game requirements you can use as much or as little of it as you need, but the engine will take care of the main tasks of managing the game loop and screen buffering for the display.  The current alpha version has support for:
  • Scene (viewport) management
  • Entity (sprite) management
  • Tiled map creation and management - Including a world/map editor (built with Inform)
  • Bitmap font support
  • Basic collision detection
  • Basic physics/gravity
  • Device input management
  • Keyboard, mouse, and game controller
  • Interactive debugging

I've made an effort to document the project here:
https://github.com/boxgaming/gx/wiki

There are several samples included in the project and even a tutorial here:
https://github.com/boxgaming/gx/wiki/Tutorial

You can download the pre-release here:
https://github.com/boxgaming/gx/releases

I'm still in the process of documenting the API, so not all of the calls are there yet, but there is a good start.  I've tried to make the style similar to the QB64 wiki.

Additionally, I'm working on a export to web feature that I will be committing in subsequent updates that will convert a GX-based QB64 game into a canvas-based javascript game that can run in the browser.  It's not quite ready for primetime yet but I've included a screenshot of where I've converted one of the sample projects.

I would appreciate any and all feedback.

- dbox

7
QB64 Discussion / Device Input Question
« on: December 01, 2021, 12:30:39 pm »
Hi QB64 community.  First off, let me just say a big thank you to all who are keeping this project going.  I have had an absolute blast since I found this project.  Like many others I was trying to find a way to run my old QBasic projects on a modern OS without needing a virtual DOS machine.  I've been impressed with the modern extensions especially as regards to the graphics capabilities which are available.

So I've been working on some new game-related material that I hope to share shortly and I've run into what seems like a cross-platform compatibility issue with device input.  I'm trying to use a flexible device input scheme that would allow dynamic mapping of inputs to game actions, regardless of whether the input is from a keyboard, mouse or game controller.

On windows the idea is working as expected.  However, when I try to run the code on Linux or MacOS it does not seem as though the keyboard events are being caught by the device import methods.

Here is a bit of sample code to demonstrate:
Code: QB64: [Select]
  1.     Dim i As Integer
  2.     For i = 1 To _Devices
  3.         If _DeviceInput(i) Then
  4.             Cls
  5.             Locate 1, 1
  6.             Print Str$(i) + " : " + _Device$(i) + " : " + Str$(_LastButton(i))
  7.             Dim j As Integer
  8.             For j = 1 To _LastButton(i)
  9.                 If _Button(j) Then
  10.                     Print "button: " + Str$(j)
  11.                 End If
  12.             Next j
  13.         End If
  14.     Next i
  15.     _Limit 60
  16.  

If you run this on windows you will see button ids corresponding to the keys that are pressed down.  However, on Linux and MacOS it only seems to be detecting mouse and controller button events.

If this has already been addressed in another thread or there is an open issue that I missed just let me know and forgive my noobness.

Pages: [1]