SpecBAS program under development

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

SpecBAS program under development

Post by llewelyn »

After a tremendous amount of help from ASH-II and ZXDunny here's the moon lander program I spoke about some days ago.

It's a work in progress and I cannot take credit for this because without those chaps I might never have got this far. However, its rather nice albeit short and sweet but there's more features yet to be implemented. Use the arrow keys to steer the lander left or right but the descent is unstoppable.

First my version:-

SpecBAS PROGRAM:- Longlander4

5 REM Preset window size
10 SCREEN WINDOW 1024,728
15 REM Make memory bank for graphic
20 GRAPHIC NEW mygfx LOAD "moon2.png"
25 REM remap pic palette to SpecBAS's
30 GRAPHIC REMAP mygfx
35 REM put picture starting at top left
40 WINDOW PUT GRAPHIC mygfx,0,0,0
45 REM increase size of 0 lander icon
50 SCALE 2,2
60 REM
70 REM Program LONGLANDER4
80 REM Set up variables first
90 REM x and y = start position of lander
100 LET x=5: LET y=19
120 PRINT AT x,y;"O":
125 REM Yellow engine flame
130 INK 6: PRINT AT x+1,y;"^":INK 0
135 REM ALWAYS have a stop
140 IF x=37 THEN STOP
500 REM potential subroutine DESCEND
505 REM slow down rate of descent
510 WAIT 300
515 REM erase previous position of lander
520 PRINT AT x,y;" "
525 REM next 2 lines give left/right move
530 IF KEYST KEY_LEFT THEN DEC y,1
540 IF KEYST KEY_RIGHT THEN INC y,1
545 REM add 1 to descent
550 let x= x+1
560 GO TO 120


And now here's ASH-II's somewhat more compact version! Boy is that sweet!

10 SCREEN WINDOW 1024,728:GRAPHIC NEW m LOAD "moon2.png": GRAPHIC REMAP m
50 SCALE 2,2:x=5;y=19
120 WINDOW PUT GRAPHIC m,0,0,0:? AT x,y;TRANS 7;INK 15;"O";AT x+1,y;INK 14;"^"
140 IF x=37 THEN STOP
530 IF KEYST KEY_LEFT THEN DEC y,1
540 IF KEYST KEY_RIGHT THEN INC y,1
550 INC x:wait 300:GO TO 120
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny »

Very nice :)

Please include a link to the graphics you're using - I'd like to see this in action. It may, when you're ready, even be included (with full credit) as a demo.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS program under development - Link to image

Post by llewelyn »

https://ibb.co/jbxvpJp

Okay heres the image Paul.

I wish I knew how to turn a running program into a video so I could put it up on my YouTube channel and show my other friends what it looks like.

Mind you, it would be hardly worth a glance were it not for your SpecBAS fractal demo that I stole that image from!

Oh and a question (what else is new?) When you create a memory bank for a graphic, can it only hold the one and must you create a fresh bank for every new image?

EDITED DUMB QUESTION! the earth doesnt appear to either move or spin.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development - Link to image

Post by ZXDunny »

llewelyn wrote: Mon Sep 02, 2019 5:02 pm I wish I knew how to turn a running program into a video so I could put it up on my YouTube channel and show my other friends what it looks like.
There are several free recording solutions on the web - though I use the built-in one in Windows 10 - it works pretty well.

Like this one:

https://www.youtube.com/watch?v=1mjwLD6juB8
Oh and a question (what else is new?) When you create a memory bank for a graphic, can it only hold the one and must you create a fresh bank for every new image?
You need one bank per graphic. You can have as many banks as you like (well, about 140 million of them) so don't worry about running out of room. SpecBAS has the whole of your PC's memory to play with (more, in fact) so have at it.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

SpecBAS program almost complete

Post by llewelyn »

Gosh Paul that's brilliant!

I typed in the listing shown at the start of the video and discovered that not only can it now rise under power but its got bloody inertia too!

