Roguelike for the beeb. In BASIC.

Got a programming project in mind? Tell everyone about it!
User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Roguelike for the beeb. In BASIC.

Postby sydney » Tue Sep 26, 2017 9:47 am

Someone on Facebook asked whether or not there were any roguelike games on the beeb and the answer seemed to be no though I did find one - I'll post a link later when I re-find it! I also found a 10 liner for the atari xl computers which I looked at and decided it wasn't really what I'd want from a roguelike so I decided to have a go at writing one myself.

I initially started writing in assembler because thats what I've been learning for the past few years and I've got a small amount done but it dawned on me that the game is perfectly suited to being written in BASIC so why not have a go? I've not really used BBC BASIC since bitd when I was 10 years old so I've got some learning to do!

Memory is probably going to be the biggest problem so from the start I decided to make it as modular as possible. I'm going to have 4 or 5 separate programs which load and run each other when needed:
ROGUE - the loader which creates the variables and tables in memory. This is run only once.
INTRO - displays a welcome message and clears the variables and tables. This is run after ROGUE and at the end of every game.
MAPGEN - populates the memory set aside for the level data, monsters, player and anything else that needs to be done before starting the game. This is run at the start of every level.
GAME - gets input, moves player, moves monsters, displays level - plays the game! Loads MAPGEN when a level is complete, loads INTRO when the player dies.

Just spotted an issue typing that up as the clearing of the tables needs to happen between levels so will need to be moved into MAPGEN.


I decided to load the game in this way before being told about 'overlaying' here, so I'm going to stick with this rather than changing what I've already done. I'm mostly using the resident variables, A% to Z%, as they are persistent between loading BASIC programs. One issue I had - which is solved with the overlaying technique - was that ROGUE is a small program so the memory I was reserving with DIM was being overwritten by later programs and these programs were then overwriting themselves because the memory set aside was low down in the memory map. I've overcome this by moving HIMEM down enough to hold the level data and using some less frequently used memory below &0E00 for other tables.

So far I have the map generation mostly working and I'm currently working on linking the rooms with passages. After that I'll get the player working, then other pick-ups like scrolls and weapons etc, then monsters, then work on hiding undiscovered parts of the level.

Eventually I want to make a VideoNuLa compatible version using one of the new attribute based screen modes to bring a bit of colour to it.

Right! Back to work!

EDIT: A screenshot!
BASICrogue.png

User avatar
leenew
Posts: 3329
Joined: Wed Jul 04, 2012 3:27 pm
Location: Doncaster, Yorkshire

Re: Roguelike for the beeb. In BASIC.

Postby leenew » Tue Sep 26, 2017 10:14 am

Nice idea Simon.
Have you seen this? http://www.phlamethrower.co.uk/riscos/batr.php
We only just discovered it.
Also White Barrows by ASP may be roguelike-like..

Lee.

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Tue Sep 26, 2017 10:22 am

leenew wrote:Nice idea Simon.
Have you seen this? http://www.phlamethrower.co.uk/riscos/batr.php
We only just discovered it.
Also White Barrows by ASP may be roguelike-like..

Lee.


Yes Lee. That is the one I found but I didn't play it. I want mine to be more like the original rogue with up to nine rooms linked by passages with monsters and scrolls and potions etc. Also it's in mode 1 giving only 40 characters width but I'll be using mode 0 which is more like the original.

User avatar
leenew
Posts: 3329
Joined: Wed Jul 04, 2012 3:27 pm
Location: Doncaster, Yorkshire

Re: Roguelike for the beeb. In BASIC.

Postby leenew » Tue Sep 26, 2017 12:03 pm

Sounds good. I also agree that this sounds like an ideal BASIC project. :D
Lee.

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Tue Sep 26, 2017 5:08 pm

I've just ran into my first 'No room' error.
I was fully expecting this because I'm using a modern text editor and beebasm to develop it and I'm being liberal with comments, whitespace and variable/procedure names. I wrote a small batch file to add linenumbers to my source before passing them on to beebasm with it's putbasic command.
I've just manually removed most of the comments and blank lines and there is plenty of memory left once this is done but it makes the source awful to read. I've had a quick google for a program to remove the REM's and white space but I doubt there is a tool that will do what I need so I'm probably going to have to roll my own.
At first I'm just going to remove lines only containing REM's, blank lines and spaces at the start of a line. I'll leave everything else until I reach the next 'No room' event.

User avatar
leenew
Posts: 3329
Joined: Wed Jul 04, 2012 3:27 pm
Location: Doncaster, Yorkshire

Re: Roguelike for the beeb. In BASIC.

Postby leenew » Tue Sep 26, 2017 5:26 pm

Does Pres BASIC editor do this?
Lurkio may know as he has been packing a few programs lately with it...

Lee.

cmorley
Posts: 213
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: Roguelike for the beeb. In BASIC.

Postby cmorley » Tue Sep 26, 2017 5:43 pm

