RetroCoders Community

FreeBasic Programming => FreeBasic Game Dev => Topic started by: electricwalrus on Sep 12, 2022, 06:46 AM

Title: Ski Slope by electricwalrus (2022)
Post by: electricwalrus on Sep 12, 2022, 06:46 AM
Ski Slope by electricwalrus (2022)

This here is a simple basic game. I used to enjoy this game because it was so easy to make. Look! Check out the source code. Download link in the attachment.

' Standard Setup Routine
#lang "fblite"
Option GOSub
Randomize timer

' Ideal Screen Size
screen 17

' Welcome
Color 2
Print "Ski Slope Challange! By electricwalrus (2022)"
Print "Try to last on this slope as long as possible"
Print
Print "Use the arrow keys to move left and right down the slope"
Print
Print "Press any key to begin!"
Sleep

start:
Cls
score = 0
x = 40
player = 40
Print "Get Ready!"
sleep 1000,1
locate 25, 1
Do
    i = int(rnd*2)+1
    if i = 1 then
        x = x - 1
        if x < 10 then x = 10
    end if
    if i = 2 then
        x = x + 1
        if x > 70 then x = 70
    end if
    x2 = x - 10
    for a = 1 to x2: print " "; : Next
    Color 11: Print "*                *";
    if MultiKey(1) then end
    If multikey(75) then player = player - 1
    If multikey(77) then player = player + 1
    check = player - x
    if check < -8 then goto endgame
    if check > 7 then Goto endgame
    locate 25, player: color 10: Print "!!"
    sleep 30,1
    score = score + 1
loop

endgame:
Beep
sleep 1000,1

cls
Locate 1,1
Color 6
Print "You crashed on the ski-field!"
Print "Score: " & score
Print
Color 15
Print "Try Again in 5 seconds"
sleep 5000,1
goto start
Title: Re: Ski Slope by electricwalrus (2022)
Post by: electricwalrus on Sep 12, 2022, 06:47 AM
skislope ss.png
Title: Re: Ski Slope by electricwalrus (2022)
Post by: electricwalrus on Sep 12, 2022, 06:55 AM
bug fixed
Title: Re: Ski Slope by electricwalrus (2022)
Post by: mysoft on Oct 13, 2022, 12:29 PM
hehehe  made a version of this game... (but as in form of rally), using pure BATCH some years ago :)
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 13, 2022, 06:03 PM
I remember this evil game from "way back"! Simple concept. Stay within the 'flags' for as long as possible. Then, some twisted individual, decided to gradually reduce the distance between the 'flags'. If that was not bad enough, the speed was increased as well...!!  Evil game I tell you. Evil. I lost count of the number of times I tried to beat that game... then it dawned on me... 'it never ends'!!

Brilliant game. Evil. But brilliant... More please...

J

ps: Are we permitted to "tinker" with the code?
Title: Re: Ski Slope by electricwalrus (2022)
Post by: electricwalrus on Oct 13, 2022, 07:17 PM
i dont see why not.
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 13, 2022, 10:00 PM
Cool...
Title: Re: Ski Slope by electricwalrus (2022)
Post by: electricwalrus on Oct 14, 2022, 05:24 AM
The intention on programming this game was to show a simple code example of a simple game that I hope people can learn from and understand how it works. Tried to keep it as straight forward as possible.
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 14, 2022, 06:06 AM
I had to increase the 'sleep' period within the main loop... 'Get Ready' popped up and before I had finished reading it... The Skier had already crashed... Changed the 'sleep 30,1' to 'sleep 100,1' and all was ok. Still a touch quick, but quite playable...

You did a good job in keeping it simple.. Ha... Even "I" could understand it... lol
Title: Re: Ski Slope by electricwalrus (2022)
Post by: electricwalrus on Oct 14, 2022, 06:27 AM
yeah good. that was the idea :)
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 26, 2022, 05:19 AM
I can remember when this game appeared many years ago...  What are you saying, Aurel?  Are you saying that... I am old? lol  Well... You are right... I can remember when Basic was created... I believe I was about to complete primary school at the time... lol
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 26, 2022, 05:42 PM
8 bit? You were lucky. Throughout my primary and secondary (high school) education... No computers! At the end of my apprenticeship, in 1976, I actually purchased a programmable calculator... It would be another 3 years before I would build my first computer... Ah... Soldering irons! Wonderful invention!
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 26, 2022, 11:05 PM
Yes, a kit. It was featured in a magazine, "Electronics Australia", in the late 70's

http://www.mjbauer.biz/DREAM6800.htm

I had just started working as a process worker assembling circuit boards and found the article in the magazine and figured, "Why not?"

Totally under-powered. 1K of ram. HEXDEC keypad input. Output to the antenna socket of a TV and saved to cassette. Sample program was a hobble photo copy... Took 45 minutes to enter a simple Pong-like game. No editing. No backspacing. Three, maybe four attempts, to get it to work. Poor photo-copy combined with typos were the main cause of failure. Saved to cassette at a 300 baud rate...

The following year I would tackle a larger kit project:

https://en.wikipedia.org/wiki/Dick_Smith_Super-80_Computer

This would be my final project. Price of 'ready made' computers were dropping in price quite quickly...
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 27, 2022, 11:19 AM
As I mentioned before, using the HEX keypad took about 45 minutes to key in a simple pong game. I tried to look for the listing but I guess it may not have survived...

