Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, 26 December 2019

Chiller 2 Demo Xmas 2019

I've been working on a game for the last few months and have produced a demo level for the Freeze64 fanzine.  The demo was emailed to Freeze64 subscribers on Christmas Eve, so I guess it's fine to post this here now, doubly so since it has appeared in 'cracked' form on CSDb!

The game is called 'Chiller 2' and is an unofficial sequel to the Mastertronic original by David and Richard Darling.



The demo was produced especially for Freeze64 for Christmas, thus it features some vaguely Xmas music and snow and holly on the title and game screens.  So as to not give too much of the game away, the demo features only the ghost enemy following simple horizontal paths and various other features of the full game disabled!

To find out more about this game-in-progress and more of it's features, you can visit my Chiller 2 development blog here...

In the meantime, if you would like to play the demo, you can download it here...

If you want to play a 'cracked' version by TRIAD, with some built-in cheats, you can grab that from CSDb here...

Tuesday, 24 December 2019

Arkrismas 2019

Happy Christmas!

I've spent the last three days coding, pixelling and composing a little C64 Christmas demo that was today released by Arkanix Labs.  It's cunningly called 'Arkrismas 2019'.


It's quite simple in nature with the main screen display being a PETSCII (albeit with a modified charset for the lettering).  However, there are some 'twinkles' with two chars being modified on the fly and snow sprites floating down the screen into the bottom border.

Pressing 'f' on the keyboard will switch screens to a 'roaring' fireplace, achieved simply be modifying the colour RAM.  I cannot tell a lie: the fireplace screen is Arkanix Labs having a direct dig at Stirring Dragon Games who have released their own Christmas demo with fireplace for the princely sum of $24.99!  The Arkanix Labs demo/fireplace is free!  We don't charge no $$$$$$$$!  ;)

This simple Christmas demo can be downloaded from CSDb here.  You can also download it from this blog here, complete with all the data files and ACME source code!

If you fancy warming yourself using a PETSCII fire, Moloch has created an animated gif of the roaring fire!  See below and click to enlarge!



Tuesday, 17 December 2019

ICC Anon

The 'Intro Creation Competition' over at CSDb is now in full swing and hot on the heels of my last entry, 'Funky Stars', comes another 16k entry from me that I've rather unimaginatively titled 'ICC Anon' which is designed with old 'Compunet' demos in mind.



This intro is thus called because of the simple PETSCII rendition of the 'Guy Fawkes' mask as used by the 'hactivist' group Anonymous.  The PETSCII was pixelled about 6 months ago when testing my screen editor 'ChillED' and ended up being repurposed for this intro.

The music is called 'tiny BONER' because it is a reworked and slightly remixed excerpt of a larger mod called 'Boner' composed by  Marx Marvelous/TPPI.  This SID is 'rare' in that is was composed with a 6581 in mind, rather than my usual 8580 choice, but should sound fine on either chip.

This intro includes my first use of sprites in the top/bottom borders and while there is absolutely nothing amazing going on code wise, it was an interesting exercise in finding out about the limitations of border use.

If you would like to see the intro in action on an emulator or real hardware, it can be downloaded from CSDb here or direct from this blog here.  The download also contains the ACME source code and all work files, including the SID tune in it's Goattracker .sng format.

T.M.R has also written short pieces on his own blog here and on the main C64CD blog here, as well as recording a video of the intro in action.  The video should appear below, but if not can be found on YouTube here.



Saturday, 30 November 2019

Funky Stars

There is an event on CSDb that has become almost annual now called the 'Intro Creation Competition'.  In this compo, entries must be created that could be an intro to something (such as a game crack) and must conform to a certain set of rules which I won't explain here, but if you're interested can be read here.

