2D Game Library for BBC BASIC

for discussion of bbc basic for windows/sdl, brandy and more
Post Reply
User avatar
Richard Russell
Posts: 2647
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

2D Game Library for BBC BASIC

Post by Richard Russell »

Many of you will know that, several years ago, David Williams wrote a library for BBC BASIC for Windows - GFXLIB, later updated to GFXLIB2 - providing support for plotting 2D graphics of the kind needed in high-performance 2D video games. Using those libraries he and others have written many excellent games, some of them prize-winning!

In the last couple of years I have converted a few of those games to BBC BASIC for SDL 2.0, so that they will run on a wider range of platforms. This was largely achieved by replacing the calls to GFXLIB2 with similar functionality from SDL 2.0. However this was done on an ad-hoc basis, with the modifications not necessarily being directly applicable to other programs.

As you may have seen in my recent announcement of the release of BBCSDL v1.26a, I have now created a library containing near-equivalents to many of the GFXLIB2 functions, which should both make converting programs easier and provide a framework for creating new video games using BBC BASIC for SDL 2.0. This library is described here.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
User avatar
BigEd
Posts: 4538
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: 2D Game Library for BBC BASIC

Post by BigEd »

Sounds like a handy library, thanks for that!
User avatar
Richard Russell
Posts: 2647
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: 2D Game Library for BBC BASIC

Post by Richard Russell »

Richard Russell wrote:
Fri Nov 19, 2021 5:07 pm
I have now created a library containing near-equivalents to many of the GFXLIB2 functions
In case anybody here wants to try using this library (unlikely, but you never know) I've made an interesting discovery. When using the collision-detection capabilities it seems that a worthwhile improvement in speed can be obtained by specifying 255 (&FF) as the 'alpha' or 'object ID' value when calling one of the relevant plotting routines (PROC_gfxShapeSetAlpha, PROC_gfxPlotSetAlpha, PROC_gfxPlotRotateScaleSetAlpha or PROC_gfxPlotFlipScaleSetAlpha).

This behaviour was somewhat unexpected, but isn't surprising when you think about what's going on 'under the hood'. In a situation when you don't care which object was collided with, or you have an alternative way of discovering which it was (e.g. from its coordinates), it will be a valuable technique for optimising performance.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
nicolagiacobbe
Posts: 103
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: 2D Game Library for BBC BASIC

Post by nicolagiacobbe »

Thanks, it is an excellent solution to have a reference library.
I have browsed the documentation but would like some hint from the source: how do you implement a scrolling game (a la 'super mario') using the library? Under plain SDL I have alway redrawn the tile but maybe there is a better way.
User avatar
Richard Russell
Posts: 2647
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: 2D Game Library for BBC BASIC

Post by Richard Russell »

nicolagiacobbe wrote:
Thu Nov 25, 2021 8:10 pm
Under plain SDL I have alway redrawn the tile but maybe there is a better way.
David Williams would be the best person to answer - he's the game expert, I've just tried to provide some software tools! But as far as I'm aware all his games redraw the entire canvas from scratch every frame; it's the most straightforward approach. It may well seem terribly inefficient to those more familiar with programming a BBC Micro, but modern graphics hardware is designed with that approach in mind, I think.

The principal scrolling example that I've adapted from BB4W/GFXLIB2 to BBCSDL is David's Forces of Darkness, and that uses a multi-layered tiled background with the tiles drawn in a different position on each frame to implement the scrolling. A factor to bear in mind is that different platforms have different texture size limits, so you should ensure the tiles aren't too big; 4K x 4K pixels is probably as large as you should go.

If you have experience of programming with plain SDL2 it's likely that you will want to use exactly the same approach. My new library is only a thin wrapper around SDL2 functions, because that gives the best chance of an acceptable performance. It's fortunate that SDL2's capabilities proved to be such a good match to those of David's GFXLIB2.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
nicolagiacobbe
Posts: 103
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: 2D Game Library for BBC BASIC

Post by nicolagiacobbe »

Thanks for the info. I always did the scrolling by the canonical way but that I could be doing it badly always remained more than a theoretical possibility.
Post Reply

Return to “modern implementations of classic programming languages”