QBasic/Advanced Graphics
< QBasic
Animation
editBasic Movement
editAnimation is basically graphics that changes over a fixed period of time. In this we will be using a do-loop .
SCREEN 7 ' we need to use a graphics enabled screen mode
animation 'calling the sub
SUB animation
SCREEN 7
x = 10 'set first x- coordinate
y = 10 'set first y-coordinate
DO
CLS ' going back to a blank screen so that the previous rectangle is erased
x = x + 3 ' setting increment of coordinate x
y = y + 3 ' setting increment of coordinate y
LINE (x, y)-(x + 5, y) 'drawing lines
LINE (x, y + 5)-(x + 5, y + 5)
LINE (x, y)-(x, y + 5)
LINE (x + 5, y)-(x + 5, y + 5)
SLEEP 2
LOOP UNTIL INKEY$ <> ""
END SUB
Explanation:
- We have switched from the default qbasic text-only screen to one which enables graphics.
- We have called the sub which creates the animation.
- We have begun the do-loop until. This enables the animation to run until the user ends it by pressing a key.
- We have set an increment of the coordinates. This allows the box to be drawn on a new position rather than the same one. If it movement in only one direction was wished, we had to set the increment only in one variable.
- We have drawn lines from each coordinate to another. Note that each time one coordinate remains fixed while the others change.(In this I refer to the two coordinate sets, the first starting and the ending one)
- We have issued a sleep command . This stops execution for 2 seconds . Without this the do-loop will execute more quickly than we want , and the animation will be very short-lived.
- By using RND for the variables, you can create a randomized ,unpredictable animation.
Mouse-Control
editIn this step, we will use the QB64 inbuilt _mousehide,_mousex,_mousey,_mouseinput and _mousebutton commands to control the mouse input.
WARNING
editThese Functions only work in QB64!
_mousehide
screen 7
mousetrack
sub mousetrack
do while _mouseinput
cls
X = _mousex
Y = _mousey
LINE (X - 10, Y)-(X + 10, Y), 15
LINE (X, Y - 10)-(X, Y + 10), 15
IF _MOUSEBUTTON(1) THEN
IF X > A AND X < A + 25 AND Y > B AND Y < B + 25 THEN
message$ = "yes"
goto action
END IF
END IF
loop until inkey$ <> ""
- Here the first function "_mousehide" prevents the default pointer mouse format to be displayed on the screen
- Mouseinput function retrieves mouse information.
- The next functions "_mousex" and "_mousey" hold the current x and y coordinates of the mouse.
- The lines draw a basic trigger .
- The "_mousebutton" function returns the value of the mouse button pressed, "1" signifies the left button being pressed.
- If the mouse button event has taken place within a certain enclosed area, a message in the form of "message$" is issued. This can be used later on.
- The procedure, if the previous condition has been fulfilled , goes to line label "action" where any commands to be executed may lie.
- Else , the process loops , until a "loop until" condition has been met. It can also be something other than the one given above.
Usage
editThese graphics and animations can be used to create a complete game. Instead of the "Mouse" functions, you could use the "Inkey$" command to issue various scenarios and cases, each with a complete code to decide what happens next.
Tip
editInstead of making games which do not contain any user information, you could use ".txt" files to store information. This information can be later retrieved to make a game with a complete "Career" option.