This competition is one of T.M.R's favourites and, since I've taken to coding on the C64 this past year, he suggested I take part.  I agreed but, not wanting to blacken the Cosine or Arkanix Labs names (C64 groups I'm a member of) in case I came last, I requested that it be released using T.M.R's other 'label', Commodore Crap Debunk (C64CD);  as a result, T.M.R has now made me a C64CD member!

Thus, after a few weeks of coding, pixelling and composing (yes, I did the lot!), C64CD has today released 'Funky Stars'.


This intro is so called because the music within it is a SID cover of an Impulse Tracker tune called 'Funky Stars' (but also know as 'Hybrid Song') by Quazar of Sanxion.

This little project has been quite interesting in the fact that one of the compo rules says that the intro must be 16K or under in the same block of memory.  This is not something I'm used to, so was an interesting challenge, particularly since my Goattracker SID ended up being over 3.5K in size.  Whoops!  To squeeze everything in to the same block, I ended up doing little tricks such as assembling the screen data straight to $0400, amongst other things.  Thanks to T.M.R for his guidance on this!

There was also some new learning here for me.  I've always been fascinated by the use of 'raster bars' on the C64 and although I knew it was something to do with writing colours values to each scanline, I've never previously attempted it until now!

Anyway, enough of the waffle!  If you would like to see the intro in action on an emulator or real hardware, it can be downloaded from CSDb here or direct from this blog here.  The download also contains the ACME source code and all work files, including the SID tune in it's Goattracker .sng format.

T.M.R has also written short pieces on his own blog here and on the main C64CD blog here, as well as recording a video of the intro in action.  The video should appear below, but if not can be found on YouTube here.



Tuesday, 9 July 2019

Unused Shmup Tunes

Inspired by the music selectors that used to appear on C64 magazine cover tapes back in the day and because I had some unused tunes taking up space on my hard drive, I've (funnily enough) coded up a music selector, released today by Cosine!  It's rather awkwardly called 'The Unused Shmup Tune Selector' or 'Unused Shmup Tunes' for short.


The Cosine PETSCII logo was pixelled with and data exported from 'ChillED', a soon to be released C64 cross-dev screen editor.  Although I handled all the code, I must confess I was helped over the code finish line by T.M.R with regards that damned MSB thing.

These tunes, as usual, were composed in Goattracker and were originally planned for use in a shoot 'em up game that T.M.R was "planning" as part of a re-write to his existing assembly language tutorials... but, as is often the case with T.M.R, those tutorials ended up being pushed onto the back burner buy other projects and are currently being rather euphemistically referred to as a "work in progress".  Those are T.M.R's words from the Cosine website, not mine! :D

There's nothing amazing going on here code-wise, but as a relative newcomer to 6502, I'm pleasantly surprised how easy it is to recycle sprites, with up to 24 sprites being displayed on occasion in the logo 'pulse' and star field.

The music selector can be download from this blog here.  The download contains the .prg file to run on a C64 or emulator as well as the ACME formatted source and all binaries and work files, including the music files in their original Goattracker .sng format.

It can also be downloaded from the Cosine website here or from the CSDb here.  If you are so inclined, all the files are also available from GitHub here.

T.M.R has written a short piece about the release on his blog here and recorded a video of the music selector in action and uploaded it to YouTube.  The video should appear below, but if not can be viewed here.





Tuesday, 11 June 2019

PETSCII Doctors

Arkanix Labs has just released a little graphics collection called 'PETSCII Doctors', which features (funnily enough) PETSCII versions of all, at time of writing, 13 Doctors from the BBC television program 'Doctor Who', as well as a PETSCII time vortex effect complete with TARDIS accompanied with a SID rendition of the famous theme tune.


On this occasion, I've handled the code and music, while helping my Grandson, w0rm, learn the ways of C64 by producing PETSCII block renderings of the Doctors in my soon to be released C64 cross-dev screen editor 'ChillED'.  Thanks go to Moloch for continued advice and suggestions.

The whole bundle has been dedicated to T.M.R as a thanks for all his patience while I continue to grapple with 6502 coding.

The graphics collection can be downloaded from CSDb here or direct from this blog here.  Both download locations supply a .zip file containing the collection itself to run on a real C64 or emulator, as well as the 6502 source, binaries and work files.  It is also available on GitHub here.

EDIT: 100bit^NiS has added PETSCII Doctors to Pouët.  Find it here... 

EDIT 2:  It seems someone has taken the time to make a video of this little PETSCII graphics collection and put it up on YouTube.  The video should appear below but if not, it's on the page here...



Wednesday, 20 February 2019

Super Galaxi-I-Birds

In an attempt to further my knowledge and understanding of 6502, I've reworked and added new code to T.M.R's C64 gallery blaster 'Super Hyperzap' and have managed to produced something kind of playable in 'Super Galax-I-Birds', released today by C64 Crap Debunk.


On this occasion, as well as producing the graphics and music, I've taken T.M.R's original 'Super Hyperzap' code and added additional features such as a 'busier' title screen in the style of the early '80's space invader style games, 'get ready' type messages for each player, a 2 player option selectable on the title screen, highest score of the day for each player and a status bar that changes it's information depending on whether the title or game screen is being displayed.

In addition, T.M.R's original 'Super Hyperzap' game used 2 sprites for the player ship with only 6 sprites then available for the 3 types of enemy.  This has been recoded in 'Super Galax-I-Birds' so that the player ship is only 1 sprite, freeing an extra sprite for the now 4 types of enemy.  This has had the effect of making 'Super Galax-I-Birds' slightly more hectic than the game on which it was based.

If the game title sounds familiar, this game is indeed an unofficial sequel of sorts to the (in)famous Sensible Software game 'Galaxibirds', released by Firebird in the mid 1980's.

Again, thanks must go to T.M.R and Moloch for their ongoing help and support during my 6502 journey.

There are a few features that didn't make it in, mainly because this game went about as far as I wanted to take it; towards the end, there was no real learning going on, just 'tinkering' and/or adding things for the sake of adding things.  Better handling of waves, with perhaps only 1 type of Galax-i-bird per wave, a high-score table and more types of bird may appear in a 'deluxe' version in the future!

The game can be downloaded from the CSDb here or direct from this blog here.  Both downloads contain the game itself, along with the source code and all binaries and work files for both the graphics and music.  The game is also on GitHub here.

Prior to release, the completed game was supplied to Moloch to be passed on to Triad for 'cracking'.  Their crack release can be downloaded here.

EDIT: A YouTuber called 'NiftyRetroGamer' has done a recording of 'Super Galax-I-Birds' using both emulation and real hardware, while reviewing the game (quite favourably!).  The video should appear below, but if not it can be viewed here...



Friday, 11 January 2019

Stardust Music

Arkanix Labs has released my small collection of C64 8580 SID tunes called 'Stardust Music' which are covers of music from the Amiga game 'Stardust'.  The original Amiga tunes were written by Risto Vuori.  The SID's have been released within a little music selector featuring a C64 version of the Stardust logo, that I pixelled years ago, and a new charset font in the scroller.


The C64 code to display this was originally provided by T.M.R and was used for some earlier, simple releases.  On this occasion however, I've actually pulled my finger out, learned some 6502 assembler and added code to detect machine type the music is running on (PAL/NTSC/Drean), key detection to be able to select the tunes and sprite display to show various pieces of information.

The machine detection alters the display and the music played, since PAL and NTSC machines run at slightly different speeds.  It was a nice coding challenge.

Special thanks must go to T.M.R and Moloch for their ongoing 6502 coding mentoring, help and support!

The music collection can be downloaded from CSDb here or direct from this blog here.  Both downloads offer a .d64 disk image for C64, both PAL and NTSC SID 8580 files and the music in it's original SNG Goattracker format.  The download from this blog also contains the graphic files in their original formats.

EDIT: Rudi has added an entry for Stardust Music on Pouët here...

EDIT 2:  It seems someone has taken the time to make a video of this little music selector and put it up on YouTube.  The video should appear below but if not, it's on the page here...



Wednesday, 31 October 2018

Old School Demo III

Following on from 'Old School Demo 1' and 'Beast Tribute - Old School Demo 2', comes the cunningly named 'Old School Demo III', released today by Cosine.   The demo was written in response to a challenge issued by the owners of the DBF Interactive website and forum to create something for Halloween 2018.


My main inspiration for the demo was the silhouette image in the hidden part of 'Sabbat', a 2013 Halloween demo released by Arkanix Labs, for which I pixelled and composed most of the assets.

The demo has been released by Cosine and is available to download from the Cosine website here...

You can also download the demo directly here...

The whole caboodle is on GitHub here...

There are a few key presses to find to activate some of the sprites as well as a key combo press to find the hidden part...

I'll follow up shortly with another blog post with a little more detail of how the demo works, how the graphics hang together, how the music was written and so on.

Sunday, 15 April 2018

PureBasic Parallax Starfield

I've always wanted to create a parallax starfield since the days of my C64 game-playing and demo-watching youth, but never had the tools or skills to create one.  Time has come...

After coding a couple of applications in PureBasic, I decided to turn my attention to the graphical abilities of said programming language. Research time and first port of call was the PureBasic forum where I found a few examples, but they were either too old for my version of PureBasic so wouldn't compile, or were overly complicated with lots of added effects that I didn't want or need.

So I decided to go it alone and code a clean and simple routine that I would then be able to 'plug' into other projects if I needed to fill the background with something interesting, as I did with 'Old School Demo 1'.  This is what I came up with to generate a simple 4 layer starfield...

       
;- INITIALISE ENVIRONMENT ------------------------------------

InitKeyboard()
InitSprite()


;- CREATE VARIABLES ------------------------------------------

#XRES = 800
#YRES = 600
#LAYER1SPEED = 1
#LAYER2SPEED = 3
#LAYER3SPEED = 5
#LAYER4SPEED = 10


;- PROCEDURES ------------------------------------------------

Procedure OpenMainWindow()
  
  OpenWindow(0,0,0,#XRES,#YRES,"Parallax Stars!",#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0),0,0,#XRES,#YRES)
  
EndProcedure

Procedure CreateStarfields()
  
  Global sp_BKGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_BKGRDSTAR))
  For n=0 To 999
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(100,100,100))
  Next
  StopDrawing()
  
  Global sp_MDGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_MDGRDSTAR))
  For n=0 To 299
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(150,150,150))
  Next
  StopDrawing()
  
  Global sp_FTGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_FTGRDSTAR))
  For n=0 To 199
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(200,200,200))
  Next
  StopDrawing()
  
  Global sp_CLGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_CLGRDSTAR))
  For n=0 To 19
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(255,255,255))
  Next
  StopDrawing() 
    
