Page 1 of 3

How to write games in BASIC

Posted: Sat Jan 16, 2021 10:15 pm
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!

How to write games in BASIC

Posted: Sat Jan 16, 2021 10:28 pm
by rje

These are fantastic tutorials!

 


How to write games in BASIC

Posted: Sat Jan 16, 2021 11:30 pm
by DusanStrakl


1 hour ago, rje said:




These are fantastic tutorials!



 



Thanks Rob, I appreciate it.


How to write games in BASIC

Posted: Sat Feb 20, 2021 6:16 am
by Jakebullet70

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

 


How to write games in BASIC

Posted: Sat Feb 20, 2021 7:09 pm
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.


How to write games in BASIC

Posted: Mon Feb 22, 2021 9:37 am
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?


How to write games in BASIC

Posted: Mon Feb 22, 2021 10:06 pm
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.


How to write games in BASIC

Posted: Wed Feb 24, 2021 5:45 am
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. 

 

 


How to write games in BASIC

Posted: Mon Nov 15, 2021 9:07 pm
by DusanStrakl

Crazy Lander links have been added to original post.


How to write games in BASIC

Posted: Wed Oct 12, 2022 11:23 am
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.