'This game has been made from my Walls Detector Example program.
'You are the blue tank and you move with the arrow keys and shoot the red tank with the space bar.
'You can control the direction of your shot by using the arrow keys as it flies.
'But first you have to make a walls layout picture using my 'Ken's Plotter' program which can be found on my website here: http://ken.x10host.com/qb64/
'Which is very simple, you just plot using the arrow keys and space bar. All instructions are on that program.
'Make many layout pictures and have a BLAST!
'I call the enemy a 'monster' in my code because at first this was going to be just shooting monsters but it turned out to be more like tanks.
'This game was made on June 30, 2019 by Ken G.
'Feel free to edit this code how you wish but do not sell it. This game took a couple weeks to make both programs and is something I've wanted to make for a very long time.
start:
'You will need to DIM these strings and variables first to make memory.
DIM x$
(10000), y$
(10000), x
(10000), y
(10000) _TITLE "Tank Walls Score: 0 Lives: 5" points = 0
lives = 5
mshot = 0
shot = 0
ds = 1
dd = 1
sht = 0
sht2 = 0
'xx and yy are the coordinates to your blue tank and others are the turrent locations of the tank.
xx = 320: yy = 240
leftxt = xx - 4: leftyt = yy + 2: leftxxt = xx: leftyyt = yy + 3
rightxt = xx + 5: rightyt = yy + 2: rightxxt = xx + 9: rightyyt = yy + 3
upxt = xx + 2: upyt = yy - 4: upxxt = xx + 3: upyyt = yy
downxt = xx + 2: downyt = yy + 5: downxxt = xx + 3: downyyt = yy + 9
PRINT "This is an example game on how to use any picture you make" PRINT "to turn into a game that shoots a computer tank." PRINT "First you need to create a picture or maze using 'Ken's Plotter'." PRINT "Make many layout pictures to use with this game and have a BLAST!" PRINT "Use your arrow keys to move the little blue square tank around and it will" PRINT "stop at every wall. You start out in the very center" PRINT "of the window. The enemy tank is the red square and it will be" PRINT "randomly placed within the walls." PRINT "When you are in line with the green square tank," PRINT "press the Space Bar to fire a shot at him." PRINT "Notice how your shot stops at every wall it hits and if you hit" PRINT "the enemy, it will make a small explosion." PRINT "You start off with 5 lives, when all 5 are gone, the game is over." PRINT "You get 10 points for every Enemy Tank you hit." PRINT "You can control the direction of your shot by using the arrow" PRINT "keys as it flies." again:
INPUT "Type file name of picture to load (without the .txt ending):", nm$
nm$ = nm$ + ".txt"
PRINT "File does not exist, try again." 'First you load the picture and put every coordinate into memory.
ggo:
p = p + 1
x
(p
) = VAL(x$
(p
)): y
(p
) = VAL(y$
(p
))LINE (x
(p
), y
(p
))-(x
(p
) + 10, y
(p
) + 10), _RGB32(255, 255, 255), BF
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(127, 127, 255), BF
LINE (upxt
, upyt
)-(upxxt
, upyyt
), _RGB32(127, 127, 255), BF
'Start monster location
place:
IF xxx
> x
(tt
) - 15 AND xxx
< x
(tt
) + 15 AND yyy
> y
(tt
) - 15 AND yyy
< y
(tt
) + 15 THEN GOTO place:
LINE (xxx
, yyy
)-(xxx
+ 5, yyy
+ 5), _RGB32(255, 0, 0), BF
leftxt2 = xxx - 4: leftyt2 = yyy + 2: leftxxt2 = xxx: leftyyt2 = yyy + 3
rightxt2 = xxx + 5: rightyt2 = yyy + 2: rightxxt2 = xxx + 9: rightyyt2 = yyy + 3
upxt2 = xxx + 2: upyt2 = yyy - 4: upxxt2 = xxx + 3: upyyt2 = yyy
downxt2 = xxx + 2: downyt2 = yyy + 5: downxxt2 = xxx + 3: downyyt2 = yyy + 9
ds = 2
LINE (downxt2
, downyt2
)-(downxxt2
, downyyt2
), _RGB32(255, 0, 0), BF
'Here is the main loop of the program where you move the square around.
go:
ds = 1
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(0, 0, 0), BF
yy = yy - 5
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(127, 127, 255), BF
upxt = xx + 2: upyt = yy - 4: upxxt = xx + 3: upyyt = yy
LINE (upxt
, upyt
)-(upxxt
, upyyt
), _RGB32(127, 127, 255), BF
ds = 2
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(0, 0, 0), BF
yy = yy + 5
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(127, 127, 255), BF
downxt = xx + 2: downyt = yy + 5: downxxt = xx + 3: downyyt = yy + 9
LINE (downxt
, downyt
)-(downxxt
, downyyt
), _RGB32(127, 127, 255), BF
ds = 3
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(0, 0, 0), BF
xx = xx - 5
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(127, 127, 255), BF
leftxt = xx - 4: leftyt = yy + 2: leftxxt = xx: leftyyt = yy + 3
LINE (leftxt
, leftyt
)-(leftxxt
, leftyyt
), _RGB32(127, 127, 255), BF
ds = 4
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(0, 0, 0), BF
xx = xx + 5
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(127, 127, 255), BF
rightxt = xx + 5: rightyt = yy + 2: rightxxt = xx + 9: rightyyt = yy + 3
LINE (rightxt
, rightyt
)-(rightxxt
, rightyyt
), _RGB32(127, 127, 255), BF
'Here is where the computer checks to see if your tank hits a wall.
check:
IF xx
> x
(t
) - 10 AND xx
< x
(t
) + 15 AND yy
> y
(t
) - 10 AND yy
< y
(t
) + 15 THEN xx
= oldxx: yy
= oldyy
oldtank:
oldyy = yy
oldxx = xx
oldleftxt = leftxt: oldleftyt = leftyt: oldleftxxt = leftxxt: oldleftyyt = leftyyt
oldrightxt = rightxt: oldrightyt = rightyt: oldrightxxt = rightxxt: oldrightyyt = rightyyt
oldupxt = upxt: oldupyt = upyt: oldupxxt = upxxt: oldupyyt = upyyt
olddownxt = downxt: olddownyt = downyt: olddownxxt = downxxt: olddownyyt = downyyt
oldtank2:
LINE (oldleftxt
, oldleftyt
)-(oldleftxxt
, oldleftyyt
), _RGB32(0, 0, 0), BF
LINE (oldrightxt
, oldrightyt
)-(oldrightxxt
, oldrightyyt
), _RGB32(0, 0, 0), BF
LINE (oldupxt
, oldupyt
)-(oldupxxt
, oldupyyt
), _RGB(0, 0, 0), BF
LINE (olddownxt
, olddownyt
)-(olddownxxt
, olddownyyt
), _RGB(0, 0, 0), BF
shoot:
shot = 1
sx = xx + 3: sy = yy - 4
sx = xx + 3: sy = yy + 10
sx = xx - 4: sy = yy + 3
sx = xx + 10: sy = yy + 4
'Up
sy = sy - 10
shoot1:
LINE (oldsx
+ 3, oldsy
+ 3)-(oldsx
- 3, oldsy
- 3), _RGB32(0, 0, 0), BF
sy = sy - 3
oldsx = sx: oldsy = sy
'Down
sy = sy + 10
shoot2:
LINE (oldsx
- 3, oldsy
- 3)-(oldsx
+ 3, oldsy
+ 3), _RGB32(0, 0, 0), BF
sy = sy + 3
oldsx = sx: oldsy = sy
'Left
sx = sx - 10
shoot3:
LINE (oldsx
+ 3, oldsy
+ 3)-(oldsx
- 3, oldsy
- 3), _RGB32(0, 0, 0), BF
sx = sx - 3
oldsx = sx: oldsy = sy
'Right
sx = sx + 10
shoot4:
LINE (oldsx
- 3, oldsy
- 3)-(oldsx
+ 3, oldsy
+ 3), _RGB32(0, 0, 0), BF
sx = sx + 3
oldsx = sx: oldsy = sy
checkshot:
'Check your shot distance.
sht = sht + 1
sht = 0
shot = 0
'Check walls and enemy.
IF sx
> x
(tt
) - 10 AND sx
< x
(tt
) + 10 AND sy
> y
(tt
) - 10 AND sy
< y
(tt
) + 10 THEN shot = 0
sht = 0
IF sx
> xxx
- 10 AND sx
< xxx
+ 10 AND sy
> yyy
- 10 AND sy
< yyy
+ 10 THEN points = points + 10
titl$ = "Tank Walls Score:" + points$ + " Lives:" + lives$
LINE (sx
- 4, sy
- 4)-(sx
+ 4, sy
+ 4), _RGB32(0, 0, 0), BF
LINE (xxx
- 5, yyy
- 5)-(xxx
+ 6, yyy
+ 6), _RGB32(0, 0, 0), BF
shot = 0
mshot = 0
sht = 0
'Your direction check to erase your old shot.
dscheck:
'--------------------------------------------------------------------------------------------
'The last half of this program is what the enemy tank does.
'--------------------------------------------------------------------------------------------
monster:
dd = 1
dd = 2
dd = 3
dd = 4
monsters:
xxx = xxx - 5
notcloser1:
LINE (oldxxx
, oldyyy
)-(oldxxx
+ 5, oldyyy
+ 5), _RGB(0, 0, 0), BF
LINE (xxx
, yyy
)-(xxx
+ 5, yyy
+ 5), _RGB32(255, 0, 0), BF
leftxt2 = xxx - 4: leftyt2 = yyy + 2: leftxxt2 = xxx: leftyyt2 = yyy + 3
LINE (leftxt2
, leftyt2
)-(leftxxt2
, leftyyt2
), _RGB32(255, 0, 0), BF
xxx = xxx + 5
notcloser2:
LINE (oldxxx
, oldyyy
)-(oldxxx
+ 5, oldyyy
+ 5), _RGB(0, 0, 0), BF
LINE (xxx
, yyy
)-(xxx
+ 5, yyy
+ 5), _RGB32(255, 0, 0), BF
rightxt2 = xxx + 5: rightyt2 = yyy + 2: rightxxt2 = xxx + 9: rightyyt2 = yyy + 3
LINE (rightxt2
, rightyt2
)-(rightxxt2
, rightyyt2
), _RGB32(255, 0, 0)
yyy = yyy - 5
notcloser3:
LINE (oldxxx
, oldyyy
)-(oldxxx
+ 5, oldyyy
+ 5), _RGB(0, 0, 0), BF
LINE (xxx
, yyy
)-(xxx
+ 5, yyy
+ 5), _RGB32(255, 0, 0), BF
upxt2 = xxx + 2: upyt2 = yyy - 4: upxxt2 = xxx + 3: upyyt2 = yyy
LINE (upxt2
, upyt2
)-(upxxt2
, upyyt2
), _RGB32(255, 0, 0), BF
yyy = yyy + 5
notcloser4:
LINE (oldxxx
, oldyyy
)-(oldxxx
+ 5, oldyyy
+ 5), _RGB(0, 0, 0), BF
LINE (xxx
, yyy
)-(xxx
+ 5, yyy
+ 5), _RGB32(255, 0, 0), BF
downxt2 = xxx + 2: downyt2 = yyy + 5: downxxt2 = xxx + 3: downyyt2 = yyy + 9
LINE (downxt2
, downyt2
)-(downxxt2
, downyyt2
), _RGB32(255, 0, 0), BF
mshot = 1
oldmonster:
oldxxx = xxx
oldyyy = yyy
oldleftxt2 = leftxt2: oldleftyt2 = leftyt2: oldleftxxt2 = leftxxt2: oldleftyyt2 = leftyyt2
oldrightxt2 = rightxt2: oldrightyt2 = rightyt2: oldrightxxt2 = rightxxt2: oldrightyyt2 = rightyyt2
oldupxt2 = upxt2: oldupyt2 = upyt2: oldupxxt2 = upxxt2: oldupyyt2 = upyyt2
olddownxt2 = downxt2: olddownyt2 = downyt2: olddownxxt2 = downxxt2: olddownyyt2 = downyyt2
oldmonster2:
LINE (oldleftxt2
, oldleftyt2
)-(oldleftxxt2
, oldleftyyt2
), _RGB32(0, 0, 0), BF
LINE (oldrightxt2
, oldrightyt2
)-(oldrightxxt2
, oldrightyyt2
), _RGB32(0, 0, 0), BF
LINE (oldupxt2
, oldupyt2
)-(oldupxxt2
, oldupyyt2
), _RGB(0, 0, 0), BF
LINE (olddownxt2
, olddownyt2
)-(olddownxxt2
, olddownyyt2
), _RGB(0, 0, 0), BF
checkmonster:
IF xxx
> x
(tt
) - 10 AND xxx
< x
(tt
) + 15 AND yyy
> y
(tt
) - 10 AND yyy
< y
(tt
) + 15 THEN xxx = oldxxx: yyy = oldyyy
checkdone:
monstershot:
mx = xxx - 4: my = yyy + 3
mx = xxx + 10: my = yyy + 4
mx = xxx + 3: my = yyy - 4
mx = xxx + 3: my = yyy + 10
oldmx = mx
oldmy = my
monstershot2:
'Left
mshot1:
LINE (oldmx
- 3, oldmy
- 3)-(oldmx
+ 3, oldmy
+ 3), _RGB32(0, 0, 0), BF
mx = mx - 3
oldmx = mx: oldmy = my
'Right
mshot2:
LINE (oldmx
- 3, oldmy
- 3)-(oldmx
+ 3, oldmy
+ 3), _RGB32(0, 0, 0), BF
mx = mx + 3
oldmx = mx: oldmy = my
'Up
mshot3:
LINE (oldmx
- 3, oldmy
- 3)-(oldmx
+ 3, oldmy
+ 3), _RGB32(0, 0, 0), BF
my = my - 3
oldmx = mx: oldmy = my
'Down
mshot4:
LINE (oldmx
- 3, oldmy
- 3)-(oldmx
+ 3, oldmy
+ 3), _RGB32(0, 0, 0), BF
my = my + 3
oldmx = mx: oldmy = my
mcheckshot:
'Check his shot distance.
sht2 = sht2 + 1
sht2 = 0
mshot = 0
'Check walls and if it hit your tank for his shot.
IF mx
> x
(tt
) - 10 AND mx
< x
(tt
) + 10 AND my
> y
(tt
) - 10 AND my
< y
(tt
) + 10 THEN mshot = 0
sht2 = 0
LINE (mx
- 4, my
- 4)-(mx
+ 4, my
+ 4), _RGB32(0, 0, 0), BF
sht2 = 0
mshot = 0
lives = lives - 1
titl$ = "Tank Walls Score:" + points$ + " Lives:" + lives$
LINE (xx
- 5, yy
- 5)-(xx
+ 6, yy
+ 6), _RGB32(0, 0, 0), BF
LINE (xxx
- 5, yyy
- 5)-(xxx
+ 6, yyy
+ 6), _RGB32(0, 0, 0), BF
xx = 320: yy = 240
LINE (xx
, yy
)-(xx
+ 5, yy
+ 5), _RGB32(127, 127, 255), BF
a$ = ""
INPUT "Play Again (Yes/No)"; ag$
IF ag$
= "yes" OR ag$
= "YES" OR ag$
= "Yes" OR ag$
= "yES" OR ag$
= "YEs" OR ag$
= "Y" OR ag$
= "y" THEN GOTO start:
'His direction check to erase his old shot.
ddcheck: