Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Small Game Tutorial (from 2014)
#1
Digging through some old junk on old drives once again, and I found more QB64 goodies.   This one is a HTML tutorial on making a little space avoidance type game, and from initial testing all still works as it should -- even after almost 10 years!  (This file was dated 6/6/2014 on my drive!)

The final version has you making this game:

Code: (Select All)
_TITLE "Space 64"

DIM asteroidx(100), asteroidy(100), asteroidspeed(100)

SCREEN 13



DATA 000,000,000,000,000,000,000,000,000,000
DATA 000,000,015,015,015,015,015,000,000,000
DATA 000,015,015,015,015,007,007,015,000,000
DATA 000,015,015,015,015,015,015,015,015,000
DATA 000,015,015,015,015,015,015,015,015,015
DATA 000,015,015,015,015,015,015,015,015,000
DATA 000,000,015,015,015,015,015,015,000,000
DATA 000,000,000,000,000,000,000,000,000,000
DATA 000,000,000,000,000,000,000,000,000,000
DATA 000,000,000,000,000,000,000,000,000,000

FOR y = 1 TO 10
FOR x = 1 TO 10

READ c
PSET (x, y), c
NEXT
NEXT

ship = _NEWIMAGE(11, 11, 13)

_PUTIMAGE (1, 1)-(10, 10), , ship, (1, 1)-(10, 10)

CLS

DATA 000,000,000,000,000,000,000,000,000,000
DATA 000,000,000,006,006,006,000,000,000,000
DATA 000,000,006,006,006,006,006,000,000,000
DATA 000,006,012,006,006,006,006,006,000,000
DATA 000,006,006,006,006,012,006,006,000,000
DATA 000,006,006,006,006,006,006,006,000,000
DATA 000,000,006,006,012,006,006,000,000,000
DATA 000,000,006,006,006,006,000,000,000,000
DATA 000,000,000,006,006,000,000,000,000,000
DATA 000,000,000,000,000,000,000,000,000,000

FOR y = 1 TO 10
FOR x = 1 TO 10

READ c
PSET (x, y), c
NEXT
NEXT

obstacle = _NEWIMAGE(11, 11, 13)

_PUTIMAGE (1, 1)-(10, 10), , obstacle, (1, 1)-(10, 10)

CLS

DATA 000,000,000,000,000,000,000,000,000,000
DATA 000,000,004,004,000,004,004,000,000,000
DATA 000,004,012,012,004,012,012,004,000,000
DATA 000,004,012,012,012,012,012,004,000,000
DATA 000,004,012,012,012,012,012,004,000,000
DATA 000,004,012,012,012,012,012,004,000,000
DATA 000,000,004,012,012,012,004,000,000,000
DATA 000,000,000,004,012,004,000,000,000,000
DATA 000,000,000,000,004,000,000,000,000,000
DATA 000,000,000,000,000,000,000,000,000,000


FOR y = 1 TO 10
FOR x = 1 TO 10

READ c
PSET (x, y), c
NEXT
NEXT

life = _NEWIMAGE(11, 11, 13)

_PUTIMAGE (1, 1)-(10, 10), , life, (1, 1)-(10, 10)

CLS

lives = 3

shipx = 10 'we set the x position of the ship to 10 and the y position is set
shipy = 95 'at the middle of the screen (middle of the ship is 5 hence 100-5=95).

DO

_LIMIT 60
CLS

IF explosion = 0 THEN
_PUTIMAGE (shipx, shipy), ship 'let's only display it when explosion = 0

'we can make some fire behind the ship by randomly setting some red pixels behind it.
FOR k = 1 TO 10: PSET (shipx - INT(RND * 5), shipy + INT(RND * 6) + 2), 4: NEXT
END IF


'display lives:
IF lives > 0 THEN
FOR k = 1 TO lives
_PUTIMAGE (k * 10, 0), life
NEXT

END IF

'display number of numbers collected:
_PRINTSTRING (0, 2), LTRIM$(STR$(collected))


IF _KEYDOWN(CVI(CHR$(0) + "H")) THEN shipy = shipy - 1
IF _KEYDOWN(CVI(CHR$(0) + "P")) THEN shipy = shipy + 1
IF _KEYDOWN(CVI(CHR$(0) + "K")) THEN shipx = shipx - 1
IF _KEYDOWN(CVI(CHR$(0) + "M")) THEN shipx = shipx + 1
IF _KEYDOWN(27) THEN END


IF shipx + 10 > 319 THEN shipx = 319 - 10
IF shipx < 0 THEN shipx = 0
IF shipy + 10 > 199 THEN shipy = 199 - 10
IF shipy < 0 THEN shipy = 0


IF numasteroids > 0 THEN
FOR asteroid = 1 TO numasteroids

_PUTIMAGE (asteroidx(asteroid), asteroidy(asteroid)), obstacle

