_TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19 '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.
'2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
' Now give the bullets a little long range before deactivating them.
' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
' Let's see, in oh it doesn't work, how about here? Works just as expected. So what's up with oh?
' (Fixed it was an index goof for public variables used in GoSubs).
'screen dimensions
CONST pip180
= 3.14159265 / 180 CONST nTargets
= 3 'should probably depend on level of play CONST tSpeed
= 5 'should probably depend on level of play
CONST explosions_buff
= 2000:
DIM SHARED explosions
(explosions_buff
- 1, 19) 'shards-dat array CONST explosions_s
= 200 'number of shards 1 when exploding
'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
IF SQR((shooter.y
- lasty
) ^ 2 + (shooter.x
- lastx
) ^ 2) > 1 THEN angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
dif_choice = 1000
angle_dif = shooter_degree - (angle + 360 * (2 - t))
IF dif
< dif_choice
THEN angle_dif_choice
= angle_dif: dif_choice
= dif
shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
DO WHILE shooter_degree
> 360: shooter_degree
= shooter_degree
- 360:
LOOP DO WHILE shooter_degree
< 360: shooter_degree
= shooter_degree
+ 360:
LOOP shooter.a = shooter_degree * pip180
lastx = shooter.x: lasty = shooter.y
IF t
- last1
> .15 THEN mb1
= 1: last1
= t
handleTargets
drawshooter
handleBullets
explosions_control
explosions_draw
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
IF hitShooter
(i
) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter 'explosion
_PRINTSTRING (xmax
/ 2 - 40, ymax
/ 2 - 10), "Bang!... Ouch!" score = score - 100
' fix target crashing into ship by removing target with reassigning
newTarget i ' in oh this does not work
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
b(i).x = b(i).x + b(i).dx
b(i).y = b(i).y + b(i).dy
IF b
(i
).x
> -50 AND b
(i
).x
< xmax
+ 50 AND b
(i
).y
> -50 AND b
(i
).y
< ymax
+ 50 THEN 'in bounds draw it 'check for collision with ...
t = hitTarget(i)
score = score + 130 - t(t).r
b(i).live = 0
newTarget t
explosions_add b(i).x, b(i).y, b(i).dx, b(i).dy
'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
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)
'check shooter x, y = fixed a long time ago!
'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
' 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
rd
= (a
+ .00001) / (b
+ .0001): degree
= ATN(rd
) / pip180
IF 0 > b
THEN degree
= degree
- 180 IF degree
< 0 THEN degree
= degree
+ 360
SUB explosions_add
(x
, y
, xd
, yd
) FOR t1
= 1 TO explosions_s
FOR t
= 0 TO explosions_buff
- 1 explosions(t, 0) = 1 'enable
explosions(t, 1) = x 'Xpos
explosions(t, 2) = y 'Ypos
explosions(t, 3) = 0 'xd / 2 'x direction
explosions(t, 4) = 0 'yd / 2 'y direction
angle
= 360 * RND(1) 'random angle speed
= 50 * RND(1) 'shard speed explosions
(t
, 5) = SIN(angle
* pip180
) * speed
'vector X explosions
(t
, 6) = COS(angle
* pip180
) * speed
'vector Y explosions
(t
, 7) = 100 * RND(1) 'boss cycle encounter explosions
(t
, 8) = 360 * RND(1) ' random/actual angle in radian explosions
(t
, 9) = (2 + 7 * RND(1)) * 4 'size explosions
(t
, 10) = (2 + 8 * RND(1)) * 3 'stepping rotate in radian explosions
(t
, 11) = 256 * RND(1) 'greyscale random color
FOR t
= 0 TO explosions_buff
- 1 explosions(t, 7) = explosions(t, 7) - 1 'cycle to dead
IF explosions
(t
, 7) <= 0 THEN explosions
(t
, 0) = 0:
_CONTINUE 'if cycle 0, then inactive shard explosions(t, 1) = explosions(t, 1) + explosions(t, 3) + explosions(t, 5) 'X pos add
explosions(t, 2) = explosions(t, 2) + explosions(t, 4) + explosions(t, 6) 'Y pos add
explosions(t, 8) = explosions(t, 8) + explosions(t, 10) 'actual degree in radian
explosions(t, 9) = explosions(t, 9) * .85 'size lower
explosions(t, 5) = explosions(t, 5) * .999 'vector X lower
explosions(t, 6) = explosions(t, 6) * .999 'vector Y lower
FOR t1
= 0 TO explosions_buff
- 1 q
(t
, 0) = SIN((t
* 120 + explosions
(t1
, 8)) * pip180
) * explosions
(t1
, 9) + explosions
(t1
, 1) q
(t
, 1) = COS((t
* 120 + explosions
(t1
, 8)) * pip180
) * explosions
(t1
, 9) + explosions
(t1
, 2) fTri q
(0, 0), q
(0, 1), q
(1, 0), q
(1, 1), q
(2, 0), q
(2, 1), _RGB32(explosions
(t1
, 11), 0, 0) 55: