# Tetris in pure BASIC

**URL:** <https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029>\
**Category:** Games!\
**Tags:** basic\
**Created:** [October 27, 2026, 6:53pm UTC](https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029 "2026-10-27T18:53:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mv13](https://forum.cpcwiki.eu/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mv13](https://forum.cpcwiki.eu/u/mv13)\
**Post date:** [October 27, 2026, 6:53pm UTC](https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029/1 "2026-10-27T18:53:50Z")

</div>

## Tetris in pure BASIC

I’ve been working on a Tetris implementation in Locomotive BASIC, as a Rosetta Code solution.

The program includes:

- All seven pieces (ITOSZJL), in seven different colours
- A 7-bag randomizer, ensuring every piece appears once per set of seven
- Next-piece preview, line clearing, and hard and soft drops
- Scoring based on lines cleared and the current level
- Increasing difficulty, with the level rising every ten lines
- Keyboard control using cursor keys, the numeric keypad, or letter keys, including clockwise and counter-clockwise rotation

A lot of attention went into performance, particularly avoiding unnecessary work in the game loop:

- Precomputed rendering: Each piece and rotation has prebuilt draw/erase strings, so movement doesn’t need to decode the shape or redraw the board.
- Fast collision detection: The four occupied cells of each rotation are decoded once. A flattened board, cached linear offsets, and padded boundaries keep collision checks simple and stop them as soon as a collision is found.
- Efficient line clearing: Row occupancy counts are maintained incrementally, and only rows touched by the locked piece need checking. Completed rows are removed by scrolling a BASIC window rather than redrawing the board.

I also experimented with overlap-aware rendering, but dropped it: the small potential gain wasn’t worth the extra startup work and complexity.

The result is a compact BASIC program with ~175 lines.

Source: [Tetris: Rosetta Code]( [Tetris - Rosetta Code](https://rosettacode.org/wiki/Tetris#Locomotive_Basic) )

It can also be run with [CPCBasicTS v0.5.8](https://benchmarko.github.io/CPCBasicTS/?database=rosetta&example=tetris)

Comments and suggestions are welcome!

 ![tetris](https://forum.cpcwiki.eu/uploads/default/original/2X/c/c38ceaa786f6aff59f7dcf48cf1aedb0e0bd4679.png)

---

<div class="post-metadata">

**Author:** ![dthrone](https://forum.cpcwiki.eu/user_avatar/forum.cpcwiki.eu/dthrone/32/164_2.png) [@dthrone](https://forum.cpcwiki.eu/u/dthrone)\
**Post date:** [October 27, 2026, 7:52pm UTC](https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029/2 "2026-10-27T19:52:47Z")

</div>

Clever implementation! 👍

---

<div class="post-metadata">

**Author:** ![BSC](https://forum.cpcwiki.eu/user_avatar/forum.cpcwiki.eu/bsc/32/23_2.png) [@BSC](https://forum.cpcwiki.eu/u/BSC)\
**Post date:** [October 27, 2026, 8:22pm UTC](https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029/3 "2026-10-27T20:22:56Z")

</div>

Yes, really clever and it plays nicely. Congrats!

---

<div class="post-metadata">

**Author:** ![Rambo](https://forum.cpcwiki.eu/user_avatar/forum.cpcwiki.eu/rambo/32/1251_2.png) [@Rambo](https://forum.cpcwiki.eu/u/Rambo)\
**Post date:** [October 28, 2026, 7:49pm UTC](https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029/4 "2026-10-28T19:49:33Z")

</div>

really super original, I wish I knew how to make this kind of game. thanks

---

<div class="post-metadata">

**Author:** ![lightforce6128](https://forum.cpcwiki.eu/user_avatar/forum.cpcwiki.eu/lightforce6128/32/32_2.png) [@lightforce6128](https://forum.cpcwiki.eu/u/lightforce6128)\
**Post date:** [October 29, 2026, 12:58am UTC](https://forum.cpcwiki.eu/t/tetris-in-pure-basic/1029/5 "2026-10-29T00:58:38Z")

</div>

I like the usage of scrolling in a BASIC text window to delete a line. This would be slow otherwise or require machine code.
