_TITLE "Mouse Action Shooter #2 Targets for MB triggers" 'B+ 2019-04-01 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
' upodate Mouse Action Shooter with MB triggers 2019-04-01
' 2019-04-03 add some targets for practice
' SCORE System:
' Right click to fire a bullet, they cost 10 points each.
' Targets range from 30 for biggest targets to 100 points for smallest Targets
' Get hit by target loose 100 points and delay of game. Just worry about aound the nose of the shooter.
'screen dimensions
CONST nTargets
= 3 'should probably depend on level of play CONST tSpeed
= 5 'should probably depend on level of play
'targets
'bullets
'shooter
shooter.x = xmax / 2
shooter.y = ymax / 2
shooter.a = 0
lastx = xmax / 2: lasty = ymax / 2
'game
GameOn = 1
mb1 = 0: mb2 = 0
shooter.a
= _ATAN2(shooter.y
- lasty
, shooter.x
- lastx
) lastx = shooter.x: lasty = shooter.y
IF t
- last1
> .15 THEN mb1
= 1: last1
= t
handleTargets
drawshooter
handleBullets
FOR i
= 0 TO nTargets
- 1 'update position
t
(i
).x
= t
(i
).x
+ tSpeed
* COS(t
(i
).a
) t
(i
).y
= t
(i
).y
+ tSpeed
* SIN(t
(i
).a
) 'inbounds?
IF t
(i
).x
< -shooterRadius
OR t
(i
).x
> xmax
+ shooterRadius
OR t
(i
).y
< -shooterRadius
OR t
(i
).y
> ymax
+ shooterradiu
THEN newTarget i
'explosion
_PRINTSTRING (xmax
/ 2 - 40, ymax
/ 2 - 10), "Bang!... Ouch!" score = score - 100
drawTarget i
'pick edge
CASE 0: t
(i
).x
= -shooterRadius: t
(i
).y
= RND * (ymax
- 300) + 150: t
(i
).a
= RND * _PI CASE 1: t
(i
).x
= xmax
+ shooterRadius: t
(i
).y
= RND * (ymax
- 300) + 150: t
(i
).a
= _PI / 2 + RND * _PI CASE 2: t
(i
).x
= RND * xmax: t
(i
).y
= -shooterRadius: t
(i
).a
= RND * _PI CASE 3: t
(i
).x
= RND * xmax: t
(i
).y
= ymax
+ shooterRadius: t
(i
).a
= _PI + RND * _PI t
(i
).r
= (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
count
= (count
+ 1) MOD 2 fcirc t(i).x, t(i).y, r, c~&
FOR i
= 0 TO nBullets
- 1 IF b
(i
).live
= 0 AND mb1
= 1 THEN 'have in active bullet index to use b
(i
).x
= shooter.x
+ .5 * shooterRadius
* COS(shooter.a
) b
(i
).y
= shooter.y
+ .5 * shooterRadius
* SIN(shooter.a
) b
(i
).dx
= bSpeed
* COS(shooter.a
) b
(i
).dy
= bSpeed
* SIN(shooter.a
) b(i).live = 1
mb1 = 0
score = score - 10 'bullets cost 10 points
'ELSEIF b(i).live = 0 AND mb2 = 1 THEN
' b(i).x = shooter.x + (shooterRadius) * COS(shooter.a - _PI(7 / 8))
' b(i).y = shooter.y + (shooterRadius) * SIN(shooter.a - _PI(7 / 8))
' b(i).dx = bSpeed * COS(shooter.a)
' b(i).dy = bSpeed * SIN(shooter.a)
' b(i).live = 1
' mb2 = 0
b(i).x = b(i).x + b(i).dx
b(i).y = b(i).y + b(i).dy
IF b
(i
).x
> 0 AND b
(i
).x
< xmax
AND b
(i
).y
> 0 AND b
(i
).y
< ymax
THEN 'in bounds draw it 'check for collision with ...
t = hitTarget(i)
score = score + 130 - t(t).r
b(i).live = 0
newTarget t
'draw bullet
ba
= _ATAN2(b
(i
).dy
, b
(i
).dx
): b
= 15 x1
= b
(i
).x
+ b
* COS(ba
) y1
= b
(i
).y
+ b
* SIN(ba
) x2
= b
(i
).x
+ b
* COS(ba
+ _PI(5 / 6)) y2
= b
(i
).y
+ b
* SIN(ba
+ _PI(5 / 6)) x3
= b
(i
).x
+ b
* COS(ba
+ _PI(7 / 6)) y3
= b
(i
).y
+ b
* SIN(ba
+ _PI(7 / 6)) fTri x1
, y1
, x2
, y2
, x3
, y3
, _RGB32(10, 160, 160) 'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
b(i).live = 0 'dectiveate
hitTarget = -1
FOR i
= 0 TO nTargets
- 1 IF SQR((t
(i
).x
- b
(bulletIndex
).x
) ^ 2 + (t
(i
).y
- b
(bulletIndex
).y
) ^ 2) <= t
(i
).r
THEN hitTarget
= i:
EXIT FUNCTION
IF SQR((shooter.x
- t
(TargetIndex
).x
) ^ 2 + (shooter.y
- t
(TargetIndex
).y
) ^ 2) <= t
(i
).r
THEN hitShooter
= 1:
EXIT FUNCTION
'just a wedge
x1
= shooter.x
+ (shooterRadius
- 30) * COS(shooter.a
) y1
= shooter.y
+ (shooterRadius
- 30) * SIN(shooter.a
) x2
= shooter.x
+ (shooterRadius
+ 20) * COS(shooter.a
+ _PI(11 / 16)) y2
= shooter.y
+ (shooterRadius
+ 20) * SIN(shooter.a
+ _PI(11 / 16)) x3
= shooter.x
+ (shooterRadius
+ 20) * COS(shooter.a
- _PI(11 / 16)) y3
= shooter.y
+ (shooterRadius
+ 20) * SIN(shooter.a
- _PI(11 / 16)) fTri x1
, y1
, x2
, y2
, x3
, y3
, _RGB32(85, 45, 0) x1
= shooter.x
+ shooterRadius
* COS(shooter.a
) y1
= shooter.y
+ shooterRadius
* SIN(shooter.a
) x2
= shooter.x
+ shooterRadius
* COS(shooter.a
+ _PI(7 / 8)) y2
= shooter.y
+ shooterRadius
* SIN(shooter.a
+ _PI(7 / 8)) x3
= shooter.x
+ shooterRadius
* COS(shooter.a
- _PI(7 / 8)) y3
= shooter.y
+ shooterRadius
* SIN(shooter.a
- _PI(7 / 8)) fTri x1
, y1
, x2
, y2
, x3
, y3
, _RGB32(0, 0, 200) x2
= shooter.x
+ shooterRadius
* COS(shooter.a
+ _PI(15 / 16)) y2
= shooter.y
+ shooterRadius
* SIN(shooter.a
+ _PI(15 / 16)) x3
= shooter.x
+ shooterRadius
* COS(shooter.a
- _PI(15 / 16)) y3
= shooter.y
+ shooterRadius
* SIN(shooter.a
- _PI(15 / 16)) fTri x1
, y1
, x2
, y2
, x3
, y3
, _RGB32(255, 255, 255)
' 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
RadiusError = -Radius
X = Radius
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
), 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