_TITLE "Invaders b0_2" 'Bplus started 2019-07-27 inspired by Ken's fun program series
CONST xmax
= 1200, ymax
= 720, PI
= 3.141592653589793, PD2
= 1.570796326794897, PT2
= 6.283185307
setUp
LINE (0, 0)-(xmax
, ymax
), _RGBA(0, 0, 0, 255), BF
IF kh
= 18432 THEN o
(0).dx
= 0 IF kh
= 19200 THEN o
(0).dx
= -3 IF kh
= 19712 THEN o
(0).dx
= 3
cText xmax
/ 2, 30, 20, &HFF009900, "Cat's lives: " + STR$(o
(0).live
) + " Cat's Points: " + STR$(points
) IF o
(i
).live
<> 0 THEN 'draw everything, update positions, check updated position drawshooter o(i).x
newBullet 0, o(0).x, ymax - 60
IF o
(i
).x
+ o
(i
).dx
> 0 AND o
(i
).x
+ o
(i
).dx
< xmax
THEN o(i).x = o(i).x + o(i).dx
o(i).dx = -o(i).dx
o(0).exploding = o(0).exploding - 1
IF o
(0).exploding
= 0 THEN 'exploded enough o(0).live = o(0).live - 1
drawshooter o(i).x
red = rand(60, 255)
fcirc o
(0).x
, ymax
- 75, o
(0).exploding
* 6, _RGB32(red
, rand
(0, red
), 0) 'from celtic knot model
'xReturn = xc + r * (COS(a) + COS(5 * a) / 1.6 + SIN(2 * a) / 3)
'yReturn = yc + r * (SIN(a) + SIN(5 * a) / 1.6 + COS(2 * a) / 3)
o(i).lastX = o(i).x: o(i).lastY = o(i).y
o
(i
).x
= o
(i
).xc
+ 150 * (COS(o
(i
).a
) + COS(o
(i
).v1
* o
(i
).a
) / 2 + SIN(o
(i
).v2
* o
(i
).a
) / 3) o
(i
).y
= o
(i
).yc
+ 150 * (SIN(o
(i
).a
) + SIN(o
(i
).v1
* o
(i
).a
) / 2 + COS(o
(i
).v2
* o
(i
).a
) / 3) 'fcirc o(i).x, o(i).y, o(i).size, o(i).c
drawRat i
o(i).a = o(i).a + PI / 1440
IF o
(i
).xc
+ o
(i
).dx
> 0 AND o
(i
).xc
+ o
(i
).dx
< xmax
THEN o(i).xc = o(i).xc + o(i).dx
o(i).dx = -o(i).dx
'drop bombs
newBullet i, o(i).x, o(i).y + o(i).size
o(i).exploding = o(i).exploding - 1
newEnemy i
red = rand(60, 255)
fcirc o
(i
).x
, o
(i
).y
, o
(i
).exploding
* 3, _RGB32(red
, rand
(0, red
), 0) fcirc o(i).x, o(i).y, o(i).size, o(i).c
IF o
(i
).x
+ o
(i
).dx
> 0 AND o
(i
).x
+ o
(i
).dx
< xmax
THEN o(i).x = o(i).x + o(i).dx
o(i).live = 0: o(i).x = -999: o(i).y = -999: o(i).dy = 0
IF o
(i
).y
+ o
(i
).dy
> 0 AND o
(i
).y
+ o
(i
).dy
< ymax
THEN IF o
(i
).dy
> 0 THEN o
(i
).dy
= o
(i
).dy
+ .1 'gravity o(i).y = o(i).y + o(i).dy
o(i).live = 0: o(i).x = -999: o(i).y = -999: o(i).dy = 0
'did this bullet hit anything
IF o
(i
).dy
> 0 THEN 'did it hit the shooter IF ((o
(i
).x
- o
(0).x
) ^ 2 + (o
(i
).y
- o
(0).y
) ^ 2) ^ .5 <= 50 THEN 'explode shooter
o(0).exploding = 20 'signal exploding
o(i).live = 0: o(i).x = -999: o(i).y = -999: o(i).dy = 0
ELSEIF o
(i
).dy
< 0 AND o
(i
).c
= &HFFFFFFFF THEN 'did it hit the enemy? IF ((o
(i
).x
- o
(j
).x
) ^ 2 + (o
(i
).y
- o
(j
).y
) ^ 2) ^ .5 <= o
(j
).size
+ 2 THEN o(j).exploding = 20
points = points + 50 - o(j).size
o(i).live = 0: o(i).x = -999: o(i).y = -999: o(i).dy = 0
topTen points
PRINT:
INPUT "Press enter to go again, any other, eg q, to quit "; again$
'obj 0 is the player's shooter
points = 0
o(0).x = xmax / 2: o(0).y = ymax - 25
o(0).live = 9
newEnemy i
o
(i
).a
= RND * PT2: o
(i
).live
= 1: o
(i
).v1
= rand
(2, 19): o
(i
).v2
= rand
(2, 19) r = rand(128, 255): g = rand(0, .5 * r): b = rand(0, .25 * r)
o
(i
).size
= rand
(10, 45): o
(i
).c
= _RGB32(r
, g
, b
) o
(i
).yc
= ymax
/ 2 - 30: o
(i
).lastShot
= TIMER(.003) + .67 * i
o(i).xc = 0: o(i).dx = 1
o(i).xc = xmax: o(i).dx = -1
SUB newBullet
(who
, x
, y
) FOR ii
= 4 TO 100 'find bullet slot o
(ii
).x
= x: o
(ii
).y
= y: o
(ii
).size
= 2: o
(ii
).live
= -1: o
(who
).lastShot
= TIMER(.001) o(ii).dy = -10: o(ii).c = &HFFFFFFFF
o(ii).dy = 1: o(ii).c = &HFFFFFF00
shoot = 0
DIM noseX
, noseY
, neckX
, neckY
, tailX
, tailY
, earLX
, earLY
, earRX
, earRY
, wX
, wY
, rh
rh
= _ATAN2(o
(i
).y
- o
(i
).lastY
, o
(i
).x
- o
(i
).lastX
) noseX
= o
(i
).x
+ 2 * o
(i
).size
* COS(rh
) noseY
= o
(i
).y
+ 2 * o
(i
).size
* SIN(rh
) neckX
= o
(i
).x
+ .75 * o
(i
).size
* COS(rh
) neckY
= o
(i
).y
+ .75 * o
(i
).size
* SIN(rh
) tailX
= o
(i
).x
+ 2 * o
(i
).size
* COS(rh
+ _PI) tailY
= o
(i
).y
+ 2 * o
(i
).size
* SIN(rh
+ _PI) earLX
= o
(i
).x
+ o
(i
).size
* COS(rh
- _PI(1 / 12)) earLY
= o
(i
).y
+ o
(i
).size
* SIN(rh
- _PI(1 / 12)) earRX
= o
(i
).x
+ o
(i
).size
* COS(rh
+ _PI(1 / 12)) earRY
= o
(i
).y
+ o
(i
).size
* SIN(rh
+ _PI(1 / 12)) fcirc o(i).x, o(i).y, .65 * o(i).size, o(i).c
fcirc neckX, neckY, o(i).size * .3, o(i).c
fTri noseX, noseY, earLX, earLY, earRX, earRY, o(i).c
fcirc earLX, earLY, o(i).size * .3, o(i).c
fcirc earRX, earRY, o(i).size * .3, o(i).c
wX
= .5 * o
(i
).size
* COS(rh
- _PI(11 / 18)) wY
= .5 * o
(i
).size
* SIN(rh
- _PI(11 / 18)) ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, o(i).c
wX
= .5 * o
(i
).size
* COS(rh
- _PI(7 / 18)) wY
= .5 * o
(i
).size
* SIN(rh
- _PI(7 / 18)) ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, o(i).c
ln o(i).x, o(i).y, tailX, tailY, o(i).c
SUB drawshooter
(x
) 'simple red iso triangle pointed towards radianAngle 'calculate 3 points of triangle shooter
y1 = ymax - 10
y2 = ymax - 60
x1 = x - 50
x2 = x + 50
fTri x
, y1
, x1
, ymax
, x
, y2
, _RGB(0, 0, 200) fTri x
, y1
, x2
, ymax
, x
, y2
, _RGB(0, 0, 200) ln x
, y1
, x1
, ymax
, _RGB32(255, 255, 128) ln x1
, ymax
, x
, y2
, _RGB32(255, 255, 128) ln x
, y1
, x2
, ymax
, _RGB32(255, 255, 128) ln x2
, ymax
, x
, y2
, _RGB32(255, 255, 128) ln x
, y1
, x
, y2
, _RGB32(255, 255, 128)
fName$ = "Top 10 Scores.txt" '<<< since this is toolbox code change this as needed for app
n = n + 1
IF compareScore
>= score
AND settleScore
= 0 THEN PRINT "You have made the Top Ten!" INPUT "Type your name here: ", Names$
(n
) scores(n) = compareScore
settleScore = -1
n = n + 1
IF n
<= 10 THEN Names$
(n
) = name$: scores
(n
) = score
scores
(n
) = score: Names$
(n
) = name$
PRINT "There is a slot open for your name and score." IF name$
<> "" THEN n
= n
+ 1: Names$
(n
) = name$: scores
(n
) = compareScore
PRINT i
, Names$
(i
), scores
(i
) INPUT "That's the list, press Enter to continue... ";
name$
PRINT "You are first into file!"
'center the text
'screen snapshot
mult = textHeight / 16
xlen
= LEN(txt$
) * 8 * mult
_PUTIMAGE (x
- .5 * xlen
, y
- .5 * textHeight
)-STEP(xlen
, textHeight
), I&
, cur&
rand%
= INT(RND * (hi%
- lo%
+ 1)) + lo%
' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]: http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
LINE (x1
, y1
)-(x2
, y2
), K
'from Steve Gold standard
Radius
= ABS(R
): RadiusError
= -Radius: X
= Radius: Y
= 0 LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), C
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), C
, BF