Skip to content

Instantly share code, notes, and snippets.

@nfarina
Created October 26, 2022 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfarina/508e2e64e346efcb87e4bcb26469771c to your computer and use it in GitHub Desktop.
Save nfarina/508e2e64e346efcb87e4bcb26469771c to your computer and use it in GitHub Desktop.
'Declare statements
DECLARE SUB playGame ()
DECLARE SUB setParms ()
DECLARE SUB clearTanks ()
DECLARE SUB checkGround ()
DECLARE SUB explodeTank ()
DECLARE SUB fireShotRight ()
DECLARE SUB fireShotLeft ()
DECLARE SUB getInfoRight ()
DECLARE FUNCTION rightRads! ()
DECLARE SUB drawLeftVelocity ()
DECLARE SUB drawRightVelocity ()
DECLARE FUNCTION leftRads! ()
DECLARE SUB drawTurretRight (turretColor!)
DECLARE SUB drawTurretLeft (turretColor!)
DECLARE SUB getInfoLeft ()
DECLARE SUB getInfo (tankNo!)
DECLARE SUB createTanks ()
DECLARE SUB findTanks (leftPos!, rightPos!)
DECLARE SUB createTerrain ()
'Global variables
COMMON SHARED range, rangeStart, nonZero, hitTank, hitGround, backgroundColor
COMMON SHARED terrainColor, turretColor, shellColor, trailColor, shotExpSize
COMMON SHARED turretLength, tankSize, tankColor, x, y, explodeSize, explodeStep
COMMON SHARED leftDownPos, leftPos, rightDownPos, rightPos, hitTankBefore
COMMON SHARED degs, rads, left, right, tankNo, shotAccuracy, retrace
COMMON SHARED leftVelocity, rightVelocity, leftDegrees, rightDegrees
COMMON SHARED degInc, velInc, xOld, yOld, leftStartPos, leftStartDownPos
COMMON SHARED rightStartPos, rightStartDownPos, originalTrailColor, wind
COMMON SHARED groundLeftParm, groundRightParm, groundUpParmLeft, groundFalls
COMMON SHARED groundUpParmRight, offScreen, orgX, orgY, shotExpColor, shotSleepTime
'Constants
CONST pi = 3.1415926535#
CONST gravity = 9.80665 * .5
CONST true = 1
CONST false = NOT true
'Set environment
RANDOMIZE TIMER
SCREEN 7
CLS
WINDOW (0, 200)-(320, 0)
CLEAR
setParms
playGame
END
SUB checkGround
FOR searchGround = groundLeftParm TO groundRightParm
FOR findGroundUpOrg = (groundUpParmLeft - 1) TO (groundUpParmLeft + shotExpSize + 1)
IF POINT(searchGround, findGroundUpOrg) = terrainColor AND POINT(searchGround, findGroundUpOrg + 1) = backgroundColor THEN searchGroundUpOrg = findGroundUpOrg: GOTO foundOrg
NEXT findGroundUpOrg
GOTO areFinished
foundOrg:
FOR searchGroundUp = (groundUpParmLeft + shotExpSize - 1) TO (groundUpParmLeft + (shotExpSize * 2) + 3)
IF POINT(searchGround, searchGroundUp) = terrainColor AND POINT(searchGround, searchGroundUp + 1) = backgroundColor AND POINT(searchGround, searchGroundUp - 1) = backgroundColor THEN
LINE (searchGround, searchGroundUp)-(searchGround, searchGroundUp), backgroundColor
END IF
IF POINT(searchGround, searchGroundUp) = terrainColor AND POINT(searchGround, searchGroundUp - 1) = backgroundColor THEN
finished = false
FOR findEndY = searchGroundUp TO (rangeStart + range)
IF POINT(searchGround, findEndY + 1) = backgroundColor THEN GOTO finishedCounting
NEXT findEndY
finishedCounting:
lineRange = (findEndY - searchGroundUp)
LINE (searchGround, searchGroundUp)-(searchGround, findEndY), backgroundColor
LINE (searchGround, searchGroundUpOrg)-(searchGround, (searchGroundUpOrg + lineRange)), terrainColor
GOTO areFinished
END IF
NEXT searchGroundUp
areFinished:
NEXT searchGround
END SUB
SUB clearTanks
CIRCLE (leftPos, leftDownPos), tankSize, backgroundColor, 6.28, 3.14
LINE (leftPos - 6, leftDownPos)-(leftPos + 6, leftDownPos), backgroundColor
PAINT (leftPos, leftDownPos + 1), backgroundColor, backgroundColor
drawTurretLeft (backgroundColor)
drawRightVelocity
CIRCLE (rightPos, rightDownPos), tankSize, backgroundColor, 6.28, 3.14
LINE (rightPos - 6, rightDownPos)-(rightPos + 6, rightDownPos), backgroundColor
PAINT (rightPos, rightDownPos + 1), backgroundColor, backgroundColor
drawTurretRight (backgroundColor)
drawLeftVelocity
END SUB
SUB createTanks
leftDownPos = leftDownPos + 1
CIRCLE (leftPos, leftDownPos), tankSize, tankColor, 6.28, 3.14
LINE (leftPos - 6, leftDownPos)-(leftPos + 6, leftDownPos), tankColor
PAINT (leftPos, leftDownPos + 1), tankColor, tankColor
drawTurretLeft (tankColor)
drawRightVelocity
rightDownPos = rightDownPos + 1
CIRCLE (rightPos, rightDownPos), tankSize, tankColor, 6.28, 3.14
LINE (rightPos - 6, rightDownPos)-(rightPos + 6, rightDownPos), tankColor
PAINT (rightPos, rightDownPos + 1), tankColor, tankColor
drawTurretRight (tankColor)
drawLeftVelocity
END SUB
SUB createTerrain
WINDOW (0, 200)-(320, 0)
bumpiness = 40
rangeStart = 40
range = 65
oldTerrainOver = 0
oldTerrainUp = 0
FOR terrainDot = 0 TO 320 STEP bumpiness
terrainUp = INT(RND * range) + rangeStart
LINE (oldTerrainOver, oldTerrainUp)-(terrainDot, terrainUp), terrainColor
oldTerrainOver = terrainDot
oldTerrainUp = terrainUp
NEXT terrainDot
PAINT (100, 0), terrainColor, terrainColor
PAINT (0, 200), backgroundColor, terrainColor
END SUB
SUB drawLeftVelocity
LOCATE 23, 1
PRINT leftVelocity
windDirection = -2
IF ABS(wind) = wind THEN windDirection = 2
LINE (160, 5)-(160 + wind, 5), tankColor
LINE (160 + wind, 5)-(160 + wind - windDirection, 7), tankColor
LINE (160 + wind, 5)-(160 + wind - windDirection, 3), tankColor
END SUB
SUB drawRightVelocity
LOCATE 23, 36
PRINT rightVelocity
windDirection = -2
IF ABS(wind) = wind THEN windDirection = 2
LINE (160, 5)-(160 + wind, 5), tankColor
LINE (160 + wind, 5)-(160 + wind - windDirection, 7), tankColor
LINE (160 + wind, 5)-(160 + wind - windDirection, 3), tankColor
END SUB
SUB drawTurretLeft (turretColor)
LINE (leftPos + (COS(leftRads) * (tankSize + 1)), leftDownPos + (SIN(leftRads) * (tankSize + 1)))-(leftPos + (COS(leftRads) * turretLength), leftDownPos + (SIN(leftRads) * turretLength)), turretColor
END SUB
SUB drawTurretRight (turretColor)
LINE (rightPos + (COS(rightRads) * (tankSize + 1)), rightDownPos + (SIN(rightRads) * (tankSize + 1)))-(rightPos + (COS(rightRads) * turretLength), rightDownPos + (SIN(rightRads) * turretLength)), turretColor
END SUB
SUB explodeTank
FOR exploding = 1 TO explodeSize STEP explodeStep
CIRCLE (x, y), exploding, explodeColor
NEXT exploding
END SUB
SUB findTanks (leftPos, rightPos)
startY = range + rangeStart
FOR findTankDown = startY TO rangeStart STEP -1
IF POINT(leftPos, findTankDown) = terrainColor THEN
leftDownPos = findTankDown
GOTO endFindTankLeft
END IF
NEXT findTankDown
PRINT "Fatal error - cannot find tank location."
END
endFindTankLeft:
FOR findTankDown = startY TO rangeStart STEP -1
IF POINT(rightPos, findTankDown) = terrainColor THEN
rightDownPos = findTankDown
GOTO endFindTankRight
END IF
NEXT findTankDown
PRINT "Fatal error - cannot find tank location."
END
endFindTankRight:
END SUB
SUB fireShotLeft
hitTank = false
hitGround = false
nonZero = false
offScreen = false
DO
leftStartPos = leftPos + (COS(leftRads) * turretLength) + 1
leftStartDownPos = leftDownPos + (SIN(leftRads) * turretLength) + 1
IF timesGone > 0 THEN
xOld = x
yOld = y
ELSE
xOld = leftStartPos
yOld = leftStartDownPos
END IF
leftVelocityX = COS(leftRads) * leftVelocity
leftVelocityY = SIN(leftRads) * leftVelocity
x = leftStartPos + (leftVelocityX * timesGone) + (.5 * (wind / 5) * timesGone ^ 2)
y = leftStartDownPos - ((-1 * (leftVelocityY * timesGone)) + (.5 * 9.80665 * timesGone ^ 2)) * (200 / 350)
SELECT CASE POINT(x, y)
CASE terrainColor
hitGround = true
nonZero = true
CASE -1
hitGround = true
nonZero = true
offScreen = true
CASE tankColor
hitTank = true
nonZero = true
CASE ELSE
nonZero = 0
END SELECT
IF x = orgX AND y = orgY THEN
hitGround = true
nonZero = true
END IF
LINE (x, y)-(x, y), shellColor
LINE (xOld, yOld)-(x, y), trailColor
timesGone = timesGone + shotAccuracy
LOOP UNTIL nonZero = true
IF offScreen = true THEN GOTO noLeftShot
IF orgX = 0 AND orgY = 0 THEN
FOR c = 1 TO shotExpSize
CIRCLE (x, y), c, shotExpColor
FOR holdOn = 0 TO shotSleepTime
NEXT holdOn
NEXT c
CIRCLE (x, y), c, tankColor
PAINT (x, y), backgroundColor, tankColor
CIRCLE (x, y), c, backgroundColor
END IF
noLeftShot:
END SUB
SUB fireShotRight
hitTank = false
hitGround = false
nonZero = false
offScreen = false
DO
rightStartPos = rightPos + (COS(rightRads) * turretLength) + 1
rightStartDownPos = rightDownPos + (SIN(rightRads) * turretLength) + 1
IF timesGone > 0 THEN
xOld = x
yOld = y
ELSE
xOld = rightStartPos
yOld = rightStartDownPos
END IF
rightVelocityX = COS(rightRads) * rightVelocity
rightVelocityY = SIN(rightRads) * rightVelocity
x = rightStartPos + (rightVelocityX * timesGone) + (.5 * (wind / 5) * timesGone ^ 2)
y = rightStartDownPos - ((-1 * (rightVelocityY * timesGone)) + (.5 * 9.80665 * timesGone ^ 2)) * (200 / 350)
SELECT CASE POINT(x, y)
CASE terrainColor
hitGround = true
nonZero = true
CASE -1
hitGround = true
nonZero = true
offScreen = true
CASE tankColor
hitTank = true
nonZero = true
CASE ELSE
nonZero = 0
END SELECT
IF x = orgX AND y = orgY THEN
hitGround = true
nonZero = true
END IF
LINE (x, y)-(x, y), shellColor
LINE (xOld, yOld)-(x, y), trailColor
timesGone = timesGone + shotAccuracy
LOOP UNTIL nonZero = true
IF offScreen = true THEN GOTO noRightShot
IF orgX = 0 AND orgY = 0 THEN
FOR c = 1 TO shotExpSize
CIRCLE (x, y), c, shotExpColor
FOR holdOn = 0 TO shotSleepTime
NEXT holdOn
NEXT c
CIRCLE (x, y), c, tankColor
PAINT (x, y), backgroundColor, tankColor
CIRCLE (x, y), c, backgroundColor
END IF
noRightShot:
END SUB
SUB getInfoLeft
DO
key$ = INKEY$
IF key$ = "4" THEN degInc = 3: GOSUB changePosLeft
IF key$ = "6" THEN degInc = -3: GOSUB changePosLeft
IF key$ = "8" THEN velInc = 1: GOSUB changeVelLeft
IF key$ = "2" THEN velInc = -1: GOSUB changeVelLeft
IF key$ = "q" THEN END
IF key$ = CHR$(13) THEN GOTO endGetInfoLeft
LOOP
changePosLeft:
turretColor = backgroundColor
drawTurretLeft turretColor
IF leftDegrees > 180 OR leftDegrees < 0 THEN
IF leftDegrees > 180 THEN
turretColor = backgroundColor
drawTurretLeft turretColor
leftDegrees = 180
turretColor = 15
drawTurretLeft turretColor
RETURN
END IF
IF leftDegrees < 0 THEN
turretColor = backgroundColor
drawTurretLeft turretColor
leftDegrees = 0
turretColor = 15
drawTurretLeft turretColor
RETURN
END IF
ELSE
leftDegrees = leftDegrees + degInc
END IF
turretColor = 15
drawTurretLeft turretColor
RETURN
changeVelLeft:
leftVelocity = leftVelocity + velInc
IF leftVelocity > 100 THEN leftVelocity = 100
IF leftVelocity < 0 THEN leftVelocity = 0
drawLeftVelocity
RETURN
endGetInfoLeft:
END SUB
SUB getInfoRight
DO
key$ = INKEY$
IF key$ = "4" THEN degInc = 3: GOSUB changePosRight
IF key$ = "6" THEN degInc = -3: GOSUB changePosRight
IF key$ = "8" THEN velInc = 1: GOSUB changeVelRight
IF key$ = "2" THEN velInc = -1: GOSUB changeVelRight
IF key$ = "q" THEN END
IF key$ = CHR$(13) THEN GOTO endGetInfoRight
LOOP
changePosRight:
turretColor = backgroundColor
drawTurretRight turretColor
IF rightDegrees > 180 OR rightDegrees < 0 THEN
IF rightDegrees > 180 THEN
turretColor = backgroundColor
drawTurretRight turretColor
rightDegrees = 180
turretColor = 15
drawTurretRight turretColor
RETURN
END IF
IF rightDegrees < 0 THEN
turretColor = backgroundColor
drawTurretRight turretColor
rightDegrees = 0
turretColor = 15
drawTurretRight turretColor
RETURN
END IF
ELSE
rightDegrees = rightDegrees + degInc
END IF
turretColor = 15
drawTurretRight turretColor
RETURN
changeVelRight:
rightVelocity = rightVelocity + velInc
IF rightVelocity > 100 THEN rightVelocity = 100
IF rightVelocity < 0 THEN rightVelocity = 0
drawRightVelocity
RETURN
endGetInfoRight:
END SUB
FUNCTION leftRads
leftRads = leftDegrees * (pi / 180)
END FUNCTION
SUB playGame
createTerrain
leftPos = 20
rightPos = 300
findTanks leftPos, rightPos
createTanks
DO
getInfoLeft
trailColor = originalTrailColor
orgX = 0: orgY = 0
IF retrace = true THEN fireShotLeft
orgX = x: orgY = y
groundLeftParm = x - shotExpSize - 1
groundUpParmLeft = y - shotExpSize - 1
IF hitTank = true THEN GOTO hitATank
trailColor = backgroundColor
fireShotLeft
IF offScreen = true THEN GOTO endOne
groundRightParm = x + shotExpSize + 1
groundUpParmRight = y - shotExpSize - 1
IF groundFalls = true THEN
clearTanks
checkGround
findTanks leftPos, rightPos
createTanks
END IF
endOne:
getInfoRight
trailColor = originalTrailColor
orgX = 0: orgY = 0
IF retrace = true THEN fireShotRight
orgX = x: orgY = y
groundLeftParm = x - shotExpSize - 1
groundUpParmLeft = y - shotExpSize - 1
IF hitTank = true THEN GOTO hitATank
trailColor = backgroundColor
fireShotRight
IF offScreen = true THEN GOTO endTwo
groundRightParm = x + shotExpSize + 1
groundUpParmRight = y - shotExpSize - 1
IF groundFalls = true THEN
clearTanks
checkGround
findTanks leftPos, rightPos
createTanks
END IF
endTwo:
LOOP
hitATank:
explodeTank
explodeTank
explodeColor = 1
explodeSize = turretLength
explodeStep = .5
explodeTank
END SUB
FUNCTION rightRads
rightRads = rightDegrees * (pi / 180)
END FUNCTION
SUB setParms
'Starting positions
leftVelocity = 25
leftDegrees = 57
rightVelocity = 25
rightDegrees = 180 - 57
'Sizes
tankSize = 5
explodeSize = 100
shotExpSize = 3
turretLength = 10
'Colors
originalTrailColor = 4
shellColor = 15
terrainColor = 2
tankColor = 15
explodeColor = 1
backgroundColor = 1
shotExpColor = 4
'Misc
groundFalls = true
retrace = true
shotAccuracy = .15
explodeStep = 5
shotSleepTime = 100
wind = INT(RND * 21) - 10
IF wind = 11 THEN wind = wind + 10
END SUB
@nfarina
Copy link
Author

nfarina commented Oct 26, 2022

FRS8ueWUUAASZ11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment