Skip to main content

Posts

(X) Writing in the screen: draw string, locate & print

How everybody! In this entry we will see how to write in the screen, to know for exemple how to show things like information or our score. Take a look at this code: We have already seen drwa string but l et me explain the new keyword used: locate  to drive the cursor used by print to the desired position in the screen. print to print a value in the screen. When we execute this code we can see this: locate and print works together and understand the screen like tiles of 8x8 pixels where there's only place for a character (1,2,3,...,a,b,c,d,e,...,!"·$%&/..., etc) in each tile, starting at 1,1 position whre the fist number is the value of the row and the second value the column that's why the second message appears at the second row and starts at the fist column. The colors used are the default (black/white) or the one's selected by the color instruction that we talk about in the past entry. This is e nough by now, i
Recent posts

(IX) Colors: depth, color & rgb

Helo everybody! In this entry we will see how to work with colors . We will use the already known screenres instruction to define a depth color of 4 bits per pixel (4 bpp) to have 2^4=16 colors labeled from 0 to 15. Color 0 is black and also works as transparent in 4bpp. Take a look at this code: Let me explain the new keyword used: color  to change foreground and background colors. Must be followed with a cls to submit the changes. When we execute this code we can see foreground and background colors changing with every step of the loop through all its possible values. This is one of this: If we want to define 24 bpp depth we can use the instruction rgb to generate the color value. rgb means red, green & blue components and we can use numbers from 0 to 255 to indicate the amount of each color this way: rgb(0,0,0) for black rgb (255,255,255) for white rgb(255,0,0) for all red rgb(0,255,0) for all green rgb(0,0,255) for all blue rgb(255

(VIII) Collisions and strings: dim as string & draw string

G'day everybody! In this entry we will see the collisions, and we will use a concret one wich is the perfect superposition between two elements, as it used for pac-man and the ghosts. We have a perfect superposition when te coordinates of two elements are the same, same value for x axis and same value for y axis. Take a look at the new code of the day: Let me explain the new keywords used: dim as string  to declare a new variable that will contain an string, an string is delimited with an initial " and a final ". draw string  to draw a string on the screen at the point indicated. The sintaxis is draw string (x,y),string in our case draw string (0,h/2),message When we execute this code we can move the white square toward the other ones and the message in the screen will remember the color with which square the last collision occurs. Today's code and concepts are very important because we have an square with controlled interacti

(VII) Movement: arrow keys, and, +=, -=, variable coordinates

Howdy everybody! Take a look at the new code of the day: In this code we have defined new keyboard scan codes for the arrow keys, see it in the DECLARATIONS as constants and declare variables to control if the keys are pressed or not, like we did it with key escape. Here x and y that are the coordinates of the white square will turn into variables because we will move this square then the value of the coordinates will be variable. When we DO UPDATE this time we will check also the four possible arrow keys and checking not to go with our white square outside our screen, otherwise the square will hide, you can prove it. Notice that the condition is multiple, using and to check that both conditions are true at the same time to change the value of the corresponding variable. We increment or decrement x or y with 1 (1 pixel), to go up y-1, right x+1, down y+1 or left x-1. This way: To increment we use the form variable+=amount of increment, for exemple x+=1 To de

(VI) Frame control & locking the screen while drawing: screensync, cls, screenlock, screenunlock

Hiya everybody! Take a look at the code of the day: Let me explain the new keywords used: screensync  is the key to take the number of frames per second under control because this instruction waits until next refresh of the screen, usually 60 times per second known as 60 fps. After this we will draw our screen. cls  to CLear the Screen and draw from zero the new state of the game. screenlock  to lock the screen to hide it while we are drawing. screenunlock  to unlock the screen to show the new drawed screen. Is very important to respect that we have to draw inmediately after the screensync and remember that between screenlock and screenunlock you have to draw, nothing else to do this part of the code as fast as possible. How is the structure? more and more accurate every time: DESCRIPTION DECLARATIONS INITIALIZATIONS GAME LOOP INPUT DO UPDATE DRAW screensync screenlock cls ... screenunlock FREE UP CPU TIME sleep 1,1 ENDING This is e n

(V) Game loop, variables, dim as boolean, if then else, multikey, false, true, do loop until

Hey everybody! Take a look at the code of the day: The result of execute our new code will be the same as the obtained with the code of the last entry but you must press Esc key to exit: An screen to play with 400 pixels of width and 300 pixels of height and four squares of 32x32 pixels one in each corner. The white square is painted or filled with same color. The screen is being draw again and again and again until you press Esc key. Let me explain the new keywords used: dim as boolean  as const as but with dim we are telling that the label (in our case finish and kescape) will have a variable value. In the case of boolean this value can be false or true. do loop until to make a loop that will repeat the code inside the instruction until the condition after until is resolve to true. if then else  to execute the code inside the instruction if the condition is resolve to true, else to execute an alternate code if the condition is  not resolve to true. multikey t

(IV) Draw some colored squares: line -step

Hello everybody! Let's enrich our first code drawing four colored squares. This is the result of our new code: An screen to play with 400 pixels of width and 300 pixels of height and four squares of 32x32 pixels one in each corner. The white square is painted or filled with same color. Let me explain the new keywords used: line  to draw a line between a point referenced with its coordinates (value in axis x,value in axis y) and an increment/decrement in pixels form this point -step(inc/dec in axis x,inc/dec in axis y) and two parameters separated by comma, the first is the color and the second is optional, if you used it you can put a b that means box or bf that means box filled. Try changing color values from 0 (black or transparent) to 15 (white) and experiment with the parameters. This is e nough by now, in t he next entry we will make great advance learning a change in the structure of the code because the famous game loop. Contact me for any question,