IF explosion = 0 THEN 'this is added so that the ship doesn't explode twice (it is invulnerable for a while)

IF shipx + 10 >= asteroidx(asteroid) AND shipx <= asteroidx(asteroid) + 10 THEN
IF shipy + 10 >= asteroidy(asteroid) AND shipy <= asteroidy(asteroid) + 10 THEN


explosion = 1
lives = lives - 1

END IF
END IF

END IF

asteroidx(asteroid) = asteroidx(asteroid) - asteroidspeed(asteroid)



IF asteroidx(asteroid) < 0 - 10 THEN
removeasteroid = asteroid
END IF


NEXT
END IF


IF removeasteroid <> 0 THEN
FOR k = removeasteroid TO numasteroids
asteroidx(k) = asteroidx(k + 1)
asteroidy(k) = asteroidy(k + 1)
asteroidspeed(k) = asteroidspeed(k + 1)
NEXT
numasteroids = numasteroids - 1
removeasteroid = 0
END IF




IF explosion = 1 THEN
expl = expl + 1

FOR k = 1 TO expl
PSET (shipx - INT(RND * k), shipy - INT(RND * k)), INT(RND * 255)
PSET (shipx + INT(RND * k), shipy + INT(RND * k)), INT(RND * 255)
PSET (shipx - INT(RND * k), shipy + INT(RND * k)), INT(RND * 255)
PSET (shipx + INT(RND * k), shipy - INT(RND * k)), INT(RND * 255)
NEXT
IF expl > 30 THEN expl = 0: explosion = 0
END IF


rand = INT(RND * (30 - (collected * 3))) + 1 '(collected*3) makes the asteroids more frequent
IF rand = 1 THEN
numasteroids = numasteroids + 1
asteroidx(numasteroids) = 319 + 10
asteroidy(numasteroids) = INT(RND * 219) + 1
asteroidspeed(numasteroids) = RND * 1.5 + .5 + ((collected + 1) / 50) '(collected+1)/50 makes them faster
END IF



IF heart = 0 THEN 'only if heart is 0 should we create one (it is already created otherwise)
rand = INT(RND * 1000) + 1 'very seldom does a heart arrive
IF rand = 1 THEN
heart = 1
heartx = 319 + 10
hearty = INT(RND * 219) + 1
heartspeed = RND * 1.5 + .5
END IF
END IF

'here we display the heart and handles the collision for the heart:
IF heart = 1 THEN
_PUTIMAGE (heartx, hearty), life
heartx = heartx - heartspeed

IF heartx < -10 THEN heart = 0 'remove it if it goes outside the screen.

IF shipx + 10 >= heartx AND shipx <= heartx + 10 THEN
IF shipy + 10 >= hearty AND shipy <= hearty + 10 THEN
'it collided with the heart!
heart = 0 'set heart to 0 to remove it
lives = lives + 1 'add 1 to lives

END IF
END IF

END IF

'we do the same for the numbers as with the heart:
IF number = 0 THEN
rand = INT(RND * 500) + 1 'very seldom does a number arrive
IF rand = 1 THEN
number = 1
numberx = 319 + 10
numbery = INT(RND * 219) + 1
numberspeed = RND * 1.5 + .5
END IF
END IF

'here we display the number and handle the collision for the number:
IF number = 1 THEN
_PRINTSTRING (numberx, numbery), STR$(collected + 1) 'we use printstring to represent the number
numberx = numberx - numberspeed
IF numberx < -10 THEN number = 0
IF shipx + 10 >= numberx AND shipx <= numberx + 10 THEN
IF shipy + 10 >= numbery AND shipy <= numbery + 10 THEN
'it collided with the number!
collected = collected + 1 'add one to the collected numbers
number = 0 'set number to 0 to remove it
END IF
END IF
END IF



'loose:
IF lives < 0 THEN
LOCATE 10, 15: PRINT "GAME OVER"
_DISPLAY: END
END IF

'win:
IF collected = 9 THEN
LOCATE 10, 16: PRINT "YOU WIN"
_DISPLAY: END
END IF



_DISPLAY
LOOP


And the whole tutorial file is here:
.html   A_Small_Game_Tutorial.html (Size: 52.38 KB / Downloads: 103)
Reply
#2
A few more old tutorials from back in the same time frame.

BASIC Programing Basics Tutorial --> 
.html   BASIC_Programming_Basics.html (Size: 51.28 KB / Downloads: 143)
Graphics with QB64 -->
.html   Graphics_with_QB64.html (Size: 19.01 KB / Downloads: 103)
Reply
#3
Graphic example Earth: I get an error message at 17, 32, 41.

The link to the image doesn't work - clearly, it's too old. Here is a "new earth".  Big Grin

[Image: Erde-frei.jpg]
Reply




Users browsing this thread: 1 Guest(s)