Slide 1

Slide 1 text

GameDev with QBasic 2019 Levi D. Smith

Slide 2

Slide 2 text

History • BASIC – Beginner’s All-purpose Symbolic Instruction Code • QBasic standard on DOS 5.0 command prompt

Slide 3

Slide 3 text

Running QBasic with DosBox • Install DOSBox • Recommended defaults • windowresolution=1024x768 • Output=opengl • [autoexec] mount C “C:\program files (x86)\DOSBox-0.74\qbasic” • Download Qbasic executable • Set default folder • C:\Users\\AppData\Local\DOSBox\dosbox-.conf • Filenames must be 8.3 format

Slide 4

Slide 4 text

Example Qbasic Games • Before Internet access, all we had was looking at example code • Nibbles • Gorilla • Programming books weren’t prevalent at book stores • QBasic comes with built-in help pages

Slide 5

Slide 5 text

Using QBasic • Shift + F5 - Run Game • F2 - View Subs • Alt, F, O - Load program • Ctrl + C - end program

Slide 6

Slide 6 text

A Simple Game PRINT display text and variables INPUT read input from user DO WHILE / LOOP control structure IF THEN, ELSEIF, ELSE, END IF control structure >, <, <>, = comparison operators = assignment RANDOMIZE TIMER, RND generate random number INT cast as integer + Arithmetic

Slide 7

Slide 7 text

A Simple Game

Slide 8

Slide 8 text

Drawing Primitives – Lines and Rectangles • Screen Mode • SCREEN 7 – 320x200, 16 colors • SCREEN 12 – 640x480, 256K colors • Lines and Rectangles • From, To, Color, Type

Slide 9

Slide 9 text

Drawing Primitives - Circles • Circles • Center, Radius, Color, Start Angle, End Angle, Aspect Ratio • Filled Circle • Paint – location, fill color, border color • Slow

Slide 10

Slide 10 text

Drawing Shapes • Define pen movements (up, down, left, right, etc) with unit distance as a string • Use BM to set starting point

Slide 11

Slide 11 text

Displaying Text • Use LOCATE x, y to set text position • PRINT to display strings and variables • Separate parameters with semicolon (;) • Comma (,) separated parameters will be extra spaced

Slide 12

Slide 12 text

Playing Music • Use Play with string • O – Octave • L – Length • CDEFGAB – Notes • Sound (frequency, duration)

Slide 13

Slide 13 text

Structures • TYPE to define structure • data types – INTEGER, LONG, SINGLE, DOUBLE, STRING • DIM to instantiate • Array – DIM foo(1 TO N) AS TYPE

Slide 14

Slide 14 text

Procedures • F2 – show procedures • SUB – Sub procedure (does not return a value) • Can pass custom types (define type before sub declaration) • FUNCTION – Returns a value • Assign value to function name (don’t use “return”) • Global variable – use COMMON SHARED

Slide 15

Slide 15 text

User Input • Read keyboard with INKEY$ • IBM PC Keyboard Scan Codes • http://www.jimprice.com/jim-asc.shtml#keycodes • Arrows • Up: CHR$(0) + CHR$(72) • Down: CHR$(0) + CHR$(80) • Right: CHR$(0) + CHR$(77) • Left: CHR$(0) + CHR$(75)

Slide 16

Slide 16 text

Delay • FOR a# = 1 TO curSpeed: NEXT a#

Slide 17

Slide 17 text

References • https://bitbucket.org/dylanwolf/oldgames/src/default/ • https://github.com/gatechgrad/QBasicMiniGames • https://www.dosbox.com/ • https://www.qbasic.net/ • http://www.petesqbsite.com/