_Title "Tanks Battle! by bplus 2018-02-03" 'from: Tanks Battle.sdlbas (B+=MGA) 2016-10-29
' let the projectiles fly!
'screen stuff
'tank stuff
Const tN
= 15 'number of tanks Const tNm1
= tN
- 1 ' for loops and arrays Const tW
= 20 'width of tank Const tH
= 8 'height of tank
'hole stuff
'projectile stuff
Const skyC
= &HFF848888 ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this used to work ! 'Dim Shared As _Unsigned Long skyC ' >>>>>>>>>>>>>>>>>>>>> fix for 2.0
'skyC = &HFF848888
Common Shared rad
, deg
' yeah don't need these with _D2R and _R2D but this was 4 years ago
ff$ = "arial" ' I have loaded and tested many fonts from Windows Folder and disappointed how few work with QB64
'load and check Big size font
bArial&
= _LoadFont("C:\windows\fonts\" + ff$
+ ".ttf", 48, "BOLD")'bFW = _FONTWIDTH(bArial&): bFH = _FONTHEIGHT(bArial&)
'_FONT bArial&
'LOCATE 1, 1: PRINT "This is BIG font."
'SLEEP
'get holes set up
holeIndex = -1
drawLandscape
initializeTanks
hotTank = tNm1
change = 1
While change
'get tanks landed before start shooting change = 0
_PutImage , land&
, 0 'land the tanks and reland the tanks if the dirt is shot out under them If Point(tanks
(i
).x
+ tW
/ 2, tanks
(i
).y
+ tH
+ 1) = skyC
Then tanks(i).y = tanks(i).y + 2
change = 1
drawTank i
While 1 '< main loop start
'the land with holes
drawHole holes(ii).x, holes(ii).y
'reland the tanks if the dirt is shot out under them
While Point(tanks
(i
).x
+ tW
/ 2, tanks
(i
).y
+ tH
+ 1) = skyC
tanks(i).y = tanks(i).y + 2
'repoint barrels and reset velocitys
If Rnd < .5 Then 'avoid straight up and down suicide shots tanks(i).da = rand(leftA, -92)
tanks(i).da = rand(rightA, -88)
tanks(i).v = rand(lVel, hVel) 'velocity
drawTank i
''whose turn to shoot
lastMan = hotTank
hotTank = hotTank + 1
While tanks
(hotTank
).f
= 1 'look for a tank still alive hotTank = hotTank + 1 'whose turn to shoot
'did we cycle through all the dead tanks?
If hotTank
= lastMan
Then 'game over, last man standing
'setup hotTank's shot
rAngle = tanks(hotTank).da * rad 'convert here to radians for SIN and COS
pX = tanks(hotTank).bx
pY = tanks(hotTank).by
pX_change
= tanks
(hotTank
).v
* Cos(rAngle
) 'this is the cuurent X vector of the projectile pY_change
= tanks
(hotTank
).v
* Sin(rAngle
) ' this is the current Y vector of the projectile pActive = 0 ' do not Activate until projectile sees the skyC
pY_change = pY_change + gravity ' pY starts in upward direction but will eventually fall due to gravity
pX = pX + pX_change
pY = pY + pY_change
'show projectile progress, hit or air
'check for tank hit
If tanks
(iTank
).f
<> 1 And pActive
Then 'tanks can blow up themselves If dist
(pX
, pY
, tanks
(iTank
).x
+ tW
/ 2, tanks
(iTank
).y
+ tH
/ 2) < hR
Then tanks(iTank).f = 1
fcirc pX, pY, rr
holeIndex = holeIndex + 1
holes(holeIndex).x = pX
holes(holeIndex).y = pY
drawHole pX, pY
pX = SW + 10
pY = SH + 10
pActive = 1
fcirc pX, pY, 2 ' <<<<<<<<<<<<<<<< to see round projectiles that could be replaced by image
'still hot but cant see
fcirc pX, pY, rr
holeIndex = holeIndex + 1
holes(holeIndex).x = pX
holes(holeIndex).y = pY
drawHole pX, pY
pX = SW + 10
pY = SH + 10
fcirc xx, i, hR
'the sky
Line (0, 0)-(SW
, SH
), skyC
, BF
'the land
startH = SH - 100
rr = 70: gg = 70: bb = 90
Xright = 0
y = startH
' upDown = local up / down over range, change along Y
' range = how far up / down, along X
upDown
= (Rnd * (.8) - .35) * (mountain
* .5) range = Xright + rand%(15, 25) * 2.5 / mountain
For x
= Xright
- 1 To range
y = y + upDown
Xright = range
rr = rand(rr - 15, rr): gg = rand(gg - 15, gg): bb = rand(bb - 25, bb)
startH = startH + rand(5, 20)
Sub initializeTanks
' x, y, barrel angle, velocity, color tl = (SW - tW) / tN: tl2 = tl / 2: tl4 = .8 * tl2
tanks(i).x = rand%(tl2 + tl * i - tl4 - tW, tl2 + tl * i + tl4 - tW)
tanks(i).y = 300 '<<<<<<<<<<<<<<<<<<<<<<<<<< for testing
tanks(i).da = rand%(-180, 0) 'degree Angle
tanks(i).v = rand%(10, 20) 'velocity
If tanks
(i
).da
< -90 Then 'barrel is pointed left tanks(i).v = -1 * tanks(i).v
tc
= i
* Int(200 / (3 * tN
)) 'maximize color difference between tanks tanks
(i
).c
= _RGB32(55 + 2 * tc
, 13 + tc
, 23 + tc
) ' first tank is darkest 'shuffle color order
r = rand%(0, i)
Swap tanks
(i
).x
, tanks
(r
).x
'ink(tanks(i, "c"))
'turret
fEllipse tanks(i).x + tW / 2, tanks(i).y + tH / 3, tW / 4 + 1, tH / 4 + 1
bX
= tW
/ 2 * Cos(rad
* tanks
(i
).da
) bY
= tW
/ 2 * Sin(rad
* tanks
(i
).da
) Line (tanks
(i
).x
+ tW
/ 2, tanks
(i
).y
+ tH
/ 3)-(tanks
(i
).x
+ tW
/ 2 + bX
, tanks
(i
).y
+ tH
/ 4 + bY
) Line (tanks
(i
).x
+ tW
/ 2 + 1, tanks
(i
).y
+ tH
/ 3 + 1)-(tanks
(i
).x
+ tW
/ 2 + bX
+ 1, tanks
(i
).y
+ tH
/ 4 + bY
+ 1) tanks(i).bx = tanks(i).x + tW / 2 + bX
tanks(i).by = tanks(i).y + tH / 4 + bY
fEllipse tanks(i).x + tW / 2, tanks(i).y + .75 * tH, tW / 2, tH / 4
ellipse tanks(i).x + tW / 2, tanks(i).y + .75 * tH, tW / 2 + 1, tH / 4 + 1
ellipse tanks(i).x + tW / 2 + 1, tanks(i).y + .75 * tH, tW / 2 + 1, tH / 4 + 1
rand%
= (Rnd * (hi%
- lo%
+ 1)) \
1 + lo%
dist# = ((x1% - x2%) ^ 2 + (y1% - y2%) ^ 2) ^ .5
'Steve McNeil's copied from his forum note: Radius is too common a name
RadiusError = -subRadius
X = subRadius
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
Line (CX
- X
, CY
)-(CX
+ X
, CY
), , BF
RadiusError = RadiusError + Y * 2 + 1
Line (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), , BF
Line (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), , BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
Line (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), , BF
Line (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), , BF
scale = yRadius / xRadius
Line (CX
, CY
- yRadius
)-(CX
, CY
+ yRadius
), , BF
y
= scale
* Sqr(xRadius
* xRadius
- x
* x
) Line (CX
+ x
, CY
- y
)-(CX
+ x
, CY
+ y
), , BF
Line (CX
- x
, CY
- y
)-(CX
- x
, CY
+ y
), , BF
scale = yRadius / xRadius: xs = xRadius * xRadius
PSet (CX
, CY
- yRadius
):
PSet (CX
, CY
+ yRadius
) lastx = 0: lasty = yRadius
y
= scale
* Sqr(xs
- x
* x
) Line (CX
+ lastx
, CY
- lasty
)-(CX
+ x
, CY
- y
) Line (CX
+ lastx
, CY
+ lasty
)-(CX
+ x
, CY
+ y
) Line (CX
- lastx
, CY
- lasty
)-(CX
- x
, CY
- y
) Line (CX
- lastx
, CY
+ lasty
)-(CX
- x
, CY
+ y
) lastx = x: lasty = y