The second machine was a kit that I built. I think it was about 1981-82... It had 16K ram. Text only. I also paid for Basic on an eprom. I think it was based on Tiny Basic? The entire machine occupied a single motherboard. The keys were soldered directly to the motherboard. Interesting thing was the "keyboard" could be physically cut off the motherboard and connected via a ribbon cable. I left it attached...

That machine did not last very long... Oh, it ran really well, for a Basic machine... It did not come with a "case"... So, the computer would sit on top of the TV and shared the TV antenna socket... Until... the day my wife was dusting and the duster snagged some of the components and the computer fell off the TV... I did not have the skills to repair a cracked double-sided motherboard... RIP... *sniff*

My soldering iron still sits in the toolbox in the laundry cupboard...
Title: Re: Ski Slope by electricwalrus (2022)
Post by: johnno56 on Oct 28, 2022, 12:59 AM
I used '95 and '98se before switching to XP in 2001. Used XP until I moved to Linux in 2005. I liked XP. I little more stable than '95 and '98. Oh, and those colour schemes... There were some real shockers! There are times that I actually miss XP... then I have another coffee and the feeling goes away... lol I cannot imagine using a machine with only 128mb of ram... But, back then, that was a lot...
Title: Re: Ski Slope by electricwalrus (2022)
Post by: __blackjack__ on Aug 03, 2025, 02:11 PM
It's easy to get rid of the GOTOs.  The one for the `start:` label is just a DO ... LOOP around the code and the other two are an EXIT DO to exit the game loop.

And the game just needs three variables.  The others can be removed.  `i` isn't needed when the value is checked with a SELECT CASE statement.  The expression defining `x2` can be inserted in the only place where `x2` is used.  `a` is for a loop that can be replaced by a LOCATE.  And for `check` we can use SELECT CASE again.

Randomize Timer
Screen 17  ' Ideal Screen Size (80x25 characters)

' Welcome
Color 2
Print "Ski Slope Challenge! By electricwalrus (2022)"
Print "Try to last on this slope as long as possible"
Print
Print "Use the arrow keys to move left and right down the slope"
Print
Print "Press any key to begin!"
Sleep

Dim score As Integer, x As Integer, player As Integer
Do
    Cls
    Print "Get Ready!"
    Sleep 1000, 1

    score = 0: x = 40: player = x
    Do
        Select Case Int(Rnd * 2)
            Case 0: If x > 10 Then x = x - 1
            Case 1: If x < 70 Then x = x + 1
        End Select
        Locate 25, x - 9: Color 11: Print "*                *";

        If MultiKey(1) Then End
        If MultiKey(75) Then player = player - 1
        If MultiKey(77) Then player = player + 1
        Select Case player - x
            Case Is < -8, Is > 6: Exit Do
        End Select
        Locate 25, player: Color 10: Print "!!"

        Sleep 100, 1
        score = score + 1
    Loop
    Beep
    Sleep 1000, 1

    Cls
    Locate 1, 1
    Color 6
    Print "You crashed on the ski-field!"
    Print "Score:"; score
    Print
    Color 15
    Print "Try Again in 5 seconds"
    Sleep 5000, 1
Loop
Title: Re: Ski Slope by electricwalrus (2022)
Post by: __blackjack__ on Aug 07, 2025, 09:04 AM
There's a type in line 130: T1 instead of T!.

In line 200 there's the `;` missing at the end of the print.  This leads to printing the slope and the player every other line instead of printing both on every line.

Line 70 isn't the best way to translate the original because that doesn't wait for any key but for the enter key.  A loop with INKEY$ would be better.

Just like in the original the FOR loop printing single spaces can be replaced by LOCATE.

All variables without a type suffix can be declared as integer instead of floating point.

Somehow the COLORs from the FreeBASIC version was missing. Easy to add back because GW-BASIC the same COLOR command with the same color values.

It was custom to pack more than one statement into a line.  Yes that makes the code more dense and thus sometimes harder to read, on the other hand the code now fits onto the 80x24 lines visible on screen when listed in GW-BASIC.
10 DEFINT A-Z:RANDOMIZE TIMER:COLOR 2
20 PRINT"Ski Slope Challenge By electricwalrus (2022)":PRINT
30 PRINT"Use the arrow keys to move left or right down the slope":PRINT
40 PRINT"Press any key to begin!":WHILE INKEY$="":WEND
50 CLS:S=0:SX=40:PX=SX
60 PRINT"Get Ready!":T!=TIMER+5:WHILE TIMER<T!:WEND
70 ON INT(RND*2)+1 GOTO 80,100
80 IF SX>10 THEN SX=SX-1
90 GOTO 110
100 IF SX<70 THEN SX=SX+1
110 LOCATE 24,SX-9:COLOR 11:PRINT"*                    *";
120 K$=INKEY$:IF K$=CHR$(27) THEN END
130 IF K$=CHR$(0)+CHR$(75) THEN PX=PX-1:GOTO 150
140 IF K$=CHR$(0)+CHR$(77) THEN PX=PX+1
150 D=PX-SX:IF D<-8 OR D>6 THEN 190
160 LOCATE 24,PX:COLOR 10:PRINT"!!"
170 T!=TIMER+.3:WHILE TIMER<T!:WEND
180 S=S+1:GOTO 70
190 BEEP:T!=TIMER+1:WHILE TIMER<T!:WEND
200 CLS:COLOR 6:PRINT"You crashed on the ski-field":PRINT"Score:";S:PRINT
210 COLOR 15:PRINT"Try Again in 5 seconds":GOTO 50