EndProcedure

Procedure DrawStarfields()
  
  Shared bgx1, bgx2, bgx3, bgx4
  
  For s1 = 0 To 1
    For s2 = 0 To 1
      DisplayTransparentSprite(sp_BKGRDSTAR,#XRES*s1-bgx1,#YRES*s2)
      DisplayTransparentSprite(sp_MDGRDSTAR,#XRES*s1-bgx2,#YRES*s2)
      DisplayTransparentSprite(sp_FTGRDSTAR,#XRES*s1-bgx3,#YRES*s2)
      DisplayTransparentSprite(sp_CLGRDSTAR,#XRES*s1-bgx4,#YRES*s2)
    Next
  Next
  
  bgx1+#LAYER1SPEED : If bgx1 > #XRES-1 : bgx1=0 : EndIf
  bgx2+#LAYER2SPEED : If bgx2 > #XRES-1 : bgx2=0 : EndIf
  bgx3+#LAYER3SPEED : If bgx3 > #XRES-1 : bgx3=0 : EndIf
  bgx4+#LAYER4SPEED : If bgx4 > #XRES-1 : bgx4=0 : EndIf
  
EndProcedure    


;- BEGIN PROGRAM ----------------------------------------------------       

OpenMainWindow()                            
CreateStarfields()
HideWindow(0,#False)


;- MAIN PROGRAM LOOP ------------------------------------------------  

Repeat
  
  WaitWindowEvent(1)
  ClearScreen(0)
  DrawStarfields()
  FlipBuffers()
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape)


;- EXIT PROGRAM ----------------------------------------------------     

FreeSprite(#PB_All)
CloseWindow(#PB_All)

End

The above code will actually run stand alone; if you compile it in PureBasic, it will open its own window and display the scrolling starfield until you exit by pressing 'escape'.

What is each part of the code doing?

;- INITIALISE ENVIRONMENT ------------------------------------

InitKeyboard()
InitSprite()

This section does what the comment says and initialises the environment - to be able to detect keypresses you must initialise the keyboard and to be able to use any graphics (including sprites) in a window you must initialise the sprite system.

;- CREATE VARIABLES ------------------------------------------

#XRES = 800
#YRES = 600
#LAYER1SPEED = 1
#LAYER2SPEED = 3
#LAYER3SPEED = 5
#LAYER4SPEED = 10

This section creates variables and assigns number values.  Changing the value of #XRES and #YRES alters the size of the window in which the starfield is displayed.  The other variables created control the speed of the scroll of each star layer, in this example 'layer 1' is the slowest to simulate being the furthest away and layer 4 the quickest to simulate being the closest, with layers 2 and 3 being somewhere in between.

Next, I've created some procedures.

;- PROCEDURES ------------------------------------------------

Procedure OpenMainWindow()
  
  OpenWindow(0,0,0,#XRES,#YRES,"Parallax Stars!",#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0),0,0,#XRES,#YRES)
  
EndProcedure

This first procedure opens a window on the users screen with the size of #XRES and #YRES, with a title "Parallax Stars!" and centres the window in the users display.  It then opens a 'windowed screen' in this window which enables the use of powerful graphic commands that display images and sprites really quickly, enough so to create fast demos and games.

Procedure CreateStarfields()
  
  Global sp_BKGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_BKGRDSTAR))
  For n=0 To 999
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(100,100,100))
  Next
  StopDrawing()
  
  Global sp_MDGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_MDGRDSTAR))
  For n=0 To 299
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(150,150,150))
  Next
  StopDrawing()
  
  Global sp_FTGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_FTGRDSTAR))
  For n=0 To 199
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(200,200,200))
  Next
  StopDrawing()
  
  Global sp_CLGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
  StartDrawing(SpriteOutput(sp_CLGRDSTAR))
  For n=0 To 19
    Plot(Random(#XRES-1),Random(#YRES-1),RGB(255,255,255))
  Next
  StopDrawing() 
    
EndProcedure

This next procedure then creates 4 sprites 'on the fly' and then randomly fills them with dots pretending to be stars.  Each sprite is held in a named variable starting with 'sp_' to indicate it's a sprite plus a name to indicate it's level in the display, so 'BKGRDSTAR' is the background layer, 'MDGRDSTAR' being the mid layer and so on.  This is my naming convention, you could call the sprite whatever you like.  Each sprite is created the same size as the window (#XRES, #YRES).

When randomly filling with dots, the closer the layer the fewer the number of dots (n). Also, since the background stars would be further away they are darker, RGB(100,100,100), while the closest layer is brighter, RGB(255,255,255).

Procedure DrawStarfields()
  
  Shared bgx1, bgx2, bgx3, bgx4
  
  For s1 = 0 To 1
    For s2 = 0 To 1
      DisplayTransparentSprite(sp_BKGRDSTAR,#XRES*s1-bgx1,#YRES*s2)
      DisplayTransparentSprite(sp_MDGRDSTAR,#XRES*s1-bgx2,#YRES*s2)
      DisplayTransparentSprite(sp_FTGRDSTAR,#XRES*s1-bgx3,#YRES*s2)
      DisplayTransparentSprite(sp_CLGRDSTAR,#XRES*s1-bgx4,#YRES*s2)
    Next
  Next
  
  bgx1+#LAYER1SPEED : If bgx1 > #XRES-1 : bgx1=0 : EndIf
  bgx2+#LAYER2SPEED : If bgx2 > #XRES-1 : bgx2=0 : EndIf
  bgx3+#LAYER3SPEED : If bgx3 > #XRES-1 : bgx3=0 : EndIf
  bgx4+#LAYER4SPEED : If bgx4 > #XRES-1 : bgx4=0 : EndIf
  
EndProcedure  

This next procedure draws the actual sprites (starfields) on the screen when this procedure is called later in the code.  The sprites are drawn in 'transparent' mode, whereby everything that is black is transparent so shows everything underneath.  Therefore, the stars (dots) on each sprite layer are always visible.

Each sprite layer is moved sideways using the #LAYERSPEED variables, with each layer moving a set number of pixels defined by that variable.  The sprites loop around continuously when they have scrolled their #XRES limit.

;- BEGIN PROGRAM ----------------------------------------------------       

OpenMainWindow()                            
CreateStarfields()
HideWindow(0,#False)

Now the program begins to actually execute by calling the 'OpenMainWindow()' procedure to open a window, generate the sprites by calling the 'CreateStarfields()' procedure and then unhides the window so we can see it, if it was hidden in the 'openwindow' procedure (which in this example it actually isn't).

;- MAIN PROGRAM LOOP ------------------------------------------------  

Repeat
  
  WaitWindowEvent(1)
  ClearScreen(0)
  DrawStarfields()
  FlipBuffers()
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape)

The code now enter a continuous loop where it waits for a window event, clears the screen each frame, draws the starfields in their new positions, flips to the second prepared screen where the drawing of starfields has taken place out of view to ensure smoothness, then checks the keyboard to see if the user has pressed 'escape'.

;- EXIT PROGRAM ----------------------------------------------------     

FreeSprite(#PB_All)
CloseWindow(#PB_All)

End

If the user pressed space, then the program loop exits, erases all sprites and closes the window.  Technically, the 'End' command does this automatically but I like to be thorough.

This code can easily be adapted to make the stars scroll the opposite direction, or even up/down.

If you want the raw code to copy and paste into PureBasic, grab it from Pastebin here...

Friday, 6 April 2018

Old School Demo 1

Here's a first!   I've coded my first ever PC based demo primarily to test the screen and sprite capabilities in PureBasic

The demo is titled 'Old School Demo 1' because it's, er, old-school in style and is the first in what may end up being a small string of demos that I may (or not) code as I learn more in PureBasic.



I've tried to 'emulate' some of my favourite features from the old Amiga demos so on screen you will see a scrolling parallax starfield, some 'copper bars' (faked of course), some animated rainbow coloured lines, the obligatory bouncing scrolling message and music which is actually a remix of the Uridium 2 loading music done by the original composer Jason Page.

The demo has been released by Cosine and is available to download from the Cosine website here...

You can also download the demo directly here...

As well as the demo itself, the download contains the PureBasic source code for you to squint at and rip apart.  Well, someone may find it useful?

Sunday, 25 June 2017

PureBasic Array Flood Fill

PureBasic CartographPC - Click to Enlarge
I'm coding a mapping application in PureBasic for my group Arkanix Labs, that will be used to produce maps for a C64 RPG called 'Crimson Twilight'.

Actually, a mapping application already exists called 'CartographPC', produced by Arkanix Labs to do just that job, but it is coded in VisualBasic 6, itself no longer supported by Microsoft and increasingly difficult to run on more modern OS's.

At some point (and I can't remember when or why), I started rewriting the application in PureBasic.  All the basic features are included so far, but then it was suggested that I add a 'flood fill' feature to randomly fill areas of the map with selected graphics, to produce random looking patches of dirt, grass, paths and so on, without having to manually fill whole areas.  Hmmm...  flood fill.

A bit of research on the internet about flood fill turned up quite a few theories, the most common being 'recursion'.  Basically, a routine repeatedly calls itself until a certain stage is reached at which point the routine exits itself.

In CartographPC (at least in the PureBasic version) the map data is held in an array, so I needed to find a way to fill an array with certain numbers (which represent graphic blocks) which observed other existing graphics and potential boundaries such as the edge of the map or enclosed area.  To the more seasoned coder, this may present no issue, but I'm new(ish) to PureBasic coding so it was a bit of a challenge and this is what I came up with:


Procedure floodfill(x, y)
  
If a_MAPDATA(x, y) <> blnkchar
 ProcedureReturn 0
EndIf
  
If a_MAPDATA(x,y) = blnkchar
 rnd = Random(rancharsel)
 rnd = rnd - 1
If rnd < 0
 rnd = 0 
EndIf
 a_MAPDATA(x, y) = a_RNDCHARS(rnd)
EndIf
  
If x > 0  ; fill left
 floodfill(x - 1, y)
EndIf
  
If y > 0 ; fill up
 floodfill(x, y - 1)
EndIf
  
If x < mcw ; fill right
 floodfill(x + 1, y)
EndIf
  
If y < mch ; fill down
 floodfill(x, y + 1)
EndIf
 
EndProcedure


The routine is contained in a 'procedure' called 'floodfill(x, y)' that can be called from the main program.  A quick explanation of some of the things in the code above:

  • a_MAPDATA(x, y) is my array holding the map layout with 'x' and 'y' being a location in the 2D array (matrix).
  • 'blnkchar' is a variable which holds the number of the graphic block which is 'blank' on the map.
  • 'rancharsel' is a variable containing the number of graphic blocks the user wants to use in the random fill.
  • a_RNDCHARS(rnd) is an array that contains the graphic blocks the user wants to use in the flood fill.
  • 'mcw' and 'mch' are variables holding the width and height of the map.

So what does each part of that routine do?

If a_MAPDATA(x, y) <> blnkchar
 ProcedureReturn 0
EndIf

The above is the base case which basically says that if the map or area being filled is no longer 'empty', then exit the procedure, or in PureBasic terminology 'ProcedureReturn 0'.

If a_MAPDATA(x,y) = blnkchar
 rnd = Random(rancharsel)
 rnd = rnd - 1
If rnd < 0
 rnd = 0 
EndIf
 a_MAPDATA(x, y) = a_RNDCHARS(rnd)
EndIf

This section checks if the element of the array we are currently on is empty (blnkchar) and if so, it generates a random number (rnd) between 0 and the number variable held by 'rancharsel'. The element in the map array is then changed to contain the number held in the random chars array (previously filled with graphic blocks selected by the user) at position 'rnd'.

If x > 0  ; fill left
 floodfill(x - 1, y)
EndIf

Now some magic (at least in my eyes) starts to happen.  The above checks to see if we are at the far left of the array and therefore map (x > 0).  If not, our 'x' position in the array is moved left (x -1) and the procedure returns to the beginning to change the map array and draw a graphic block on the map.  If we are at the far left of the array / map (x = 0), then we proceed to the next section in the procedure.

If y > 0 ; fill up
 floodfill(x, y - 1)
EndIf

Now we start moving up the map / array, checking and drawing until our 'y' position is '0', the top of the map.  Each time the routine loops around, it check left in the array first and then up in the array.  But of course, we could also move right or down in the array until we reach the far right or bottom of the map / array.  This is checked by the following:

If x < mcw ; fill right
 floodfill(x + 1, y)
EndIf
  
If y < mch ; fill down
 floodfill(x, y + 1)
EndIf

So each time the routine loops, the array is checked left, up, right then down from the current position.  If the drawing was updated on the screen slowly for every graphic block, which in the application it isn't because that would be too slow, the fill would snake around the screen up, left, right and down until boundaries or existing graphics are encountered, eventually leading to the array / map being filled with the desired graphics.

I'm sure that more seasoned coders could refine the code further and make it better / more efficient, but in this state it works for my application and that is fine by me!

If you want the raw code to copy and paste into PureBasic, grab it from Pastebin here...

Sunday, 16 May 2010

Hex Files Advert

There is a discussion currently going on in a private area of the Arkanix Labs forum, where Warlock is discussing some ideas for a demo that he will produce while learning to code on the C64.  Moloch has pointed him to the Hex Files tutorials written by T.M.R.

I have seconded that suggestion, pointing out that even I was able to create something!  And then I realised that the little demo I made is not mentioned anywhere other than the OldSchool Gaming website forum.  Guess I need to write about it then, since that's the idea of this blog!

Introducing the 'Hex Files Advert' from 2008...


The idea for this simple demo was to create an 'advert' for the tutorial used to create it.

As well as being on coding duties for a change, I also pixelled the bitmap image, sprites and the 'font' charset.  The music is by AumTRoN.  When I say I was on coding duties, I obviously followed the tutorial, modifying it along the way because I wanted the scroller at the bottom of the screen, along with a few other small changes.

To be honest, I did get a little stuck with trying to remove an annoying flicker caused by the scroller, so Trooper was very helpful with tidying up my code and T.M.R obviously needs credit since he wrote the original tutorial code!

As a result, the demo scroller credits code to Trooper and T.M.R, leaving me out because I felt a little sheepish crediting myself when I was basing it all on the work of somebody else!  This was a last minute decision/change, so if you take a look as the source it actually still credits code to me also.

Look at the source?

You can download the source, bitmap, chars, sprites and other files, along with a C64 disk image containing the final demo here...