So I can see a bit of studying ahead of me (not tonight cos its my wife's birthday) to figure out exactly how it (it being all the features) were implemented.

There's a lot there that's new to me, things like joining two terms (such as KEY_LEFT) and a few more examples of unusual terminology but it all makes sense being in English which is why I've doggedly persisted with Basic all these years.

One does at least stand a fighting chance of deciphering it.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny »

I look forward to discussing it with you - taking apart other people's programs and studying how they work is the fastest way to learn to code.

Most of the variable names should be pretty obvious (if abbreviated in places). looking up what commands do that you're uncertain of will help. The "joining two terms" part has been explained before, but you might not recognise it. Hint - everything in programming is numbers. And that goes for everywhere you might scratch your head in puzzlement.

the "x+=y" bits are a kind of shorthand for "LET x=x+y". SpecBAS lets you omit the LET.

Anyway. Let's see how much you understand, and what you do with it.
ASH-II
Drutt
Posts: 11
Joined: Sun Jun 16, 2019 11:48 am

Re: SpecBAS program under development

Post by ASH-II »

Stick in some random landing pads and you have a game :)
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny »

ASH-II wrote: Tue Sep 03, 2019 6:32 am Stick in some random landing pads and you have a game :)
I'm gonna use this to teach Mike about some of the more fun aspects of getting a game going on a PC :)

For landing pads, you've got two issues - firstly, how to identify something as a landing pad when using an image of a moon surface, and secondly... Collision detection!

