SpecBAS program under development

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

SpecBAS program under development

Post by llewelyn » Mon Sep 02, 2019 2:57 pm

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
0 x

User avatar
ZXDunny
Manic Miner
Posts: 237
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny » Mon Sep 02, 2019 3:42 pm

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.
0 x

llewelyn
Dizzy
Posts: 94
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS program under development - Link to image

Post by llewelyn » Mon Sep 02, 2019 4:02 pm

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.
0 x

User avatar
ZXDunny
Manic Miner
Posts: 237
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development - Link to image

Post by ZXDunny » Mon Sep 02, 2019 5:41 pm

llewelyn wrote:
Mon Sep 02, 2019 4: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:


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.
0 x

llewelyn
Dizzy
Posts: 94
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

SpecBAS program almost complete

Post by llewelyn » Mon Sep 02, 2019 9:54 pm

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.
0 x

User avatar
ZXDunny
Manic Miner
Posts: 237
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny » Mon Sep 02, 2019 11:17 pm

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.
0 x

ASH-II
Berk
Posts: 11
Joined: Sun Jun 16, 2019 10:48 am

Re: SpecBAS program under development

Post by ASH-II » Tue Sep 03, 2019 5:32 am

Stick in some random landing pads and you have a game :)
0 x

User avatar
ZXDunny
Manic Miner
Posts: 237
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS program under development

Post by ZXDunny » Tue Sep 03, 2019 8:21 am

ASH-II wrote:
Tue Sep 03, 2019 5: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).
0 x

ASH-II
Berk
Posts: 11
Joined: Sun Jun 16, 2019 10:48 am

Re: SpecBAS program under development

Post by ASH-II » Tue Sep 03, 2019 10:17 am

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
0 x

llewelyn
Dizzy
Posts: 94
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS program under development

Post by llewelyn » Tue Sep 03, 2019 1:01 pm

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.
0 x

Post Reply