# QBasic Games

Contents: Click for quick access

## Introduction

The world of computing has made significant progress since the early days of personal computers. Back then, high-definition graphics and complex game engines were not yet available. Instead, there was QBasic, a simple but powerful programming language that brought joy to many people interested in game development. In this blog, we’ll look back at some of the memorable QBasic games that left a lasting impression on players in the past.

## 1. Gorillas

Do you remember those days when you and your friend would have exciting battles using explosive bananas? Gorillas was one of the earliest QBasic games that introduced many of us to this world. It was a fun two-player game where each player controlled a gorilla on top of a building, and the goal was to throw bananas at each other. The challenge was to adjust the angle and speed of the throw correctly to hit the other gorilla before it was their turn to retaliate. It was a straightforward game but so much fun that you couldn’t stop playing!

``````SCREEN 12

' Set up the game
DIM SHARED Pi, Gravity
CONST MaxTurns = 5
CONST Speed = 1
CONST Pi = 3.14159
CONST Gravity = 0.2

' Function to clear the screen
SUB ClearScreen
LOCATE 1, 1
PRINT STRING\$(25 * 80, " ");
END SUB

' Function to draw the gorillas
SUB DrawGorilla(x, y)
CIRCLE (x, y), 15, , 15, 15
LINE (x, y)-(x - 20, y + 30), 15, B
LINE (x, y)-(x + 20, y + 30), 15, B
LINE (x - 15, y + 30)-(x + 15, y + 30), 15, B
END SUB

' Function to display the game over screen
SUB GameOver
ClearScreen
LOCATE 12, 30
PRINT "GAME OVER"
SLEEP 2
END SUB

' Main game loop
DO
' Clear the screen
ClearScreen

' Draw the gorillas
DrawGorilla(100, 200)
DrawGorilla(500, 200)

' Get player input for angle and velocity
LOCATE 24, 1
INPUT "Angle (0-90): ", Angle
IF Angle < 0 OR Angle > 90 THEN
PRINT "Invalid angle. Please enter a value between 0 and 90."
SLEEP 1
CONTINUE DO
END IF

LOCATE 24, 1
PRINT "                                                        ";

LOCATE 24, 1
INPUT "Velocity (1-10): ", Velocity
IF Velocity < 1 OR Velocity > 10 THEN
PRINT "Invalid velocity. Please enter a value between 1 and 10."
SLEEP 1
CONTINUE DO
END IF

LOCATE 24, 1
PRINT "                                                        ";

' Calculate the initial horizontal and vertical velocities
VelX = Velocity * COS(Angle * Pi / 180)
VelY = Velocity * SIN(Angle * Pi / 180)

' Start the projectile at the first gorilla's position
X = 100
Y = 200

' Main projectile loop
DO
' Draw the projectile
PSET (X, Y), 4

' Update the projectile's position and velocity
VelY = VelY + Gravity
X = X + VelX * Speed
Y = Y - VelY * Speed

' Check for collision with the ground
IF Y >= 200 THEN
GameOver
EXIT DO
END IF

' Check for collision with the second gorilla
IF X >= 480 AND X <= 520 AND Y >= 170 THEN
ClearScreen
LOCATE 12, 30
PRINT "Player 1 wins!"
SLEEP 2
EXIT DO
END IF

' Check for collision with the first gorilla
IF X >= 80 AND X <= 120 AND Y >= 170 THEN
ClearScreen
LOCATE 12, 30
PRINT "Player 2 wins!"
SLEEP 2
EXIT DO
END IF

' Slow down the game loop
SLEEP 50

' Erase the previous position of the projectile
PSET (X, Y), 0
LOOP

' Decrement the number of turns remaining
Turns = Turns - 1

LOOP UNTIL Turns = 0

' End of game
ClearScreen
LOCATE 12, 30
PRINT "Game Over. Thanks for playing!"
SLEEP 2``````

## 2. Nibbles (Snake)

Snake games are always popular, and QBasic had its version called Nibbles, which was just as timeless. In Nibbles, players controlled a snake on the screen, and the aim was to eat apples and make the snake longer. But they had to be careful not to run into the snake’s own body or the walls, as that would mean game over. It was a game that required quick reflexes and smart thinking – a true classic!