Are you using a model B? You could use one of the OS shadow RAM modules I made & put your verbose program at &C000 while you are developing and debugging (15kB code space) with the variables in main memory. Then shrink it/optimise for space/massage PAGE etc when you've got it working.

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Tue Sep 26, 2017 7:51 pm

leenew wrote:Does Pres BASIC editor do this?
Lurkio may know as he has been packing a few programs lately with it...

Lee.

There are lots of beeb based tools to do this but I don't want to have to start doing stuff in the emulator, I'd like to keep it all PC based just to keep it simple.

cmorley wrote:Are you using a model B? You could use one of the OS shadow RAM modules I made & put your verbose program at &C000 while you are developing and debugging (15kB code space) with the variables in main memory. Then shrink it/optimise for space/massage PAGE etc when you've got it working.


I'm doing it all on a PC. You'll be getting an email from my wife sometime before christmas about those modules and the SRAM and EEPROM ones too.

SteveF
Posts: 429
Joined: Fri Aug 28, 2015 8:34 pm

Re: Roguelike for the beeb. In BASIC.

Postby SteveF » Tue Sep 26, 2017 7:53 pm

Nice idea, the screenshot looks good already!

I can see the appeal of writing something which runs on a standard machine, but have you considered writing it under HiBASIC? You get 44K for code and data without any need to be clever that way. (But I can see that being clever and squashing it into memory might well be part of the fun anyway.)

I ported David Schmenk's Apple roguelike to the BBC as part of my PLASMA port; you can see it at viewtopic.php?f=55&t=12306#p159013 That won't currently run on a standard BBC B; you need a second processor or a Master 128.

crj
Posts: 129
Joined: Thu May 02, 2013 4:58 pm

Re: Roguelike for the beeb. In BASIC.

Postby crj » Tue Sep 26, 2017 10:03 pm

Another option during development is the version of BBC Basic that runs in main memory and stores the program in 64Kbytes of sideways RAM.

I'm not imagining that, am I? I forget what it's called.

User avatar
BigEd
Posts: 1390
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Roguelike for the beeb. In BASIC.

Postby BigEd » Wed Sep 27, 2017 3:28 am

Is that BAS128?

crj
Posts: 129
Joined: Thu May 02, 2013 4:58 pm

Re: Roguelike for the beeb. In BASIC.

Postby crj » Wed Sep 27, 2017 5:34 am

That's the one, yes.

User avatar
DutchAcorn
Posts: 1583
Joined: Fri Mar 21, 2014 9:56 am
Location: Maarn, Netherlands

Re: Roguelike for the beeb. In BASIC.

Postby DutchAcorn » Wed Sep 27, 2017 6:16 am

crj wrote:Another option during development is the version of BBC Basic that runs in main memory and stores the program in 64Kbytes of sideways RAM.

I'm not imagining that, am I? I forget what it's called.

There are limitations and differences with Basic2. See this acorn note: "Using BAS128 on the Master 128 and Master".
Paul

User avatar
daveejhitchins
Posts: 3617
Joined: Wed Jun 13, 2012 5:23 pm
Location: Newton Aycliffe, County Durham

Re: Roguelike for the beeb. In BASIC.

Postby daveejhitchins » Wed Sep 27, 2017 8:15 am

I had similar problems to Simone e.g. No Room Error, when writing the MGC Menu. I chose to use BeebEM, on my MacBook, as I could do that anywhere - even in the caravan :D Shadow Mode, Mode 0 and ABE (Advanced BASIC Editor) along with the ABEs in-built Utilities gives me a good working environment. And secure, as I can back-up BeebEm's hard drive and the Mac's hard drive.

One thing I found that ABE's PACK utility doesn't remove is ':' Colons. I use them as line spacers (I know, I could just use a blank line! OCD!). To remove the Colon Line spacers and not Colons between statements I just use ':***', as line spacers, then carry out a global search-and-replace. ABE is, probably, one ofthe best packers - not that I've used all available packers for comparison, though!

The original Probe6 by Altra (that ABE is derived from), has a Tube version, which would give more memory. I've not found this, however. Does anyone have a copy?

Another drawback, using BeebEm, is I can't get all the keys remapped, so lose some functions. I've not managed to get BeebEm4 working, yet (need some guidance <please>!)

I suppose ABE's editor isn't as versatile as a PCs text editor e.g. no cut-and-paste etc. IMO BeebEm is easier and probably quicker to test your code, though, as you're already in the correct environment!

Dave H :D
Parts: UM6502CE, GAL22V10D, GAL16V8D, AS6C62256A, TC514400AZ, WD1772, R6522, TMS27C512, AT28C256
Products: ARA II, ABR, ATI, AP6, MGC, AP5 . . .
For a price list, contact me at: Retro Hardware AT dave ej hitchins DOT plus DOT com

User avatar
lurkio
Posts: 1142
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Roguelike for the beeb. In BASIC.

Postby lurkio » Wed Sep 27, 2017 3:14 pm

