Jump to content
DusanStrakl

How to write games in BASIC

Recommended Posts

I wrote a series of blog posts/articles on Commander X16 architecture and coding. I have started with focus on beginners and then slowly moved to more advanced topics and techniques. First I tackle smaller chunks and use simple examples to show the topic in practice.

After enough new knowledge is covered I write a complete game to utilize several of the techniques to illustrate how it all comes together so each new complete project is more complex than the one before. I do cover only Commander X16 specific so I recommend reading Commodore C64 BASIC tutorials and guides.

Please note that the games and most examples are written with a goal to be as clearly readable and understandable so there is very little source code optimizations.


 Snake Game 

oOYtAniyluEqKGq-Z6IYr3fc-bdW01qqw_VQP5u2vEZwL5BAUQXWmErnzjQUA0NW-o_IGt__c0SKe5TdkFb3aKSxoq4f4ipjOhM0SlbxoguY2umKOZrNj9nuGBxu6AjmUqtQ4UXG    oPDpxW_K66EjJ-C2B-zzYq7zwd0QonPGrQ44qHIL-tG8WF9mbg1bbJoKohFpHBE86BU122Kr98VU173cwR8lFc26_c-T2KCygEGGhwdU6wy3jdtZZwP3ZWm7xPKn_Bm4weclLt8b    rmmo1izUqdbxJi4uddUn9u9kDt53ndQCKQmmd1HTplwYbOplfZZXtoRPn7dbS8Rh3KLl49G-bW-z_CpXkwrEIbJWVoWmhz6Cy7txanEwyOHNNyHo85r8UShz9scxuSWOv1TwcSal

This game is written in very clean BASIC with very little trickery so not much special Commander X16 knowledge is required. We do VPOKE directly into video memory so only understanding of fundamentals is required.

Recommended reading

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlVERA Overview

 

Topics Covered in Game
Analyzing the game itself is a great way to learn basics like:

  • How to structure source code (outer loops, game loop)
  • What is Game loop
  • Use of Data structure like multiple Arrays
  • How to read Joystick, Keyboard
  • How to use VPOKE to “talk to” VERA
  • Video RAM organization and using colors
  • Writing to certain location on the screen
  • Using PETSCII control characters to display messages and title screen

 

GOTO Crazy Snake Tutorial

GOTO Download

 

 

Tetris Clone

gILKFp0pW36o62XxJfc8dS7z_-hQ82YVr-MBawFC6cq6JZh-OPMOV-UQad42YaD6v6AQUOxUYXTxvhIsdsQP52R5J4eX_9pad9zjFlygc6LR3qv9gi9jPyngWgAtPNND1L4atY_M    oh6ewn4R1cxTisraVGcGCS-sas2uKU4D-7P8nb2v8kFdOpva623LucBFEpvohrMoCll34E6Il6iIVDZ9tY05eghEPftp42gMZT2mY1UYeZzkqvZ0oqMC7AJRk2P3fnAuaSBcThHc    JPM61wsvucbiBTCxoia-BsN_xZM6liVXAwGAlo3kFiD_N3ZwM8PmcpikKAeYQaBdNd19sC_mKeUVk_wUp4cEM_nRzSM31QON8NGgMy3g1fhIQWFr4MoCAA6P-PEDj_0OxKEcrLMb

This game introduces some more advanced features of Commander X16 and we have to take a bit more care of how to use data structures and optimize some parts of the game to make it playable.
 

Recommended reading

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlVERA Overview

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlTiles in Basic I - Video Modes 0 and 1 

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlColors and Palettes

 

Topics Covered in Game

Tetris clone requires us to improve on pretty much all parts of the snake game structure:

  • We have additional loops outside and inside game loop
  • Advanced game collisions based on screen state
  • Pre-calculate relative positions of four segments of each tetromino
  • Customize color palette
  • Customize tiles (characters)
  • Speed increase per level
  • Adding sound to the game
     

 

GOTO Crazy Tetrominoes Tutorial

GOTO Download

 

 

Boulder Dash style game

ud1ty1ycxpxLmtpop5k-PlIOuJRyyH2BE_4VvokAB2s0n4uH61G8wDI2H_eZ0pnl81-bwNyWOjjFIA8MloXGeeWRQ3hMlBh4pRDYrrH8ifftexgKlC2rpXeV_qMJ9RE2ki3q5O4Z    6GQwHXMtGLMWqh0An2Zute9l5PwpGFLnkgQBtxrJ3af8zhRMe9KxXkqGk2AeA_nftq_j2r_YfnHRQ5kWuW_3nKu79kcrARw8wulBFEfbTxIiwCsPZUfBfJ4qsIq5K2ddPV5sBeeZ    FkDDhFMClZ1kMNdJPGkxaHXGdLvjcLCf08RlEBFFUmbHxJs5wemfDspInr4JIp6OPuNHfH8GNfAWEpIxV_l-3oZnwFLaa6xqAWaQ2J93yq__LbfF-HlQ-4fMFW7KJpYTER_5H2mP    

