How to write games in BASIC

Tutorials and help articles.

Articles will be approved by our staff before posting. This is to ensure that the community gets the highest quality possible content.
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

How to write games in BASIC

Post by DusanStrakl »

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.


Crazy Snake 

Image


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

VERA 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
Try me!
 

Tetris Clone

Image

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

VERA Overview
Tiles in Basic I - Video Modes 0 and 1
Colors 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
Try me!
 

 

Boulder Dash style game

Image

Image

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
 
VERA Overview
Tiles in Basic I - Video Modes 0 and 1
Sprites in Basic I - Setup
https://www.8bitcoding.com/p/sprites-in ... Animation
Scrolling and Layers in BASIC
Colors and Palettes
Simplest Sound Effects Library for BASIC
Font 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
Try me!

 

Lunar Lander style game

Image

Image
 

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. Due to pixel perfect collision detection requirement we had to use small machine code routine.

 
Recommended reading

VERA Overview
Tiles in Basic I - Video Modes 0 and 1
Sprites in Basic I - Setup
https://www.8bitcoding.com/p/sprites-in ... Animation
Scrolling and Layers in BASIC
Colors and Palettes
Music Player Library for BASIC Programs
Font 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:
  • Integration of machine code, Assembly source code is available
  • Full color mode
  • 256 Color Title screen
  • Two layer graphics
  • Bitmap background
  • Tile based HUD
  • Full color sprites
  • Advanced physics and game mechanics
  • Loading assets to memory from binary files for:
  • Tileset - fonts
  • Sprite Sheet
  • Background music
  • Title screen

GOTO Crazy Lander Tutorial
Try me!
Last edited by DusanStrakl on Sun Jun 25, 2023 7:43 pm, edited 3 times in total.
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

How to write games in BASIC

Post by rje »


These are fantastic tutorials!

 

User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

How to write games in BASIC

Post by DusanStrakl »



1 hour ago, rje said:




These are fantastic tutorials!



 



Thanks Rob, I appreciate it.

User avatar
Jakebullet70
Posts: 15
Joined: Sat Nov 21, 2020 8:18 pm

How to write games in BASIC

Post by Jakebullet70 »


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

 

If you do not see any flak... Your not on target!
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

How to write games in BASIC

Post by DusanStrakl »



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.

Lucky Phil
Posts: 18
Joined: Mon Feb 08, 2021 10:58 am

How to write games in BASIC

Post by Lucky Phil »


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?

User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

How to write games in BASIC

Post by DusanStrakl »



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.

User avatar
Jakebullet70
Posts: 15
Joined: Sat Nov 21, 2020 8:18 pm

How to write games in BASIC

Post by Jakebullet70 »


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. 

 

 

If you do not see any flak... Your not on target!
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

How to write games in BASIC

Post by DusanStrakl »


Crazy Lander links have been added to original post.

TwentySixHundred
Posts: 1
Joined: Wed Oct 12, 2022 11:15 am

How to write games in BASIC

Post by TwentySixHundred »


Thank you for the guides, these really help with understanding BASIC on 8bit home computers. I usually use batari Basic and 7800Basic for coding on the 2600 and 7800 Atari systems. However very interested in this project as the emulator/system has some great capabilities.

Post Reply