daveejhitchins wrote:Another drawback, using BeebEm, is I can't get all the keys remapped, so lose some functions. I've not managed to get BeebEm4 working, yet (need some guidance <please>!)

What problems are you having exactly? Is the following thread of any help?:

:?:

crj
Posts: 129
Joined: Thu May 02, 2013 4:58 pm

Re: Roguelike for the beeb. In BASIC.

Postby crj » Wed Sep 27, 2017 4:58 pm

DutchAcorn wrote:There are limitations and differences with Basic2.

Most of those are differences from Basic IV, not Basic II.

If the intention is to have this able to work in older machines without shadow memory, most of those features wouldn't be available anyway.

The problems with assembly language crossing bank boundaries are also not an issue unless one is writing assembler.

The one problem that I'd say is major, possibly even show-stopping, is that it's much slower than normal Basic.

User avatar
marcusjambler
Posts: 85
Joined: Mon May 22, 2017 11:20 am
Location: Bradford
Contact:

Re: Roguelike for the beeb. In BASIC.

Postby marcusjambler » Wed Sep 27, 2017 10:39 pm

Perhaps this is an opportunity to make use of the RPI copro...
Plenty space there and it would be making use of the new developments
Just a thought... 8)

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Fri Sep 29, 2017 9:59 pm

I've got my little crunch program working enough to save enough space to continue, MAPGEN.BAS shrank from 5084 bytes to 3247 an 1800 byte saving and there are plenty more savings to be made if necessary.

I've got a rudimentary path generator working which should be fine as long as I don't get a level with less than 5 rooms - which I shouldn't, but do - or with 5 rooms in an X formation which would leave the centre room unconnected. I might check for this and add an extra path or room to prevent this.
It works by stepping through each room in a row and connecting it to the room to its right, if one doesn't exist it tries to connect to the room further right, then doing the same for each column connecting down. This means every room is connected but there are no dead ends. I'm going to fully comment the code so that when I come back to it I'll be less confused than I was this afternoon.

One problem I seem to have is that everytime I launch beebem I get the same run of levels produced. Is there a way to make the random numbers more random?

Another screenshot:

rogue2.png

User avatar
Lardo Boffin
Posts: 594
Joined: Thu Aug 06, 2015 6:47 am

Re: Roguelike for the beeb. In BASIC.

Postby Lardo Boffin » Fri Sep 29, 2017 10:11 pm

It's a kludge but if you wait for the user to press a key before the level is created ('press space to start') then in the key press wait loop you can continually generate random numbers and the last one generated will be used when space is pressed and the level created.

If that makes sense...
BBC model B 32k issue 4, 16k sideways RAM, Watford 12 ROM board, Retroclinic Datacentre + HDD, matchbox co-proc, Viglen twin 40/80 5.25" discs, acorn cassette
BBC model B 32k issue 7, turboMMC, Opus Challenger 3 512k, Pi 3 coproc, Acorn 6502 coproc

User avatar
danielj
Posts: 5118
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester

Re: Roguelike for the beeb. In BASIC.

Postby danielj » Fri Sep 29, 2017 10:20 pm

Or use TIME to seed the random number generator?

d.

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Fri Sep 29, 2017 10:22 pm

danielj wrote:Or use TIME to seed the random number generator?

d.


How'd I do that then? I had a look in the user guide but it wasn't much help.

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Fri Sep 29, 2017 10:32 pm

Just reread the user guide and the BBC BASIC 4 windows help site and I presume it'll be like this:

Code: Select all

RND(-TIME)


Nope! It's:

Code: Select all

X=RND(-TIME)

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Sat Sep 30, 2017 11:06 am

Looking pretty good now! I'm off work Monday and Tuesday so with any luck should have something playable next week.
Keyboard controls next then it'll be time to look at displaying it properly, hiding undiscovered part of the level until you get to them. Monsters, treasure and other items will just have to wait.

ROGUE3.png

User avatar
sydney
Posts: 1964
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Roguelike for the beeb. In BASIC.

Postby sydney » Tue Oct 03, 2017 12:48 pm

sydney wrote:...I'm off work Monday and Tuesday so with any luck should have something playable...


Here is something playable! I'm stretching the definition of 'playable' a bit but you can move your character around the level to the exit and go down the stairs to the next level.

It is SLOW. Particularly when clearing memory between levels and generating a new level. I can probably rewrite this part faster using BASIC but if it's still too slow I may end up using assembler here.

You may need to press CAPS LOCK when the game loads as the game checks for lower case input - it's how the original works.
Your character is the '@' and the staircase is '>'.
Keys are the same as the original rogue:
h - left
j - down
k -up
l - right
> - down staircase - you may need to use shift to generate the '>' character - I've not tested on a beeb yet only beebem.

Next on my list is to have only parts of the level you have visited visible so that you get the feeling of exploring an unknown dungeon.
Attachments
beebrogue.zip
(2.96 KiB) Downloaded 13 times


Return to “projects”

Who is online

Users browsing this forum: No registered users and 2 guests