On the speccy, you have attributes to check and SCREEN$ as another method of detecting characters (which falls over on UDGs, which SpecBAS doesn't). But how about using a sprite and collision routines? Or maybe a second window holding a mask of the landscape and using POINT? So many possibilities.

But there's also the issue of inertia to make it more fun (I've started on that but it's really simple and needs to be more... elegant).

Also code style - when to use a direct colour command and when to embed them - using functions (FN) to do common tasks - say we have thrust in both the x and y axes, we could do flames to the sides as well as below so the colour could be a function call instead of an expression duplicated for both types...

SO MANY POSSIBILITIES, it's quite exciting really.


P.S - ASH-II: TRANS 7 is the same as TRANS 1. The transparent font command TRANS is either on or off. If it's on, then PAPER isn't drawn for the following characters, and only applies for mono fonts (colour fonts have their own transparent index in the font bank they inhabit).
ASH-II
Drutt
Posts: 11
Joined: Sun Jun 16, 2019 11:48 am

Re: SpecBAS program under development

Post by ASH-II »

P.S - ASH-II: TRANS 7 is the same as TRANS 1. The transparent font command TRANS is either on or off. If it's on, then PAPER isn't drawn for the following characters, and only applies for mono fonts (colour fonts have their own transparent index in the font bank they inhabit).
Ahh right , I wondered why TRANS 0 wasn't working for the font black background but TRANS 7 did, confused it with sprites...MUST REMEMBER THAT.

you could also add random UDG landing pads and just use x,y to detect the pads or even ZONE for an area on top of the pads???

if you wanted it like Lunar Lander you need to magnify when the lander is closer to the moons surface (so a WINDOW GRAB and PUT with SCALE)

(If you read Mikes blog you need to add a rotating Earth as well) :o :o :o :D
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS program under development

Post by llewelyn »

I'll probably need a couple of days breathing space to figure out and assimilate everything you have shown me, Paul and Ash.

Fallen behind in my studies and need to go back to the beginning and start over because I made or accepted changes without stopping to think about how it was done. You won't learn just by cutting and pasting code, its more useful to experiment with various commands, alter variables, see the results.

ASH forget the rotating earth! Apparently its so slow that an observer on the moon would never notice and it also stays in the same place on the horizon. Mind you nobody says it has to be our moon or even our solar system! It would be a cool feature and add a bit of sparkle to the look of the thing.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny »

llewelyn wrote: Tue Sep 03, 2019 2:01 pm ASH forget the rotating earth! Apparently its so slow that an observer on the moon would never notice and it also stays in the same place on the horizon. Mind you nobody says it has to be our moon or even our solar system! It would be a cool feature and add a bit of sparkle to the look of the thing.
Did you see the spinning globe demo in SpecBAS's demo folder? :D

https://www.youtube.com/watch?v=0EGDJybA_HE

But yeah, that would likely be overkill. Many games on the Speccy (such as Earthlight, Nodes of Yesod) had a static image of the earth in the background. All considerations of exposure aside, it looks good with stars in the background.

I know you were worried about the background being erased, but SpecBAS can help there too - the demo video I posted keeps the moon surface intact if you look closely... Have you ever considered instead of simply erasing the lander with empty space, you might erase the lander by restoring the background? If you read the source closely, you might see how it's done. And that's just one method, there are at least two others I can think of!
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS program under development

Post by llewelyn »

I have encountered a few problems trying to load DEMOS - following the instructions given in the 'Installing SpecBas' text file, I types in LOAD"" and got the file requester with / showing in the bar. So I typed in the route to my DEMOS files which is:-

C:\Users\dench\Downloads\SpecBAS\demos\demos

That wasn't acceptable. I tried a couple of other tricks mostly old DOS like CD\ but nothing worked.

However, more interesting discoveries, when I went to the demos folder manually and started to examine each one via Notepad expecting to get something I could copy and paste into SpecBas, some come up as rubbish!
EXAMPLE from Toys - Filename UNIVERSE - I have cut out most of it left just enough to show you:

ZXBASICÿÿÿÿ& K
1 "MU" Model Universeÿÿÿÿ ÿºÉN
4 (C) W.R.Masefield 1983ÿÿÿÿ ÿ°I4P
6 Enhanced by ZXDunny 2012ÿÿÿÿ ÿ4kl\L
( . î Àr@ 300ÿÿÿÿ Àr@ Ù ÿ‹$G‘“
2 A X † : u MODEL UNIVERSE: u ÿÿÿÿ :# MODEL UNIVERSE u 6 : 8 u ÿ{6'÷¬

It's not the only file that comes up like that, I got a couple more but figured better to ask you whats going on.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny »

llewelyn wrote: Wed Sep 04, 2019 1:06 pm I have encountered a few problems trying to load DEMOS - following the instructions given in the 'Installing SpecBas' text file, I types in LOAD"" and got the file requester with / showing in the bar. So I typed in the route to my DEMOS files which is:-

C:\Users\dench\Downloads\SpecBAS\demos\demos
You've installed them in the wrong place. SpecBAS will look in:

C:\Users\dench\SpecBas\

which is the folder you can see right now in the file requester. You've popped your demos into your downloads folder. See below for a rational explanation for this.
However, more interesting discoveries, when I went to the demos folder manually and started to examine each one via Notepad expecting to get something I could copy and paste into SpecBas, some come up as rubbish!
EXAMPLE from Toys - Filename UNIVERSE - I have cut out most of it left just enough to show you:

It's not the only file that comes up like that, I got a couple more but figured better to ask you whats going on.
They're very very old demos from back when SpecBAS used a kind of binary file format for programs. It will load just fine, and if you re-save it then it will revert to text that you're familiar with. I should probably update them all at some point :)


Rational explanation time!

Back in the grim and murky days of Windows 95, applications could be installed anywhere and they could write their files anywhere they liked. Obviously from a security point of view, this is unacceptable. Starting with WinXP (albeit poorly) they started restricting where apps could write to.

Most programs are installed to c:\program files(x86)\ which is now a protected folder in Windows 10. Which means that SpecBAS, although it can see into that folder, cannot write to it without administrator permission. This causes all sorts of headaches, and now Microsoft offers a solution straight out of the Unix/Linux playbook - programs can only write to certain places inside the User's own folder. The can do what they like in there, with no fear of screwing up the whole Operating System if one goes nuts.

SpecBAS therefore creates a folder "specbas" in your user folder. In your case, this is

C:\Users\dench\

SpecBAS then calls that folder (C:\Users\dench\specbas) it's "root" or "/" folder and cannot "see" anywhere else on your drive but there. This prevents badly behaved SpecBAS programs from wiping your system should they so choose.

A great many people still believe that an application, such as SpecBAS, should keep all its files and folders inside its installation directory but that is no longer the case in Windows. So now you have two folders - C:\Users\dench\Downloads\SpecBAS\ where the SpecBAS_x64.exe is stored, and the other folder where SpecBAS does its work. It's not nice having to work in two folders per application, but them's the rules.
Post Reply