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

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

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

(III) Make an screen to play: ', const as integer, screenres, sleep & end

Come on everybody! Let's see our first code to make an screen to play. Let me explain the keywords used: '   t o add comments to the code, very useful to understand even the code made by ourselves. Used alone in a row or at the end of an instruction. const as integer to declare labels as integer numbers that contain constant values, non modifiable along the program. In this case w and h are constants. We must separate different consts with comma. screenres to do an screen to play, we have to tell two parameters the width and the height of the screen. We must separate parameters with comma. sleep to wait until a key is pressed to see the screen that otherwise will close too fast. end to end the program.  And the structure of this code not too far from the structure of a larger one: DESCRIPTION DECLARATIONS INITIALIZATIONS Main code ENDING In FBIde you can run the code pressing function key F5 or clicking Quick run icon This is the result of our ...