Computer English

Just Basic Game Tutorial

about writing games in just basic – game listing – game source code – sprites an sound.

Free – Game – Tutorial

about writing games in just basic - game listing - game source code - sprites an sound. example programming games in just basic (JBasic)

Just Basic Game Tutorial :

The Just Basic Game Tutorial is about how to make games in just basic – game listing – game source code – sprites an sounds.

Below the article is a youtube video where you can see the game in action. There will be also a ZIP (free download) with the sounds and the necessary drawings to make the game yourself. Also a zip with just the finished game so you don’t have to install JustBasic. But you can just play it.

UPDATE: programming games in Just Basic Tutorial

In the meantime I have improved the game. It now also stores your highest score. This makes it more fun to play, because you now have an extra goal. (Improve your highest score) But first I start the explanation with V1.0 of this just basic game (Jbasic). Because this is easier in this tutorial on learning how to program games in Just Basic. (Step by Step 🙂 The sourecode of the improved version V1.1 can also be found at the bottom of this tutorial in a ZIP for download. (Free download)

Just Basic

Just Basic is a programming language that is very easy to use. (see for example in this game, it uses only 2 pages of code) It is like Basic that used to be standard on every Microsoft MS-DOS computer. But now adapted to work on any Windows computer. You can download the program on the following link. JB website (get V2.x.x) This is FREE. 😎

If you like this, and you want to support the developers, you can also buy Liberty BASIC there. This is the same but with many more options. But the free version is sufficient to practice.

Basketball Game in Just Basic Programming language.

OK, it’s just a simple game. And my drawing arts aren’t worth much :-). But the purpose of this just basic tutorial is simply to show how game code works. And how simple it is, without all kinds of plugins that you need at Phyton for example. And another advantage. You can compile an independent version. So that the end user does not have to install JB first, and without being able to see your source code.

The files you need:

  • background.bmp
  • ball.bmp (the sprite)
  • music.mid (background music)
  • hit.wav
  • cheers.wav
  • bs-basket.wav

Make a new folder and put all files there. And put all code in a file bs-basket.bas (it is plain ascii text like a TXT file)

At the bottom is a download button to download a zip file with the drawings and the sound files. You must enter the code yourself. Or cut and paste. But the best thing is that you type it yourself, so you will learn faster what the code does. You still have to fine tune some numbers here and there. And you can also keep the highest score, for example. And even save it in a file. That you then read when the game starts. And of course you can create your own improved background with Paint, to make it your unique game. You can also replace the WAV and MID files with your own files. For example, the bs-basket.wav file is just a drum sample from LMMS that I edited with Audacity.

Game source code in Just Basic V2.0.0


I have split the code into blocks. But you have to retype it (or copy it) in 1 name.BAS file. (you can choose the name. In my case it is ‘bs-basketball.bas’)

' if you want this justbasic listing (my first game in just Basic)
' and the pictures follow the link below the video.
' in this verry basic game you'll find everything you need to know, to make
' your own game(s) in Just Basic :-)
' Copyright (c) Bruno Stroobandt :
' It is better that you type the code yourself instead   '
' of ctrl-c ctrl-v. This way you get more feeling with   '
' the code and you will understand it faster.            '
' <- this is comment symbol, or ignores code.
' ok here we go :-)

    nomainwin 'this gives only the program-window

    WindowWidth = 540     ' the width
    WindowHeight = 410    ' the height (also of you background file)
    loadbmp "ball","ball.bmp"    ' load the sprite into memory
    loadbmp "bg","background.bmp" ' load the background
' center your program on screen
' draw the 3 action buttons
' UL=upper left corner of the button x,y,width,height
' #main is your working screen : "caption on the button" : [action]
    button #main.button1, "Start dribble", [Drop], UL, 30, 26, 122, 25
    button #main.button3, "Reset", [Reset], UL, 318, 26, 122, 25
    button #main.button4, "Shoot", [Shoot], UL, 166, 26, 122, 25
' this is where the score will be displayed
    statictext #main.stxt, "StaticText Caption", 500, 26, 40, 25
' this activates the graphical enviroment
    open "bs-basketball" for graphics_nsb_nf as #main

    print #main, "fill white;flush" 'makes the title white
    print #main, "trapclose [quit.main]" ' action when X is clicked
    print #main, "font ms_sans_serif 10" ' the txt font
    print #main, "addsprite ball ball" 'makes the ball bmp a sprite
    print #main, "spritexy ball "; x;" "; y 'set x-y of the ball
    print #main, "background bg" ' print the background bmp
' the above is all done off-screen in memory to prevent flickering
' and now we print the finished composition :
    print #main, "drawsprites"
    playmidi "music.mid", howLong ' start midi music 