``````SCREEN 12

' Set up the game
DIM SHARED Map(80, 25), Snake(100, 2)
CONST MaxLength = 100
CONST SnakeSpeed = 40

' Function to draw the snake
SUB DrawSnake
FOR i = 1 TO SnakeLength
PSET (Snake(i, 1), Snake(i, 2)), 15
NEXT i
END SUB

' Function to move the snake
SUB MoveSnake
FOR i = SnakeLength TO 2 STEP -1
Snake(i, 1) = Snake(i - 1, 1)
Snake(i, 2) = Snake(i - 1, 2)
NEXT i
Snake(1, 1) = Snake(1, 1) + XDir
Snake(1, 2) = Snake(1, 2) + YDir
END SUB

' Main game loop
DO
' Clear the screen
LOCATE 1, 1
PRINT STRING\$(25 * 80, " ");

' Draw the snake
DrawSnake

' Move the snake
MoveSnake

' Check for collision with the walls
IF Snake(1, 1) < 0 OR Snake(1, 1) > 79 OR Snake(1, 2) < 0 OR Snake(1, 2) > 24 THEN
PRINT "Game Over. Hit the wall!"
SLEEP 2
END
END IF

' Check for collision with the snake's body
FOR i = 2 TO SnakeLength
IF Snake(1, 1) = Snake(i, 1) AND Snake(1, 2) = Snake(i, 2) THEN
PRINT "Game Over. Ate itself!"
SLEEP 2
END
END IF
NEXT i

' Slow down the game loop
SLEEP SnakeSpeed

LOOP UNTIL INKEY\$ = CHR\$(27) ' Press Esc to exit the game

' End of game
END
``````

## 3. QBasic Trek

Before the complex space exploration games we have now, there was QBasic Trek, a text-based adventure set in outer space. In this game, players controlled a starship and traveled through the galaxy, meeting different alien races and having tactical battles. The game’s simple text interface allowed us to use our imaginations to explore strange and exciting worlds right on our computer screens.

## 4. QBert

QBert was a fun platform game where players controlled a lovable character hopping on cubes arranged like a pyramid. The goal was to change the color of each cube by landing on it, but players had to be careful of pesky enemies that could knock QBert off the pyramid. It was a charming and captivating game with a playful design that appealed to players of all ages.

## 5. QBasic Chess

QBasic Chess was a game perfect for chess enthusiasts who enjoy the mental challenge of the game. The graphics might have been simple, but the chess engine was strong, allowing players to play against the computer at different difficulty levels. Many chess enthusiasts spent lots of time on this game, practicing and improving their strategies and tactics in this digital chess battleground.

``````SCREEN 12

DIM SHARED Board(8, 8)

' Function to initialize the chessboard
SUB InitBoard
' Set up the initial board positions
' (Fill the Board array with values representing pieces on the board)
END SUB

' Function to draw the chessboard
SUB DrawBoard
' Draw the chessboard grid and pieces based on the Board array
END SUB

' Main game loop
DO
' Clear the screen
LOCATE 1, 1
PRINT STRING\$(25 * 80, " ");

' Draw the chessboard
DrawBoard

' Get player input for the move
' (Implement input handling to get the source and destination positions)

' Check if the move is valid
' (Implement validation of moves based on the rules of chess)

' Update the board and check for checkmate/stalemate
' (Implement the logic for updating the board and checking for game-over conditions)

' Check for computer moves (if AI is implemented)
' (Implement AI logic to make computer moves)

LOOP UNTIL INKEY\$ = CHR\$(27) ' Press Esc to exit the game

' End of game
END
``````

## Conclusion

As we look back at these classic QBasic games, we can’t help but feel a sense of nostalgia for a simpler time in computing history. These games weren’t just about entertainment; they sparked creativity and curiosity, laying the foundation for many future game developers and programmers.

While modern gaming has evolved into a stunning realm of virtual reality and cutting-edge graphics, there’s something special about the unassuming charm of QBasic games. They remind us of the joy we found in simplicity and the thrill of exploring uncharted territories within the digital realm.