Here's an ancient QB version of Defender by Tim Truman from the 90s.
The original "QBDEFEND.BAS" failed because of deffn, so I turned that into a function.
It now runs but way too fast, so I added _Limit at line 248, which brought it back to normal speed.
That version is "QBDEFEND_v2.BAS".
(I tried cleaning it up some more but "QBDEFEND_v8.BAS" fails with a subscript out of range error at line 2784.)
There are probably bigger problems with the program - ancient joystick, timer, adlib routines, writing to adlibs registers, a whole lot of stuff I don't understand.
If anyone wants to play with it, I am attaching the code!
I'm sure at some point I've done this, but now I can't find the example.
Let's say I'm wanting to express a heading to navigate. Formally, instead of saying "heading 45," you would say "heading 045 degrees."
So, if I calculate a heading of 45, how would I then print that as 045? In hex, you'd use
c$ = Right$("0000" + Hex$(n), 4)
to always show leading 0s if the hex value otherwise might consist of less than four characters. I'm pretty sure there's a way of doing this sort of thing directly with decimal numbers?
Thanks, guys. I couldn't figure out where to find this in the wiki.
It being so diminutive, it is pretty awesome for embedding into anything, and setting it up as "view-only": go to settings, click on a check box, and save.
I'm interested in knowing if there might be a different way to recalculate Scientific Notation into a decimal value. Here is the method I'm presently using which works ok with Single dimension arrays/variables but when the resultant value is zero I've been going back are Redim to Double or whatever can get me a decimal value other than zero.
Code: (Select All)
' Removing Scientific Notation from a Variable/Array of Single dimension
Dim Shared Number, x, y
'In the main module will be a calculation which generates a Scientifically Notated value
Number = 115 / 123456
Print Number
x = 115
y = 123456
Number = SNrid
Print Number
Function SNrid
ScNote$ = Str$(x / y)
If InStr(1, ScNote$, "E") Or InStr(1, ScNote$, "D") Then
SNA = x / y
a = SNA * 10000000
b = a \ 1
C = a - b
If C >= .5 Then
b = b + 1
SNB = b * .0000001
End If
If C < .5 Then
SNB = b * .0000001
End If
SNrid = SNB
Exit Function
End If
SNrid = x / y
The small screen resolution when using the font causes an error for me - the program has stopped working and will be terminated. I am attaching the font used to test if it will behave the same on your systems. I understand that the screen height is set small, but if you are debugging a large program, this type of error will definitely be very annoying to deal with.
NOTE: Later down there's an updated version that is more optimized and does away with colons.
I present to you the game Mastermind, in 25 lines of code. Technically a little more because of
colons, but all the colons here are fine I think. For tiny little one-statement DO and FOR loops,
I find it's more readable like this; likewise for concatenating a handful of simple results of an
IF statement, to avoid a block IF...END IF. For much larger programs, it makes understanding
program flow much less convoluted, since my eyes have less nesting hierarchy to navigate.
Also, this code works in QBasic!
Code: (Select All)
do: input "How many possible letters (2-26)? ", code_colors%: loop while code_colors% < 2 or code_colors% > 26
do: input "How many letters long? ", code_length%: loop while code_length% < 1
dim match%(code_length%)
randomize timer
for n = 1 to code_length%: solution$ = solution$ + chr$(int(rnd * code_colors%) + asc("a")): next n
do
do: input "> ", attempt$: loop until len(attempt$) = code_length%
black_pegs% = 0: white_pegs% = 0
for n = 1 to code_length%
if mid$(attempt$, n, 1) <> mid$(solution$, n, 1) then match%(n) = 0 else match%(n) = n: black_pegs% = black_pegs% + 1
next n
for n = 1 to code_length%
if match%(n) = 0 then
for n1 = 1 to code_length%
if n1 <> n and mid$(attempt$, n, 1) = mid$(solution$, n1, 1) then
for n2 = 1 to code_length%
if match%(n2) <> n1 then m = 0 else m = -1: exit for ' Check for pre-existing white peg
next n2
if m = 0 then match%(n) = n1: white_pegs% = white_pegs% + 1: exit for
end if
next n1
end if
next n
print black_pegs%; "black,"; white_pegs%; "white"
loop while black_pegs% < code_length%
This operates exactly like Mastermind as you know it, except with lowercase letters instead of
colored pegs. You specify how many letters are possible, and how long the solution is. So, if
you say 12 possible letters and 4 letters long, the game will use the letters a through l, and
produce solutions such as "glhf" and "dljk." If you say 2 possible letters and 15 letters long,
it will produce things like "baabbbabaababba."
Guesses must be of the specified length, and must be in all lowercase. The game will signal
a correct letter in correct position with a "black peg," just like a typical Mastermind set,
and will signal a correct letter that is in the wrong position with a "white peg." For example,
if the solution is "hall," and you guess "hola," you will get two black pegs for the first h and
the third l, and one white peg for the a, which is not in the second position. If the solution
is "other," and you guess "trout," you will get three white pegs, not four, since the solution
only has one t.
Posted by: Petr - 03-25-2023, 04:01 PM - Forum: Petr
- Replies (52)
I'll say straight away that I literally only passed very light OpenGL. Still, I have a few absolutely basic things to post here.
The first program is completely primitive. Draws a triangle and a square in 2D, without texture.
Code: (Select All)
$Resize:On
Screen _NewImage(800, 600, 32)
Do While InKey$ <> Chr$(27)
_Limit 20
Loop
Sub _GL
_glViewport 0, 0, 800, 600
_glMatrixMode _GL_PROJECTION '// set projection matrix
_glLoadIdentity ' // Reset matrix
_gluPerspective 45.0F, 800 / 600, 0.1F, 100.0F ' claculate perspective
_glMatrixMode _GL_MODELVIEW ' set matrix _GL_MODELVIEW
_glLoadIdentity
_glShadeModel _GL_SMOOTH ' allow smooth shading
_glClearColor 0.0F, 0.0F, 0.0F, 0.5F
_glClearDepth 1.0F ' set depth buffer
_glEnable _GL_DEPTH_TEST ' allow depth testing
_glDepthFunc _GL_LEQUAL ' depth testing type
_glHint _GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ' set the best projection correction
_glClear _GL_COLOR_BUFFER_BIT: _glClear _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
_glLoadIdentity ' matrix reset
' Sem kresli primitivy
_glTranslatef -1.5F, 0.0F, -6.0F 'Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glBegin _GL_TRIANGLES ' Begin draw triangle
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point
_glVertex3f -1.0F, -1.0F, 0.0F ' left bottom point
_glVertex3f 1.0F, -1.0F, 0.0F ' right bottom point
_glEnd ' End draw triangle
_glTranslatef 3.0F, 0.0F, 0.0F ' we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a square
_glBegin _GL_QUADS ' Square draw begin
_glVertex3f -1.0F, 1.0F, 0.0F ' left upper point
_glVertex3f 1.0F, 1.0F, 0.0F ' right upper point
_glVertex3f 1.0F, -1.0F, 0.0F ' right bottom point
_glVertex3f -1.0F, -1.0F, 0.0F ' left bottom point
_glEnd ' end draw square
End Sub
[size=1]182 / 5 000
[/size]
This source code shows how to draw a pyramid in color with blending colors on the walls, as well as how to draw a cube with walls of one color and how to rotate these objects.
Code: (Select All)
$Resize:On
Screen _NewImage(800, 600, 32) '
Dim Shared rquad As _Float: rquad = 7
Dim Shared rtri As _Float: rtri = 7
_glTranslatef -1.5F, 0.0F, -6.0F ' Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glRotatef rtri, 0.0F, 1.0F, 0.0F ' Rotate the triangle around the y-axis
_glBegin _GL_TRIANGLES ' The beginning of drawing the PYRAMID
_glColor3f 1.0F, 0.0F, 0.0F ' Red color (it is as _glColor3f Red, Green, Blue and values can be calculated as 1 / 255)
_glVertex3f 0.0F, 1.0F, 0.0F ' Upper point
_glColor3f 0.0F, 1.0F, 0.0F ' Green color
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point
_glColor3f 1.0F, 0.0F, 0.0F ' red color
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (right wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F 'left point (right wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' right point (right wall) '
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (rear wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' left point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'right point (rear wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (back wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'left point (left wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f -1.0F, -1.0F, 1.0F ' right point (left wall)
_glEnd 'triangle draw end
_glTranslatef 3.0F, 0.0F, 0.0F 'we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a quad
'FOR THE ENTIRE OBJECT IN ONE COLOR:
_glLoadIdentity ' we call it to align the X Y Z axes to the original direction, without it it would default to the previous rotated state
_glTranslatef 1.5F, 0.0F, -7.0F ' The displacement of the origin is higher than in a quad
_glRotatef rquad, 1.0F, 1.0F, 1.0F 'Rotate the quad around the x-axis
_glBegin _GL_QUADS ' begin draw quad
_glColor3f 0.0F, 1.0F, 0.0F ' green color
_glVertex3f 1.0F, 1.0F, -1.0F ' left upper point
_glVertex3f -1.0F, 1.0F, -1.0F ' right upper point
_glVertex3f -1.0F, 1.0F, 1.0F ' right bottom point
_glVertex3f 1.0F, 1.0F, 1.0F ' left bottom point
_glColor3f 1.0F, 0.5F, 0.0F ' orange color
_glVertex3f 1.0F, -1.0F, 1.0F ' right upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (bottom wall)
_glVertex3f 1.0F, -1.0F, -1.0F ' right bottm point (bottom wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 1.0F, 1.0F, 1.0F ' right upper point (front wall)
_glVertex3f -1.0F, 1.0F, 1.0F ' Left upper point (front wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point (front wall)
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point (front wall)
_glColor3f 1.0F, 1.0F, 0.0F ' yellow
_glVertex3f 1.0F, -1.0F, -1.0F ' right upper point (rear wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left upper point (rear wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left bottom point (rear wall)
_glVertex3f 1.0F, 1.0F, -1.0F ' right bottom point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, 1.0F, 1.0F ' right upper point (left wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left upper point (left wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (left wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' right bottom point (left wall)
_glColor3f 1.0F, 0.0F, 1.0F ' purple
_glVertex3f 1.0F, 1.0F, -1.0F ' right upper point (right wall)
_glVertex3f 1.0F, 1.0F, 1.0F ' left upper point (right wall)
_glVertex3f 1.0F, -1.0F, 1.0F 'Left bottom point (right wall)
_glVertex3f 1.0F, -1.0F, -1.0F 'Right bottom point (right wall)
_glEnd 'quad draw end
rtri = rtri + 0.52F 'Incrementing the angle of rotation of the triangle
rquad = rquad - 0.515F 'Incrementing the angle of rotation of the quad
'it is important to RESET THE AXES so that they are rotated to the basic setting (otherwise the X axis can move to the Y axis) using _glLoadIdentity,
'and it is EXTREMELY IMPORTANT to always move in the scene to the beginning of the scene using _glTranslateF
'moving the object in openGL is not done by recalculating _glVertex, but by moving the start of rendering using _glTranslatef
End Sub