'   (and remember how long it is)
    'timer 1000, [checkPlay] ' removed this timer (you see the ' )
     wait ' wait until the user clicks a button

The game A.I. actions

' start dribeling
    dy=0 ' delta Y = speed of the ball (down or up)
    if y>=220 then [Stop] ' if it is on the floor
    hmax=y ' maximum height the ball can go

    timer 50, [fall]
     gosub [checkPlay] 'for the midi music
     gosub [Score] 'check score conditions
     if x>=440 then
        x=440 '+80 ball width (max right on your screen)
        s=0 ' can the ball go right 0=no 1=yes
     end if
        t=t+5 ' to adjust the speed
        if y>=300 then 'ball hits the floor
            timer 0
            goto [bounce]
        end if

        if s=1 then 'if you gave a throw click
            if x<=400 then
            spd=spd-0.25 'slows the ball while flying
            if spd<=0 then
                s=0 'end throw action
                end if
            end if
        end if
        print #main, "spritexy ball "; x;" "; y 'new position
        print #main, "drawsprites" ' update the user screen
        scan ' to prevent a freeze (look for user interaction)
' if the ball hits the floor
    timer 50, [rise]
    playwave "bs-basket.wav", asynch ' the bounce sound
     if x>=440 then
        x=440 '+80 ball width
        hmax=hmax+50 'every bounce the ball goos less high
        end if
        t=t - 5
        if y<= hmax then
            timer 0
            goto [Drop]
        end if
        if s then 'only when you throw
            if x<=800 then
            if spd<=0 then
                end if
            end if
        end if
        print #main, "spritexy ball "; x;" "; y
        print #main, "drawsprites"
        if hmax=220 then [Stop]

' this is called if the ball does not bounce anymore
' to low on the ground, and after a goal
    timer 0
    if scc = 1 then 'if score counter is active
        print #main.stxt, points
        playwave "cheers.wav", asynch 'you made a goal sound
        end if
' check if it is posible you made a goal
    if x>=410 then 'far enough to the right
        if y<=65 then 'and high enough
            playwave "hit.wav", asynch 'hits the basket sound
            scc=1 'flag score count = ON
            for k = 1 to 200000 ' short pause to play hit.wav
            next k 'change this if you have a slow pc
            end if
    end if

' after a goal or if you wait to long (ball is death on floor)
' you have to press the reset button
    timer 0
        print #main, "spritexy ball "; x;" "; y
        print #main, "drawsprites"
' when you click the shoot button
    s=1 'shot flag is ON
    spd=worp 'speed of the ball depends on when you click
    dy=dy*2 ' double the delta-y speed
    hmax=1 'make it possible to go high enough
    goto [fall] ' continue the fall-code

Closing time

' quit all background actions in the correct manner
' so it will not stay resident in memory afther you close
' the game
    close #main
' check if the midi is finished
  if howLong = midipos( ) then gosub [musicEnded]
' if it is, start it again
  stopmidi 'always unload it first
  playmidi "music.mid", howLong

'Copyright (c) Bruno Stroobandt :

Basketball – The background picture

just basic game example background (the wallpaper)

You don’t have to be an artist to make drawings. I just made this background in the free version of Excel (OpenOffice) and made a screen shot of it and then updated it in Paint. The size must match what you describe in the code. In this case 540×410 pixels.

Basketball – The sprite

The black part = the mask

If you make a sprite. This should be twice as high as wide. The top half is the mask to clear your sprite. In this case, that is the black sphere. But if you draw a man, for example. Then the black spot must have the same shape and place as the man in the lower half. In our case, the bottom half is the basketball for our game example. But that can be anything. BLACK is the transparent color. If you want to use black in your drawing, then you have to use a lighter shade. 99% black also looks black to the eye. But you may not use 100% black, because this is the transparent color.

The game in action

If you follow the instructions in this just basic game tutorial. This will be the result:

this is my first game (in Just Basic)

Free download – Just Basic game data-files

Here you can download the pictures and sounds in 1 zip file. The source code is not included – see above.

Standalone version – (from the game tutorial)

Here you can download the working free game (to play the game without programming it first.) Tested on Win 10 (but should work on any win32 en win64 machine)

update: This new compiled version keeps a high score on disk !!! V1.1 (in the video you see V1.0 without the High Score function.

It is possible that you get a windows defender smartscreen pop-up. Click on ‘more info’ and then execute. (This only happens once because Windows defender of course doesn’t know me (I’m not famous enough 🙂 )

Just Basic Game source code 1.1

update: here you have a free download of the just basic game Bs-Basketball V1.1 – this version includes how to read and write to disk to keep track of the HighScore. Note: If you use this version you should also rename your picture and sound files to *.dat (example hit.wav becomes hit.dat) In that way your game looks even more pro, and the end user does not now what the files are. 😉 You should actually call them 001.dat. Do not forget to apply this in your code. 😎

⚠️TIP: if you are still learning. Then first try using the code from version 1.0 above. First try to walk before you start running. 🙂

How to compile a just basic program?

You can see this in this video:

In dutch script but the visual is self-explanatory

It is another program that I made in just basic that converts a binary number into a decimal number. But the method of making a compiled version is the same.

Of course you first write your code. And then instead of RUN, choose under the RUN menu for make TKN file. This TKN file is your compiled program.

You create a new folder and put that file in it. Then you go to the root folder where the Just Basic program is installed.

There you select the following files. And make a copy of it. (Do not move but copy) You can paste the copy in the folder where you have placed your TKN file.

  • VTK1631W.DLL
  • VTK3231W.DLL
  • VVM31W.DLL
  • jbrun2.exe

Copy and rename jbrun2.exe

The jbrun.exe is the just Basic software that you use to create programs. The JBRun2.exe is the program that will execute your TKN. All you have to do now is rename this jbrun2.exe to the same name as your TKN file.

So in this example I have called my program bs-basketball.TKN. And so I change the Jbrun2.exe to bs-basketball.exe. And if you now start that EXE, your TKN program will start automatically. In our exampled we also use BMP and WAV files. You must of course also put it in that self-made folder. And then you can put everything in 1 ZIP file to be put on the internet for example. And it’s done 😎 (P.S. I use 7Zip to zip 🙂 )

In my compiled version I also renamed all WAV and BMP files to * .DAT. That works too. Please note that you have changed these names in your source code.

End of ‘Programming games in Just Basic Tutorial’

Corona Shooter Game in C-sharp

Back to English index

Terug naar Computer en Elektronica

Hoe externe data file gebruiken in C#

Corona shooter game in c# (Dutch)