Skip to main content

(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 interaction of its environment, here we have static squares to collide with but could be enemies both static or moving, solids like floor, walls, stairways, objects like power-ups, weapons, etc. and all this things working the same way. In this point begins to work your imagination to use all this powerfull knowledge.
This is enough by now, in the next entry we will talk about the colors.

Contact me for any question and tell me your feedback, see you!

Go to the next entry
Go to the previous entry
Go to the first entry

Comments

Popular posts from this blog

(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...

(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...

(II) Download & setup FreeBASIC's IDE FBIde

Hi everybody! If you use Microsoft Windows on your computer you can download FBIde from SourceForge in this link:  https://sourceforge.net/projects/fbide/files/ Go to fbide 0.4 folder and then fbide 0.4.6 r4  folder and download the zip file with the name  FBIde0.4.6r4.zip . Note: 0.4.6 r4 is the last version while doing this blog entry. Now decompress downloaded file in the path you desire. Me I decided to use my Desktop, beside my FreeBASIC compiler and help folders. Go into  FBIde0.4.6r4  folder and execute the application  fbide Click Yes in the message window. And search fbc application inside your FreeBASIC's compiler folder to open it. Go to View/Settings to Choose your Theme for the editor, I like obsidian theme. Add some new Keywords in Group 2 . Choose the path for FreeBASIC Help file (.chm) downloaded in the previous entry of this blog. Remember to click OK to submit the changes. This is e nough by now, i...