Using SDL nativelyBy Chris Williams. Published: 6th Oct 2004, 09:18:10 | Permalink | Printable
Neil White makes his moveThe SDL library has helped RISC OS programmers bring various games and utilities from the open source world to the platform. Although not everything these days is about porting software: Neil White has begun using SDL in his own native puzzle games, such as Crazeeman and Conveysdl.
Neil's main reasons for using SDL for native games are that you can now play the games in the desktop, the software can use the graphics features of the SDL library and also, interestingly, the games can be ported to other platforms more easily.
We asked Neil to explain how he moved over to using SDL for his games, as Convey was originally written in BASIC and used the FastSpr library to plot graphics to the screen.
"Most of my BASIC games were always written with a view to converting them to C, so it actually only took me a few hours," explained Neil. "For example, the FastSpr routines take the x,y origin from the top left, and so does SDL. The only difference is that FastSpr defaults to plotting from the center of the image, which is quite useful sometimes. So I printed out my Convey BASIC code for easy reference and pretty much copied the code only using C functions instead of the BASIC ones.
"The main play area apart from the hoods at each end of the conveyer belt and the main character still use the same plot co-ordinates as the basic FastSpr version, and because all the collision detection is done in an array, the graphics you see on the screen are really just a representation of the game workings."
"Generally, like most of my games, Convey was a 'self improving' programming exercise. One little thing I was playing with was packing all the main
images in one file and splitting them up in the code, because keeping
all the images needed in a game as separate bitmaps in a directory could
get very silly."
One problem that Neil faced was the methods required to update the screen using SDL, which is different to how you would normally go about it with BASIC and FastSpr.
"Clearing the screen and completely redrawing the frame isn't all that efficient, so everything is plotted onto what was there before. So for example, when the score changes it plots a black rectangle before updating the score, and there is another black rectangle plotted 'under' the left edge of the belt to cover up where the character jumps into the black background. If there was a graphical background you'd have to grab the piece of background before anything moves into it and put it back after, so having a black background is a bit of a slack out."
The source code to the SDL games are also available for download, if you're feeling nosey. The Conveysdl also uses the same original data files that the BASIC version used. Neil, who also approved of Alan Buckley's SDL port of xrick, hopes to eventually cross-compile his games on his Linux PC, for speed reasons.
SDL library website
Previous: Midlands show ready for December
Next: Middleton: 'Select 32' due 2005
DiscussionViewing unthreaded comments | View comments threaded by reply | Skip to the end
Please login before posting a comment. Use the form on the right to do so or create a free account.
Search the archives
Today's featured article
Running RISC OS Programs on Linux
Peter Naulls contemplates the possibilities
17 comments, latest by drjones69 on 6/6/05 11:17AM. Published: 31 Mar 2005
Select32 mini-Q and A
Trying to get to the bottom of this
16 comments, latest by AndrewDuffell on 25/11/04 11:39PM. Published: 24 Nov 2004
News and media:
RISCOS Ltd •
RISC OS Open •
MW Software •
Advantage Six •
CJE Micros •
Liquid Silicon •
Chris Why's Acorn/RISC OS collection •
The Register •
The Inquirer •
Apple Insider •
BBC News •
Sky News •
Google News •
© 1999-2009 The Drobe Team. Some rights reserved, click here for more information
Powered by MiniDrobeCMS, based on J4U | Statistics
"Oh, and books are freaking books, not dead trees, for gawd's sake"
Page generated in 0.5674 seconds.