Welcome, Guest |
You have to register before you can post on our site.
|
|
|
What day is Christmas on |
Posted by: eoredson - 11-30-2024, 03:36 AM - Forum: Christmas Code
- No Replies
|
|
Code to determine what day Christmas of 2024 is on:
Code: (Select All) Rem determine day of week Christmas of 2024 is:
m% = 12 ' month
d% = 26 ' day
y% = 2024 ' year
If m% < 3 Then m% = m% + 12: y% = y% - 1
W% = ((13 * m% + 3) \ 5 + d% + y% + y% \ 4 - y% \ 100 + y% \ 400 + 1) Mod 7
Select Case W%
Case 0
WeekDayLong$ = "Sunday"
Case 1
WeekDayLong$ = "Monday"
Case 2
WeekDayLong$ = "Tuesday"
Case 3
WeekDayLong$ = "Wednesday"
Case 4
WeekDayLong$ = "Thursday"
Case 5
WeekDayLong$ = "Friday"
Case 6
WeekDayLong$ = "Saturday"
End Select
Print "Christmas of 2024 is on: "; WeekDayLong$
End
|
|
|
Space Pongy |
Posted by: bplus - 11-29-2024, 06:51 PM - Forum: Programs
- Replies (3)
|
|
I was playing around with the paddle that you can angle with Mouse Wheel and thought it might be fun to do a Pongy style game with it like Ken's, so here it is!
Use mouse wheel to angle paddle either to bounce ball into Spaceship Or keep ball away from the Death Star.
You score a point when ball hits towards center of ship and lose a ball if Death Star runs into ball. You get 5 balls per game.
Code: (Select All) _Title "Space Pongy" 'b+ started 2020-03-08 from _vince idea Angle Paddle Collision
' 2024-11-29 Make game in style of Ken's Pongy
Const xmax = 800, ymax = 600, xc = 400, yc = 300
Dim Shared P, P2, Pd2
P = _Pi: P2 = 2 * P: Pd2 = P / 2
Dim Shared sx, sy, srI, srO, snP, sa, sdx, sdy ' death Star
Screen _NewImage(xmax, ymax, 32)
_ScreenMove 280, 60
Randomize Timer
bx = xc: by = yc: br = 20: bs = 5: ba = _D2R(60): ball = 5
mr = 50: ma = 0
goalx = 325: goaly = 80
goaldir = 2
NewStar
While _KeyDown(27) = 0
Cls
drawShip goalx, goaly, 2, &HFFFFFF00
goalx = goalx + goaldir
If goalx > 700 And goaldir = 2 Then goaldir = -2
If goalx < 100 And goaldir = -2 Then goaldir = 2
If _Hypot(bx - goalx, by - goaly) < br + 40 Then
score = score + 1: bx = _Width - goalx: by = _Height - goaly: ba = _Pi(2) * Rnd
For snd = 300 To 900 Step 50
Sound snd, .5
Next snd
End If
Circle (bx, by), br 'ball
Circle (bx, by), 2, &HFFFFFF00 'ball
drawStar
Locate 1, 20: Print "Score: "; score
Locate 1, 70: Print "Balls: "; ball
bdx = bs * Cos(ba): bdy = bs * Sin(ba)
bx = bx + bdx
If bx < br Then bx = br: bdx = -bdx
If bx > xmax - br Then bx = xmax - br: bdx = -bdx
by = by + bdy
If by < br Then by = br: bdy = -bdy
If by > ymax - br Then by = ymax - br: bdy = -bdy
ba = _Atan2(bdy, bdx)
While _MouseInput ' paddle
ma = ma + _MouseWheel * P2 / 72 '5 degrees change
Wend
mx = _MouseX: my = _MouseY
mx1 = mx + mr * Cos(ma)
my1 = my + mr * Sin(ma)
mx2 = mx + mr * Cos(ma + P)
my2 = my + mr * Sin(ma + P)
Line (mx1, my1)-(mx2, my2), &HFFFF8800
'draw a handle to track the side the ball is on
hx1 = mx + br * Cos(ma + Pd2): hy1 = my + br * Sin(ma + Pd2)
hx2 = mx + br * Cos(ma - Pd2): hy2 = my + br * Sin(ma - Pd2)
d1 = _Hypot(hx1 - bx, hy1 - by): d2 = _Hypot(hx2 - bx, hy2 - by)
If d1 < d2 Then
Line (hx2, hy2)-(mx, my), &HFFFF8800
paddleNormal = _Atan2(my - hy2, mx - hx2)
Else
Line (hx1, hy1)-(mx, my), &HFFFF8800
paddleNormal = _Atan2(my - hy1, mx - hx1)
End If
tx = -99: ty = -99
dist = _Hypot(bx - mx, by - my) ' collision?
If dist < br + mr Then ' centers close enough
contacts = lineIntersectCircle%(mx1, my1, mx2, my2, bx, by, br, ix1, iy1, ix2, iy2)
'If contacts Then Print "Contact"; contacts ': _DELAY .5 'OK so far
If contacts = 1 Then 'just touched (or passed through)
If _Hypot(ix1 - mx, iy1 - my) < br Then tx = ix1: ty = iy1
ElseIf contacts = 2 Then
'contact point would have been in middle of 2 points
tx = (ix1 + ix2) / 2: ty = (iy1 + iy2) / 2
End If
If tx > 0 Then ' rebound ball
Circle (tx, ty), 2 'show contact point
'relocate bx, by
bx = tx + br * Cos(paddleNormal) 'this is where the ball would be at contact
by = ty + br * Sin(paddleNormal)
'find the angle of reflection
ba = _Atan2(bdy, bdx)
aReflect = Abs(paddleNormal - ba) 'apparently I have to flip the next clac by PI
If ba < paddleNormal Then ba = paddleNormal + aReflect + P Else ba = paddleNormal - aReflect + P
End If
End If
'update death Star
sx = sx + sdx
If sx < srO Then sx = srO: sdx = -sdx
If sx > xmax - sor Then sx = xmax - sr0: sdx = -sdx
sy = sy + sdy
If sy < srO Then sy = srO: sdy = -sdy
If sy > ymax - srO Then sy = ymax - srO: sdy = -sdy
sa = sa + _Pi * .05
If _Hypot(sx - bx, sy - by) < br + srO Then
ball = ball - 1
For snd = 1200 To 200 Step -50
Sound snd, .5
Next
If ball <= 0 Then ' game over
Sleep
End
End If
NewStar
End If
'If _Hypot(goalx - sx, goaly - sy) < 40 + srO Then
' For snd = 900 To 300 Step -50
' Sound snd, .5
' Next
' NewStar
' bx = _Width - goalx: by = _Height - goaly: ba = _Pi(2) * Rnd
'End If
_Display
_Limit 60
Wend
' return 0 no Intersect, 1 = tangent 1 point touch, 2 = 2 point intersect
Function lineIntersectCircle% (lx1, ly1, lx2, ly2, cx, cy, r, ix1, iy1, ix2, iy2)
'needs SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept)
If lx1 <> lx2 Then
slopeYintersect lx1, ly1, lx2, ly2, m, Y0 ' Y0 otherwise know as y Intersect
' https://math.stackexchange.com/questions/228841/how-do-i-calculate-the-intersections-of-a-straight-line-and-a-circle
A = m ^ 2 + 1
B = 2 * (m * Y0 - m * cy - cx)
C = cy ^ 2 - r ^ 2 + cx ^ 2 - 2 * Y0 * cy + Y0 ^ 2
D = B ^ 2 - 4 * A * C 'telling part of Quadratic formula = 0 then circle is tangent or > 0 then 2 intersect points
If D < 0 Then ' no intersection
ix1 = -999: iy1 = -999: ix2 = -999: iy2 = -999: lineIntersectCircle% = 0
ElseIf D = 0 Then ' one point tangent
x1 = (-B + Sqr(D)) / (2 * A)
y1 = m * x1 + Y0
ix1 = x1: iy1 = y1: ix2 = -999: iy2 = -999: lineIntersectCircle% = 1
Else '2 points
x1 = (-B + Sqr(D)) / (2 * A): y1 = m * x1 + Y0
x2 = (-B - Sqr(D)) / (2 * A): y2 = m * x2 + Y0
ix1 = x1: iy1 = y1: ix2 = x2: iy2 = y2: lineIntersectCircle% = 2
End If
Else 'vertical line
If r = Abs(lx1 - cx) Then ' tangent
ix1 = lx1: iy1 = cy: ix2 = -999: iy2 = -999: lineIntersectCircle% = 1
ElseIf r < Abs(lx1 - cx) Then 'no intersect
ix1 = -999: iy1 = -999: ix2 = -999: iy2 = -999: lineIntersectCircle% = 0
Else '2 point intersect
ydist = Sqr(r ^ 2 - (lx1 - cx) ^ 2)
ix1 = lx1: iy1 = cy + ydist: ix2 = lx1: iy2 = cy - ydist: lineIntersectCircle% = 2
End If
End If
End Function
Sub slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) ' fix for when x1 = x2
slope = (Y2 - Y1) / (X2 - X1)
Yintercept = slope * (0 - X1) + Y1
End Sub
Sub drawShip (x, y, scale, colr As _Unsigned Long) 'shipType collisions same as circle x, y radius = 30
Static ls
Dim light As Long, r As Long, g As Long, b As Long
r = _Red32(colr): g = _Green32(colr): b = _Blue32(colr)
fellipse x, y, 6 * scale, 15 * scale, _RGB32(r, g - 120, b - 100)
fellipse x, y, 18 * scale, 11 * scale, _RGB32(r, g - 60, b - 50)
fellipse x, y, 30 * scale, 7 * scale, _RGB32(r, g, b)
For light = 0 To 5
fcirc x - 30 * scale + scale * 11 * light + ls * scale, y, 1 * scale, _RGB32(ls * 50, ls * 50, ls * 50)
Next
ls = ls + 1
If ls > 5 Then ls = 0
End Sub
' ======== helper subs for drawShip that you can use for other things specially fcirc = fill_circle x, y, radius, color
Sub fellipse (CX As Long, CY As Long, xr As Long, yr As Long, C As _Unsigned Long)
If xr = 0 Or yr = 0 Then Exit Sub
Dim h2 As _Integer64, w2 As _Integer64, h2w2 As _Integer64
Dim x As Long, y As Long
w2 = xr * xr: h2 = yr * yr: h2w2 = h2 * w2
Line (CX - xr, CY)-(CX + xr, CY), C, BF
Do While y < yr
y = y + 1
x = Sqr((h2w2 - y * y * w2) \ h2)
Line (CX - x, CY + y)-(CX + x, CY + y), C, BF
Line (CX - x, CY - y)-(CX + x, CY - y), C, BF
Loop
End Sub
Sub fcirc (x As Long, y As Long, R As Long, C As _Unsigned Long) 'vince version fill circle x, y, radius, color
Dim x0 As Long, y0 As Long, e As Long
x0 = R: y0 = 0: e = 0
Do While y0 < x0
If e <= 0 Then
y0 = y0 + 1
Line (x - x0, y + y0)-(x + x0, y + y0), C, BF
Line (x - x0, y - y0)-(x + x0, y - y0), C, BF
e = e + 2 * y0
Else
Line (x - y0, y - x0)-(x + y0, y - x0), C, BF
Line (x - y0, y + x0)-(x + y0, y + x0), C, BF
x0 = x0 - 1: e = e - 2 * x0
End If
Loop
Line (x - R, y)-(x + R, y), C, BF
End Sub
Sub NewStar
r = Rnd * 5 + 1
sx = Rnd * _Width: sy = Rnd * _Height: srI = Rnd * 20 + 10: srO = Rnd * 20 + 5 + 30
snP = Int(Rnd * 7) + 3: sa = _Pi(2 * Rnd): sdx = r * Cos(sa): sdy = r * Sin(sa)
End Sub
Sub drawStar
star sx, sy, srI, srO, snP, sa, &HFF0088FF
End Sub
Sub star (x, y, rInner, rOuter, nPoints, angleOffset, K As _Unsigned Long)
' x, y are same as for circle,
' rInner is center circle radius
' rOuter is the outer most point of star
' nPoints is the number of points,
' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
' this is to allow us to spin the polygon of n sides
Dim pAngle, radAngleOffset, x1, y1, x2, y2, x3, y3, i As Long
pAngle = _D2R(360 / nPoints): radAngleOffset = _D2R(angleOffset)
x1 = x + rInner * Cos(radAngleOffset)
y1 = y + rInner * Sin(radAngleOffset)
For i = 0 To nPoints - 1
x2 = x + rOuter * Cos(i * pAngle + radAngleOffset + .5 * pAngle)
y2 = y + rOuter * Sin(i * pAngle + radAngleOffset + .5 * pAngle)
x3 = x + rInner * Cos((i + 1) * pAngle + radAngleOffset)
y3 = y + rInner * Sin((i + 1) * pAngle + radAngleOffset)
ftri x1, y1, x2, y2, x3, y3, K
'triangles leaked
Line (x1, y1)-(x2, y2), K
Line (x2, y2)-(x3, y3), K
Line (x3, y3)-(x1, y1), K
x1 = x3: y1 = y3
Next
Paint (x, y), K, K
End Sub
Sub ftri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
Dim D As Long
Static a&
D = _Dest
If a& = 0 Then a& = _NewImage(1, 1, 32)
_Dest a&
_DontBlend a& ' '<<<< new 2019-12-16 fix
PSet (0, 0), K
_Blend a& '<<<< new 2019-12-16 fix
_Dest D
_MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
End Sub
Life is short in space.
|
|
|
Pin-Pongy |
Posted by: SierraKen - 11-28-2024, 08:13 PM - Forum: Programs
- Replies (1)
|
|
Using code from my Pongy game, I removed the mouse use and added pinball flippers. It still has the evil red ball that destroys your ball and to get points, you make it go into the moving goalie up above, like Pongy. I widened the goalie to make it easier and shrank the red ball in half. I do need some help on getting the flippers to detect the ball every time. They detect it maybe 90% of the time but they also bounce the ball down instead of up about half the time. For now, it's a goofy little game. Use both Ctrl keys to used the flippers.
Code: (Select All)
'Pin-Pongy - by SierraKen
'November 28, 2024
'This is a little goofy game I made using my Pongy code and adding flippers instead of a mouse ball.
'Sometimes the flippers work, sometimes they don't. That's what makes it's goofy. lol
'Thanks to the QB64 Phoenix Forum for the inspiration and past help.
'Thanks also to Chat GPT for the math code.
Do
Dim score As Single
Dim ball As Single
Dim boxRight As Single
Dim boxLeft As Single
Dim BoxTop As Single
Dim BoxBottom As Single
Dim a As String
Dim ag As String
score = 0
ball = 15
' Set box boundaries
boxLeft = 200
boxRight = 600
BoxTop = 25
BoxBottom = 575
seconds = 26
seconds2 = 35
Cls
Screen _NewImage(800, 600, 32)
' Ball properties
Dim As Integer ballX, ballY, ballx2, bally2
Dim As Single angle, angle2
Dim As Integer speedX, speedY, speedx2, speedy2
ballX = (boxRight + boxLeft) / 2 ' Start in the center
ballY = (BoxTop + BoxBottom) / 2
angle = 45 ' Starting angle in degrees
ballx2 = (boxRight + boxLeft) / 2 ' Start in the center
bally2 = (BoxTop + BoxBottom) / 2 + 100
angle2 = 45 ' Starting angle in degrees
' Convert angle to radians
Dim As Single radAngle
radAngle = angle * 3.14159265 / 180
Dim As Single radAngle2
radAngle2 = angle2 * 3.14159265 / 180
Dim goalx As Single
Dim goaly As Single
Dim goaldir As Single
Dim redballout As Single
Dim starx As Single
Dim stary As Single
' Set speed based on angle
speedX = Cos(radAngle) * 5
speedY = Sin(radAngle) * 5
speedx2 = Cos(radAngle2) * 5
speedy2 = Sin(radAngle2) * 5
goalx = 200: goaly = 25
goaldir = 1
redballout = 5
_Title "Pin-Pongy - by SierraKen - Use Both Ctrl Keys"
Randomize Timer
Do
Cls
a = InKey$
If a = Chr$(27) Then End
If _KeyDown(100306) Then
flip1 = 1: ' left side ctrl
Else
flip1 = 0
flip1stop = 0
End If
If _KeyDown(100305) Then
flip2 = 1: ' right side ctrl
Else
flip2 = 0
flip2stop = 0
End If
' Draw box boundaries
Line (boxLeft, BoxTop)-(boxRight, BoxBottom), _RGB32(255, 255, 255), B
' Draw Flippers
If flip1 = 0 Or flip1stop = 1 Then
Line (boxLeft, BoxBottom - 180)-(boxLeft + 180, BoxBottom - 30), _RGB32(253, 253, 253)
seconds = 26
End If
If flip2 = 0 Or flip2stop = 1 Then
Line (boxRight, BoxBottom - 180)-(boxRight - 180, BoxBottom - 30), _RGB32(253, 253, 253)
seconds2 = 35
End If
'Left Flipper
If flip1 = 1 And flip1stop = 0 Then
If seconds > 25 Then flip1up = 1
If seconds < 5 Then flip1up = 2
If flip1up = 1 Then seconds = seconds - .75
If flip1up = 2 And _KeyDown(100306) = 0 Then seconds = seconds + .75
If flip1up = 2 And seconds > 25 Then
flip1 = 0: flip1up = 0: flip1stop = 1:
Line (boxLeft, BoxBottom - 180)-(boxLeft + 180, BoxBottom - 30), _RGB32(253, 253, 253)
GoTo skip1:
End If
s = (60 - seconds) * 6 + 180
x = Int(Sin(s / 180 * 3.141592) * 200) + boxLeft
y = Int(Cos(s / 180 * 3.141592) * 200) + BoxBottom - 180
skip1:
For f3 = .1 To 5 Step .1
Line (boxLeft + f3, BoxBottom - 180 + f3)-(x + f3, y + f3), _RGB32(253, 253, 253)
Next f3
End If
'Right Flipper
If flip2 = 1 And flip2stop = 0 Then
If seconds2 < 36 Then flip2up = 1
If seconds2 > 55 Then flip2up = 2
If flip2up = 1 Then seconds2 = seconds2 + .75
If flip2up = 2 And _KeyDown(100305) = 0 Then seconds2 = seconds2 - .75
If flip2up = 2 And seconds2 < 36 Then
flip2 = 0: flip2up = 0: flip2stop = 1:
Line (boxRight, BoxBottom - 180)-(boxRight - 180, BoxBottom - 30), _RGB32(253, 253, 253)
GoTo skip2:
End If
s2 = (60 - seconds2) * 6 + 180
x2 = Int(Sin(s2 / 180 * 3.141592) * 200) + boxRight
y2 = Int(Cos(s2 / 180 * 3.141592) * 200) + BoxBottom - 180
skip2:
For f4 = .1 To 5 Step .1
Line (boxRight + f4, BoxBottom - 180 + f4)-(x2 + f4, y2 + f4), _RGB32(253, 253, 253)
Next f4
End If
For check = -4 To 4 Step .5
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(254, 254, 254) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(253, 253, 253) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(252, 252, 252) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(251, 251, 251) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(250, 250, 250) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(253, 252, 252) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(253, 251, 251) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(252, 251, 251) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(252, 253, 253) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(251, 252, 252) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(251, 251, 252) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(252, 252, 253) Then GoTo collision:
If Point(Int(ballX + check), Int(ballY + check)) = _RGB32(253, 252, 251) Then GoTo collision:
Next check
flipper:
Line (goalx, goaly)-(goalx + 200, goaly), _RGB32(1, 1, 1)
goalx = goalx + goaldir
If goalx = 680 And goaldir = 1 Then goaldir = -1
If goalx = 20 And goaldir = -1 Then goaldir = 1
' Draw the ball
fillCircle ballX, ballY, 10, _RGB32(255, 255, 255)
If redballout = 0 Then fillCircle ballx2, bally2, 10, _RGB32(255, 0, 0)
' Update ball position
ballX = ballX + speedX
ballY = ballY + speedY
If redballout = 0 Then
ballx2 = ballx2 + speedx2
bally2 = bally2 + speedy2
End If
If ballX > goalx And ballX < goalx + 200 And ballY < 26 Then
score = score + 1: ballX = 375: ballY = 275: speedY = -speedY
For snd = 300 To 900 Step 50
Sound snd, .5
Next snd
End If
Locate 1, 20: Print "Score: "; score
Locate 1, 70: Print "Balls: "; ball
' Check for collision with box boundaries
If ballX <= boxLeft Or ballX >= boxRight Then
speedX = -speedX ' Reflect on the X axis
If redballout > 0 Then redballout = redballout - 1
Sound 600, .5
End If
If ballY <= BoxTop Or ballY >= BoxBottom Then
speedY = -speedY ' Reflect on the Y axis
If redballout > 0 Then redballout = redballout - 1
Sound 600, .5
End If
If ballY > BoxBottom + .4 Then ballY = BoxBottom - 7
If ballY < BoxTop - .4 Then ballY = BoxTop + 7
If ballX > boxRight + .4 Then ballX = boxRight - 7
If ballX < boxLeft - .4 Then ballX = boxLeft + 7
'If redballout > 0 Then GoTo skip:
If (ballx2 <= boxLeft Or ballx2 >= boxRight) And redballout = 0 Then
speedx2 = -speedx2 ' Reflect on the X axis
Sound 600, .5
End If
If (bally2 <= BoxTop Or bally2 >= BoxBottom) And redballout = 0 Then
speedy2 = -speedy2 ' Reflect on the Y axis
Sound 600, .5
End If
If bally2 > BoxBottom + .4 And redballout = 0 Then bally2 = BoxBottom - 7
If bally2 < BoxTop - .4 And redballout = 0 Then bally2 = BoxTop + 7
If ballx2 > boxRight + .4 And redballout = 0 Then ballx2 = boxRight - 7
If ballx2 < boxLeft - .4 And redballout = 0 Then ballx2 = boxLeft + 7
'skip:
' Check for collision between red ball and white ball.
'If redballout > 0 Then GoTo skip2:
If Sqr((ballx2 - ballX) ^ 2 + (bally2 - ballY) ^ 2) < 25 And redballout = 0 Then
fillCircle ballX, ballY, 10, _RGB32(0, 0, 0)
snd = 300
_AutoDisplay
starx = ballX: stary = ballY
For t = 1 To 25
fillCircle starx, stary, t * 5, _RGB32(255, 255, 255)
Sound snd - t, .5
Next t
redballout = 5
Locate 1, 70: ball = ball - 1: Print "Balls: "; ball
If ball = 0 Then
_AutoDisplay
Locate 20, 50: Print "G A M E O V E R":
Locate 25, 50
Print "Again (Y/N)?"
Do
ag = InKey$
If ag = "y" Or ag = "Y" Then Exit Do
If ag = "n" Or ag = "N" Then End
Loop
Exit Do
End If
Sound 600, .5
End If
'skip2:
_Display
_Limit 60 ' Limit the speed of the loop to 60 FPS
Loop
Loop
collision:
' Calculate deflection angle
radAngle = _Atan2(ballY, ballX) * 180 / 3.14159265
'radAngle = angle * 3.14159265 / 180
speedX = Cos(radAngle) * 5
speedY = Sin(radAngle) * 5
ballX = ballX + speedX
ballY = ballY + speedY
Sound 100, 1
skip3:
GoTo flipper:
'from Steve Gold standard
Sub fillCircle (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
Dim Radius As Integer, RadiusError As Integer
Dim X As Integer, Y As Integer
Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
If Radius = 0 Then PSet (CX, CY), C: Exit Sub
Line (CX - X, CY)-(CX + X, CY), C, BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
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
Wend
End Sub
|
|
|
Mix mode input of a binary open file Question! |
Posted by: doppler - 11-28-2024, 01:06 PM - Forum: General Discussion
- Replies (5)
|
|
I get the strangest ideas now and then. By the experts here everyone might get ideas about my thought. - OR - I will be shot down in flames.
Normally I would use binary open to read in a text file. Much faster than "open" using input mode. My thoughts on the matter, I would like to use a mix mode of getting the data. I would normally open with binary mode start reading using "line input #1,d$". But switch to "input #1,n1,n2,n3,n4" at some point. Such as content of my file:
# Comments
# Comments
# Comments
# Comments
#
#eoc
1,2,3,4
5,6,7,8
9,10,11,12
999999,0,0,0
# more comments
# Comments
# Comments
# Comments
# Comments
#
#eoc
13,14,15,16
17,18,19,20
Note the line "#eoc". This would be my trigger point to switch to "input #1,n1,n2,n3,n4" to get the remaining data. An after thought at this point and I changed my file now as I am typing this out. If I can switch mix input modes. Can I go back to "line input" and again go back to "input" modes ? The other trigger point is the 999999 value in first position.
I can see this as a possibility since binary input has a pointer to the file opened. To where the next read of file takes place. The input request only specifics how much input happens and where to stop.
Thanks for any answers.
BTW, if you are a United States member. Why are you reading my comments. GO GET STUFFED!!!.
By Turkey.
|
|
|
Incongruence between PRINT; and LOCATE+ PRINT; on the 25th row of Screen 0 |
Posted by: TempodiBasic - 11-25-2024, 06:16 PM - Forum: Learning Resources and Archives
- Replies (6)
|
|
Hi friends
here I discovered again hot water!!!
here the experience about PRINT in SCREEN 0 (standard 80 columns and 25 rows of text)
Be calm QB64pe duplicates QB4.5 and Qbasic in this behaviour , so the issue comes from the far past of Qbasic.
run the code and enjoy the experience:
Code: (Select All)
_Title "Incongruence of behaviour of 25th line of text in SCREEN 0 using PRINT;"
While s$ <> "Q"
Locate 1, 1
Print "Please choose 1 to test PRINT; mode " + Chr$(13) + "and 2 to test LOCATE & PRINT; mode" + Chr$(13) + "press q to quit program demonstration"
s$ = UCase$(InKey$)
If s$ = "1" Then
GoSub PrintMode1
ElseIf s$ = "2" Then
GoSub PrintMode2
End If
Wend
End
PrintMode1:
Cls
For a% = 1 To 25
If a% = 25 Then Print a%; Else Print a%
_Delay .2
Next a%
Sleep 2
Cls
Return
PrintMode2:
Cls
For a% = 1 To 25
Locate a%, 1
Print a%;
_Delay .2
Next a%
Sleep 2
Cls
Return
I repeat that this code (adapted to Qbasic : no instructions _delay and _Title) gives the same result in Qbasic under Dosbox!
Well you can see how you can print on the 25th row (the last at the bottom) without going ahead only if you use LOCATE before PRINT ; otherwise you go ahead also if you use PRINT; and you don't go over the 80 characters for row!
Why this information is useful?
in a Q&A
Question: How to print on the last row of text without going ahead?
Answer: You must use Locate Lastrow, Column: Print SomethingToPrint; (Be care that Lastcolumn - Column >=LEN(SomeThingToPrint)) [example LOCATE 25,10: PRINT "SomethingLessThanLastColumn" REM 80-10 >= LEN( "SomethingLessThanLastColumn") --> 70>=27
|
|
|
Happy Birthday Petr! |
Posted by: Dav - 11-23-2024, 02:59 PM - Forum: General Discussion
- Replies (10)
|
|
I see in the forum calendar that today is Petr’s birthday. Have a happy one! Thanks for sharing your programming talents here with us all.
- Dav
|
|
|
Emulating DS4QB2 |
Posted by: jofers - 11-23-2024, 01:20 PM - Forum: QBJS, BAM, and Other BASICs
- Replies (4)
|
|
You might need to be a certain age to appreciate this, but I made a "driver" for emulating old QB games that use DS4QB2 for sound in the V86 PC emulator. Behold, no one has heard these sounds in 20 years!
Some tests:
Some that almost work but not quite- Super Sumo Wrestling - gets to the menu screen and plays music, but hangs
- Zeta (B2) - (game from the library author. Gets to the production logo and hangs before playing anything)
Long story:
DS4QB was a family of audio libraries for QB. Instead of using a sound blaster driver, they used an I/O port to signal a Win32 host application that played sounds using LibBASS. This ended up being a cursed solution - when Windows XP rolled around with its Hardware Abstraction Layer, both DOS and Win32 applications lost direct access to I/O and the games stopped working. And since it used this hacky mechanism, DOS emulators never supported it, unless you make a VM and install Windows 9x on it.
How I got this working:
V86 is a lovely, very hackable javascript X86 emulator. So I wanted to see if I could run DOS in the emulator and talk to games using one of the DS4QB protocol, but from Javascript code. I picked DS4QB2 because it had a lot of games using it, and it's easier to emulate than the original.
DS4QB2 communicated with its host (a Visual Basic program) like this:- Client writes parameters to a file called DS4QB2.DAT
- Client sets I/O port 0 (DMA) to a value to indicate the function
- Host polls port 0 and responds when the value is non-zero
- Host reads parameters from DS4QB2.DAT and calls an audio function
- Host clears port 0
- Guest polls port 0 and resume executing
V86 has an API to read I/O ports, so I polled it every 50ms and did a little dance when I saw port 0 flip from 0 to 3 ("Load SFX").
But V86 doesn't have any APIs to share files with DOS guests. Luckily though, If you put the contents of your FAT image into an ArrayBuffer and provide that instead of a URL to V86 for the hard disk, it will read and write blocks directly to that ArrayBuffer. So, using a FAT library I ported to webassembly, I mounted, read DS4QB2.DAT, and unmounted the ArrayBuffer right after the port when high.
With the decoded signal and parameters, I used howler.js to play sounds and MP3s. MOD/IT/S3M/XM don't have browser support, so I used a library called chiptune3.js to play those.
I also added a few other nice-to-haves:- Automatically extract ZIP files into a FAT image
- Code to open AUTOEXEC.BAT and add a game's EXE, the mouse driver, or EMS Magic.
What's Left:
DS4QB++ shouldn't be too bad to support since it had a Win9X mode that worked similarly to DS4QB2
The original DS4QB, however, used a clipboard interrupt that Windows 3.1 and 9x added for transferring parameters. Supporting this will require writing a TSR to mimic the original interrupts and write memory addresses to I/O ports instead of whatever black magic Windows used to access the clipboard.
I need to package the source code and make it available. In the meantime, if anyone has any old hard drives with forgotten DS4QB2 games, let me know!
|
|
|
Flying |
Posted by: SierraKen - 11-23-2024, 05:07 AM - Forum: SierraKen
- Replies (4)
|
|
Here is a pretty basic flying simulator I made back in 2020. It has no ground map, just random hills, water, and line grid. And it doesn't show any part of the plane, just the outside. It shows the altitude and speed. I made this as an example, or a possible framework to make it better later on, or into a game. Instructions are in the title bar. There's no actual "flying simulation" to it, just basic turning, speed, and higher and lower. Start out by adding some speed with the + key (to decrease use the - key). Then use the down arrow key to go up and up arrow key to go down. The left and right arrow keys turn. And that's about it. It reminds me of 1980's games a little bit.
Code: (Select All)
'Flying - By SierraKen
'Made on May 26, 2020.
'V. 0.9 - Fixed airspeed and made hills look better.
Dim waterx(500), watery(500), shape(500), watersz(500)
Dim hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
Dim cloudx(500), cloudy(500), shapecl(500), cloudsz(500)
Screen _NewImage(800, 600, 32)
xs = 10
c = 0
e = 100
d = 0
For g = 1 To 20
GoSub grid:
Next g
_Title "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
Do
_Limit 2000
a$ = InKey$
If a$ = Chr$(0) + Chr$(72) Then d = 6: e = e + .5: b = 0 'Up arrow key flies down.
If a$ = Chr$(0) + Chr$(80) Then d = 5: e = e - .5: b = 0 'Down arrow key flies up.
If a$ = "+" Then d = 1: speed2 = speed2 + 10
If a$ = "-" Then
speed2 = speed2 - 10
End If
If speed2 <= 0 Then speed = 0: b = 1: d = 0
If a$ = Chr$(0) + Chr$(77) Then d = 3: speed2 = speed2 + .2 'Right
If a$ = Chr$(0) + Chr$(75) Then d = 4: speed2 = speed2 + .2 'Left
If a$ = Chr$(27) Then End
If d = 1 Then speed = speed + 2: b = 0
If d = 3 And speed > 0 Then
v = v - 1
vv = vv - 2
tilt = tilt - 2
End If
If d = 4 And speed > 0 Then
v = v + 1
vv = vv + 2
tilt = tilt + 2
End If
If d = 3 And speed <= 0 Then
v = v - 1
vv = vv - 2
tilt = tilt - 2
speed = speed + 4
End If
If d = 4 And speed <= 0 Then
v = v + 1
vv = vv + 2
tilt = tilt + 2
speed = speed + 4
End If
If d = 5 Or speed2 > 0 Then speed = speed + 1: b = 0
If d = 6 Or speed2 > 0 Then speed = speed + 1: b = 0
If tilt > 200 Then tilt = 200
If tilt < -200 Then tilt = -200
If (d = 3 Or d = 4 Or d = 5 Or d = 6) And b = 0 Then speed = speed + 1
If (d = 3 Or d = 4) And b = 1 Then speed = speed - 1
If e > 100 Then e = 100
If e < 0 Then e = 0
elevation = e - 100
elevation = -elevation
elevation = elevation * 100
If d <> 0 Then GoSub grid:
If speed2 < 0 Then speed2 = 0
If speed2 > 500 Then speed2 = 500
delay = 2 / speed2
If delay < .002 Then delay = .002
If delay > .02 Then delay = .02
_Delay delay
Loop
grid:
Cls
For bsky = 0 To 600
Line (0, bsky)-(800, bsky), _RGB32(0, 0, bsky)
Next bsky
Line (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
Paint (400, 599), _RGB32(0, 155, 0)
'Calculate Compass
tilt2 = tilt
If tilt2 < 0 Then tilt2 = -tilt2
If tilt < 0 Then c = c - tilt2 / 314
If tilt > 0 Then c = c + tilt2 / 314
If c > 359 Then c = 0
If c < 0 Then c = 359
cc = Int(c)
If cc >= 340 Or cc < 25 Then comp$ = "North"
If cc >= 25 And cc < 65 Then comp$ = "Northeast"
If cc >= 65 And cc < 115 Then comp$ = "East"
If cc >= 115 And cc < 160 Then comp$ = "Southeast"
If cc >= 160 And cc < 205 Then comp$ = "South"
If cc >= 205 And cc < 250 Then comp$ = "Southwest"
If cc >= 250 And cc < 295 Then comp$ = "West"
If cc >= 295 And cc < 340 Then comp$ = "Northwest"
_PrintMode _KeepBackground
_PrintString (390, 550), comp$
cc$ = Str$(cc)
_PrintString (395, 570), cc$
'Sun
If cc < 225 Or cc > 315 Then til = 0: GoTo nosun:
tilt3 = tilt / 50
If cc = 315 Then sunx = 800
If cc = 225 Then sunx = 0
If cc < 315 And tilt < 0 And tilt3 = oldtilt3 Then sunx = sunx - 10: til = til - tilt3
If cc > 225 And tilt > 0 And tilt3 = oldtilt3 Then sunx = sunx + 10: til = til + tilt3
oldtilt3 = tilt3
For sz = .25 To 10 Step .25
Circle (sunx, til), sz, _RGB32(255, 255, 127)
Next sz
nosun:
'Clouds
Randomize Timer
clouds = Int(Rnd * 200) + 1
If clouds > 190 Then
cl = cl + 1
If cl > 100 Then cl = 1
Randomize Timer
cloudx(cl) = Int(Rnd * 799) + 1
cloudy(cl) = 180
Randomize Timer
cloudsz(cl) = Int(Rnd * 5) + 1 + e / 1.5
If cloudsz(cl) < 10 Then cloudsz(cl) = 10
Randomize Timer
shapecl(cl) = (Rnd - .4)
If shapecl(cl) < .4 Then shapecl(cl) = .4
End If
If cl = 0 Then GoTo skipclouds2:
For cl2 = 1 To cl
cloudy(cl2) = cloudy(cl2) - speed2 / 125
tilt6 = tilt / 5
If tilt6 < 0 Then tilt6 = -tilt6
cloudy(cl2) = cloudy(cl2) + tilt6 / 10
If cloudy(cl2) < -50 Then GoTo skipclouds:
ttttilt = tilt / 10
If ttttilt > 6 Then ttttilt = 6
If ttttilt < -6 Then ttttilt = -6
cloudx(cl2) = cloudx(cl2) + ttttilt
If cloudx(cl2) < -50 Or cloudx(cl2) > 850 Then GoTo skipclouds:
If cloudy(cl2) >= 175 Then ccl = 100
If cloudy(cl2) < 175 And cloudy(cl2) >= 150 Then ccl = 125
If cloudy(cl2) < 150 And cloudy(cl2) >= 125 Then ccl = 150
If cloudy(cl2) < 125 And cloudy(cl2) >= 100 Then ccl = 175
If cloudy(cl2) < 100 And cloudy(cl2) >= 75 Then ccl = 200
If cloudy(cl2) < 75 And cloudy(cl2) >= 50 Then ccl = 225
If cloudy(cl2) < 50 Then ccl = 255
For sz = .25 To cloudsz(cl2) Step .25
Circle (cloudx(cl2), cloudy(cl2)), sz, _RGB32(ccl, ccl, ccl), , , shapecl(cl2)
Next sz
skipclouds:
Next cl2
skipclouds2:
'Water
Randomize Timer
water = Int(Rnd * 200) + 1
If water > 197 Then
w = w + 1
If w > 100 Then w = 1
Randomize Timer
waterx(w) = Int(Rnd * 799) + 1
watery(w) = 310
Randomize Timer
watersz(w) = Int(Rnd * 5) + 1 + e / 1.5
Randomize Timer
shape(w) = (Rnd - .35)
End If
If w = 0 Then GoTo skipwater2:
For ww = 1 To w
watery(ww) = watery(ww) + speed2 / 125
tilt4 = tilt / 5
If tilt4 < 0 Then tilt4 = -tilt4
watery(ww) = watery(ww) + tilt4 / 10
If watery(ww) > 650 Then GoTo skipwater:
ttilt = tilt / 10
If ttilt > 6 Then ttilt = 6
If ttilt < -6 Then ttilt = -6
waterx(ww) = waterx(ww) + ttilt
If waterx(ww) < -50 Or waterx(ww) > 850 Then GoTo skipwater:
If Point(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) Then GoTo skipwater:
For sz = .25 To watersz(ww) Step .25
Circle (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
Next sz
skipwater:
Next ww
skipwater2:
'Hills
Randomize Timer
hills = Int(Rnd * 200) + 1
If hills > 150 Then
h = h + 1
If h > 300 Then h = 1
Randomize Timer
hillx(h) = Int(Rnd * 799) + 1
hilly(h) = 310
Randomize Timer
hillsz(h) = Int(Rnd * 5) + 1 + e / 1.5
Randomize Timer
hshape(h) = (Rnd - .35)
hcolor(h) = Int(Rnd * 100) + 100
End If
If h = 0 Then GoTo skiphill2:
l = l + 1
For hh = 1 To h
If speed2 > 0 Then hilly(hh) = hilly(hh) + speed2 / 125
tilt5 = tilt / 5
If tilt5 < 0 Then tilt5 = -tilt5
hilly(hh) = hilly(hh) + tilt5 / 10
If hilly(hh) > 650 Then GoTo skiphill:
tttilt = tilt / 10
If tttilt > 6 Then tttilt = 6
If tttilt < -6 Then tttilt = -6
hillx(hh) = hillx(hh) + tttilt
If hillx(hh) < -50 Or hillx(hh) > 850 Then GoTo skiphill:
If Point(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) Then GoTo skiphill:
For sz = .25 To hillsz(hh) Step .25
Circle (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh), hcolor(hh) + 44, 0), 2 * _Pi, _Pi, hshape(hh)
Next sz
skiphill:
Next hh
skiphill2:
'Left vertical lines.
For x = 395 - e To -300 Step -xs - xx - e
xx = xx + 55
If v > 7 + e Then v = -7
If v < -7 Then v = 7 + e
If vv > 300 Then vv = 300
If vv < -300 Then vv = -300
For findy = 0 To 600
If Point(x + v - vv, findy) = _RGB32(0, 155, 0) Then yy = findy: GoTo nex:
Next findy
nex:
If Point(x - xx + v + vv, 600) = _RGB32(0, 0, 150) Or Point(x + v - vv, yy) = _RGB32(0, 0, 150) Then GoTo skip:
Line (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
skip:
Next x
'Right vertical lines.
For x = 405 + e To 1100 Step xs + xx2 + e
xx2 = xx2 + 55
If v > 7 + e Then v = -7
If v < -7 Then v = 7 + e
If vv > 300 Then vv = 300
If vv < -300 Then vv = -300
For findy = 0 To 600
If Point(x + v - vv, findy) = _RGB32(0, 155, 0) Then yy2 = findy: GoTo nex2:
Next findy
nex2:
If Point(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) Or Point(x + v - vv, yy2) = _RGB32(0, 0, 150) Then GoTo skip2:
Line (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
skip2:
Next x
'Horizontal lines.
For hy = 0 To 600 Step xs + xx3 + e
xx3 = xx3 + 5
If speed > 7 + e Then speed = -7
If speed < -7 Then speed = 7 + e
For findx = 0 To 800
If Point(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) Then
xx4 = findx
End If
Next findx
For findx2 = 0 To 800
If Point(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) Then
xx5 = findx2
Line (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
GoTo nex3:
End If
Next findx2
nex3:
Next hy
_PrintMode _KeepBackground
_PrintString (250, 550), "Altitude"
elevation$ = Str$(elevation)
_PrintString (255, 570), elevation$
_PrintString (530, 550), "Airspeed"
speed2 = Int(speed2)
speed2$ = Str$(speed2)
_PrintString (535, 570), speed2$
_Display
xx = 0: xx2 = 0: xx3 = 0
Return
|
|
|
|