07-03-2022, 08:51 PM
Hi all, I am starting a thread for MasterGy who has just PM'd me today asking about a spot of his own in Prolific Programmers. Until Steve can get him setup, I offer a place here like with vince to show off his talents in QB64.
To kick off this thread I found an interesting start of a game possibly, anyway it's interesting and fun to play:
That opening comment might be mine. I fixed up the degree function for version 2.0+ and added an escape from Do Loop since we are in Full Screen.
MasterGy, you are most welcome to add to this thread as you see fit. Thankyou for sharing all your interesting creations!
To kick off this thread I found an interesting start of a game possibly, anyway it's interesting and fun to play:
Code: (Select All)
' ref 2021-03-29 https://www.qb64.org/forum/index.php?topic=3714.msg131236#msg131236
' checkout how he reorientates the whole screen when the mouse is moved, no tan, atan nor atan2 used but it is way smoother than my mouse action
Randomize Timer
Const pip180 = 3.141592654 / 180
global_speed = 1.5
space_grav = 15
space = 1000 'space size x-y
planets = 600
planetsize_min = 1
planetsize_max = 12
planet_dif = .05
cr_c_max = 199
zoom = 10
me_buffer_size = 5000
'creating 2d planet
Dim cr(planets - 1, cr_c_max - 1, 1), cr_dat(planets - 1, 3), me_buffer(me_buffer_size - 1, 1)
'cd_dat 0-x,1-y,2-size,3-polars
For aplanet = 0 To planets - 1
cr_dat(aplanet, 2) = planetsize_min + (planetsize_max - planetsize_min) * Rnd(1) 'planet size
cr_l1 = (1 - planet_dif) * cr_dat(aplanet, 2)
cr_l2 = (1 + planet_dif) * cr_dat(aplanet, 2)
cr_dat(aplanet, 0) = space * Rnd(1) - space / 2 'X position
cr_dat(aplanet, 1) = space * Rnd(1) - space / 2 'Y position
cr_dat(aplanet, 3) = Int(cr_dat(aplanet, 2) * 6) 'polars
For t = 0 To cr_dat(aplanet, 3) - 1
cr_r = cr_l1 + (cr_l2 - cr_l1) * Rnd(1)
cr(aplanet, t, 0) = Sin(360 / cr_dat(aplanet, 3) * t * pip180) * cr_r
cr(aplanet, t, 1) = Cos(360 / cr_dat(aplanet, 3) * t * pip180) * cr_r
Next t, aplanet
me_x = 0 'my Xpos
me_y = 0 'my Ypos
me_a = 30 'my angle
me_size = 2 'arrow size
me_size_a = .4
mon = _NewImage(800, 600, 32): Screen mon: _FullScreen: _MouseHide
centx = _Width(mon) / 2: centy = _Height(mon) / 2
Do
'draw me
y1 = centy - me_size / 2 * zoom
y2 = y1 + me_size * zoom
Line (centx, y1)-(centx, y2)
y2 = y1 + me_size_a * zoom
Line (centx, y1)-(centx - me_size_a * zoom, y2)
Line (centx, y1)-(centx + me_size_a * zoom, y2)
'my position center, but where any object ?
grav_x = 0: grav_y = 0: grav_active = 0
For aplanet = 0 To planets - 1
angle1 = degree(me_x - cr_dat(aplanet, 0), me_y - cr_dat(aplanet, 1)) 'how many degree
angle2 = angle1 + angle_me '+arrow
distance = Sqr((me_x - cr_dat(aplanet, 0)) ^ 2 + (me_y - cr_dat(aplanet, 1)) ^ 2)
cr_cx = (Sin(angle2 * pip180)) * distance 'planet origo position on monitor
cr_cy = (Cos(angle2 * pip180)) * distance
For t = 0 To cr_dat(aplanet, 3)
If t = cr_dat(aplanet, 3) Then t2 = 0 Else t2 = t
px = cr(aplanet, t2, 0)
py = cr(aplanet, t2, 1)
angle_r = angle_me * pip180
px2 = (px * Cos(angle_r)) + (py * Sin(angle_r))
py2 = (py * Cos(angle_r)) - (px * Sin(angle_r))
px = (px2 + cr_cx) * zoom + centx
py = (py2 + cr_cy) * zoom + centy
If t Then Line (px, py)-(px_l, py_l)
px_l = px: py_l = py
Next t
'gravity planet
If distance < space / 100 * space_grav Then
grav_active = grav_active + 1
gravity = cr_dat(aplanet, 2) ^ 2 / distance ^ 2
'IF gravity > .01 THEN gravity = .01
grav_x = grav_x + Sin(angle1 * pip180) * gravity
grav_y = grav_y + Cos(angle1 * pip180) * gravity
End If
Next aplanet
'draw my way
For a_buff = 0 To me_buffer_size - 1: If me_buffer(a_buff, 0) = 0 Then _Continue
angle1 = degree(me_x - me_buffer(a_buff, 0), me_y - me_buffer(a_buff, 1)) 'how many degree
angle2 = angle1 + angle_me '+arrow
distance = Sqr((me_x - me_buffer(a_buff, 0)) ^ 2 + (me_y - me_buffer(a_buff, 1)) ^ 2)
cr_cx = (Sin(angle2 * pip180)) * distance 'planet origo position on monitor
cr_cy = (Cos(angle2 * pip180)) * distance
PSet (centx + cr_cx * zoom, centy + cr_cy * zoom)
Next a_buff
'control
mw = 0: mousex = 0: While _MouseInput: mousex = mousex + _MouseMovementX: mw = mw + _MouseWheel: Wend: angle_me = angle_me + mousex
If _MouseButton(1) Then speed = speed + .05
If _MouseButton(2) Then speed = speed - .05
'inertia vector
speed = speed - .01 * Sgn(speed)
If Abs(speed) > .5 Then speed = .5 * Sgn(speed)
vector_x_my = -Sin(pip180 * angle_me) * speed * global_speed
vector_y_my = -Cos(pip180 * angle_me) * speed * global_speed
'gravity vector
angle_g = degree(grav_x, grav_y)
strong = Sqr((grav_x - me_x) ^ 2 + (grav_y - me_y) ^ 2): If strong > 2 Then strong = 2
If Abs(strong) > 1 Then strong = 1 * Sgn(strong)
vector_x_grav = -Sin(pip180 * angle_g) * strong / 5 * global_speed
vector_y_grav = -Cos(pip180 * angle_g) * strong / 5 * global_speed
'resulting vector
me_x = me_x + vector_x_my + vector_x_grav
me_y = me_y - vector_y_my + vector_y_grav
If me_x > space / 2 Then me_x = me_x - space
If me_x < -space / 2 Then me_x = me_x + space
If me_y > space / 2 Then me_y = me_y - space
If me_y < -space / 2 Then me_y = me_y + space
me_buffer(me_buffer_a, 0) = me_x
me_buffer(me_buffer_a, 1) = me_y
me_buffer_a = me_buffer_a + 1: If me_buffer_a = me_buffer_size Then me_buffer_a = 0
zoom = zoom + mw / 2
If zoom > 50 Then zoom = 50
If zoom < .5 Then zoom = .5
'view
_Display
_Limit 30
Cls
'LOCATE 1, 1
'PRINT speed, SQR(grav_x ^ 2 + grav_y ^ 2)
' PRINT "grav_active:"; grav_active
Loop Until _KeyDown(27)
Function degree (a, b)
qarany = (a + .00001) / (b + .00001): d = honnan + Atn(qarany) / pip180
If 0 > b Then d = d - 180
If d < 0 Then d = d + 360
degree = d
End Function
That opening comment might be mine. I fixed up the degree function for version 2.0+ and added an escape from Do Loop since we are in Full Screen.
MasterGy, you are most welcome to add to this thread as you see fit. Thankyou for sharing all your interesting creations!
b = b + ...