GOvuu-XJH7UNuQAPFrxNUTkttcAzPnOhTDs4pkE7UpESP4ZhC7P7PK-lfFe_G4ko0mMTZf0YLPjM9TJtw_5SWTj6Vq8RjFS89q5Ei7XzSkx9DWMUzqfKbOBaurK8UxBnT1olfCZo    VoIhp1ZuOsTd-F6FxU-wrDPpbd4dI82dRHZNm764comUrPT4NivAZXdF9w6V6xLps93HX2cPKsqNZZCmwDiHE-ZhpHRXRVjPntjZgKHOASaq7gk0wBZFblZYrPQku3tKnTrO9COy    KagZ6agOfbYQP7Z49lWK8GZ3IzkErgs_K_fRzu9_VJUAdQJzbEcGKWOQO-mK6S-3m3QRFJvunSKxaDyVAnAoqEC6XLiH8cOiudXeDBQ02wF9W0k8EsR2PHU8p9-esOj0hRmK45E-

3IgVaRRFp5Zfg9c0PHaxWDC4iszptrLPuVmLHO3hhbqG7m6005uhPTka4ck69xJrokufbiJRZLUbv9cQdsqr7Qx5N6OG_7ePZSYCNm5dyARLRYLuHroWAWwkY8X362oII_jrJpdj

 

With this game we are using most of the Commander X16 hardware capabilities and we are getting close to squeezing most out of it for BASIC games. We have to pay close attention to timings, synchronizing scrolling and animation, take care of different types of collisions, etc.
 

Recommended reading

 

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlVERA Overview

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlTiles in Basic I - Video Modes 0 and 1 

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlSprites in Basic I - Setup

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlSprites in Basic II - Animation

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlScrolling and Layers in BASIC

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlColors and Palettes

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlSimplest Sound Effects Library for BASIC

GAraTm_TwejiKNrGmFvu_YDAEbUl2eAsCtjMVs1bvjx1gCGz8dmYGIRGltMGJZey0BbpcdEBOAfvrf2lzdDXN1l_1PzmPOwZax5WOZHSfWZu6sJXJNLYqlND9OOiCc8MuXSFytQlFont Library for Commander X16

 

Topics Covered in Game

This game is taking advantage of hardware features of Commander X16 to the level it almost looks like 16bit game or something written in Assembly for 8 bit computer like:

  • Two phase approach to development
  • Full color mode
  • Full screen scrolling
  • Two layer graphics
    • Scrollable playfield
    • Static HUD
  • Animated full color sprites
  • 256 color title screen in graphics mode
  • Advanced physics and game mechanics
  • Loading assets to memory from binary files for:
    • Tileset
    • Sprite Sheet
    • Fonts
    • Sound effects library
    • Title screen
       

 

GOTO Crazy Boulders Tutorial

GOTO Download

 

Edited by DusanStrakl
  • Like 5
  • Thanks 5

Share this post


Link to post
Share on other sites
12 hours ago, Jakebullet70 said:

This is real good stuff. Sometimes I think people forget this is still a BASIC machine.

 

Thanks Jake. I agree and with powerful hardware supported graphics and 8Mhz clock speed a lot can be done in BASIC. I am working mostly on my Assembly tutorials now but I am sure I will add some more BASIC tutorials and games soon.

  • Thanks 1

Share this post


Link to post
Share on other sites

Terrific stuff... very nicely done! From a novice point of view, it's great to see what can still be achieved in BASIC - without diving head-first into assembly language. I guess that the relatively fast clock rate and sophisticated code (as opposed to what were on offer in the beloved, original Commodore 64) negate many of the arguments against developing in BASIC, after all?

Share this post


Link to post
Share on other sites
12 hours ago, Lucky Phil said:

Terrific stuff... very nicely done! From a novice point of view, it's great to see what can still be achieved in BASIC - without diving head-first into assembly language. I guess that the relatively fast clock rate and sophisticated code (as opposed to what were on offer in the beloved, original Commodore 64) negate many of the arguments against developing in BASIC, after all?

Thanks Lucky Phil. I agree, Commodore BASIC is not ideal language but then again there is no such thing anyway. I find it very convenient to tinker with, prototype and with some effort and clever coding a lot of fun results can be achieved.

  • Like 1

Share this post


Link to post
Share on other sites

Would love to see an extended BASIC that can be tucked into one of the ROM banks like say something like DotBASIC: http://dotbasic.cbm8bit.com/about.html

Or even the addition of Commodore BASIC V7 commands in ROM somewhere.

http://dotbasic.cbm8bit.com/dc.html   -- .BASIC command summery. I played with these years ago. 

 

 

Edited by Jakebullet70

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use