Intro to Programming 2 by MikeS4th Mar 2004 16:41
|
---|
Summary Introduction to darkbasic(Pro) programming. Description Introduction to darkbasic(Pro) programming. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com ` This tutorial was created by Yellow -Mike- 3-4-04 ` Although not necessary, it would be nice to be credited and ` notified at yellow1dbp@hotmail.com if this was used in a game ` Thanks, and I hope the tutorial helps. `Dark Basic Professional Introductory Programming `This article is aimed towards newcomers or people who want to reinforce the basic `Principles of Basic programming `Welcome to programming `As you may have noticed the "`" mark has been used many times `This basically tells the compilier to ignore anything after that mark `This is helpful for putting in notes you, so you remember information in long lines of code. `Alternatvies to the ` mark are the statment "Rem". There are others, but don't worry `about them at this moment. `Now we begin `This tutorial is broken down into _ lessons `Please follow them 1 by 1 ` Lesson 1- Print command ` Lesson 2- Variables ` Lesson 3- Input ` Lesson 4- text ` Lesson 5- Creating objects ` Lesson 6- Manipulating objects ` Lesson 7- Creating a Matrix ` Lesson 8- Moving in the 3D world ` Lesson 9- Manipulating the matrix ` Lesson 10- Texturing a matrix `***********************KEEP IN MIND*********************************** `1.) It's possible there's mistakes, though I've tested all code `2.) The Help key is F1 after the statement, or visit help at the menu `3.) Expect headaches. `4.) Have Fun! `*********************************************************************** ``````````````````````````` `````````Lesson 1`````````` ``````````````````````````` do `This tells the program to do something print "hello world" `This tells the compilier to print the words following in parenthesis loop `The loop command constantly repeats this action `This should rapidly repeat Hello world, because we're telling the program to `Do(the action) print(the statement inside parentheses) and loop(continuly loop around and around). ``````````````````````````` `````````Lesson 2`````````` ``````````````````````````` A=1 `This assigns A to 1. So whenever we use A in certain commands, the value returns 1. do print A loop `This should repeatedly repeat 1. This is because A is equal to 1. ``````````````````````````` `````````Lesson 3`````````` ``````````````````````````` do input "What is your name?",name$ `The input command tells the program to ask the user for information. `This input is then stored in a variable name, with the $. This represents `stored text information. This information can be stored with any value as long `as it ends with $. print name$ loop `This should repeateadly print whatever you type as your name. `We can also make things a little bit more advanced, by combinging a semicolon with `the parenthese. do input "What is your name?",name$ print "Hello ";name$ `the semi-colon works like a space between strings of commands. loop `This should repeadetly print, hello ____(whatever your name is) ``````````````````````````` `````````Lesson 4`````````` ``````````````````````````` `The text command is fairly versitile and can be used in many ways. do text 0,0,"This is a text" `The numbers define the x,y position of the text on the 2d screen. `The text inside the parenthesis tells what to display" loop `Text can also be combined with variables A#=2 `the # sign works in the same way as the $ sign, but holds numbers. do text 0,0,"Your number is "+str$(A#) `the str$ command is added to show a variable after the text. loop ``````````````````````````` `````````Lesson 5`````````` ``````````````````````````` make object cube 1,1 `This makes a cube with the unique number of 1, and size of 1. `You should never really have objects with the same numbers, for these numbers are unique. `They're later used to define what the object may do. do loop `You should see a cube on your screen. ``````````````````````````` `````````Lesson 6`````````` ``````````````````````````` make object cube 1,1 do rotate object 1,0,object angle y(1)+0.1,0 `This rotates the object 1, 0.1 degreesY everytime the loop hits this statement. loop `You should see a rotating cube(from left to right) spinning. ``````````````````````````` `````````Lesson 7`````````` ``````````````````````````` `Now we enter a more advanced subject `Matrices are easy ways of making worlds. They're basically tiles, that can be moved up `and down, and get textured. make matrix 1,100,100,10,10 `This makes matrix number 1,100 wide,100 long,10 x and z segments do loop `You should see a tile floor on your screen ``````````````````````````` `````````Lesson 8`````````` ``````````````````````````` `When moving in a 3D world, we'll want things to be constantly updated `Even in a 2D world, we still want to use this command. `This may be the most important command you learn. The sync command sync on `Turns the refreshing of a screen on sync rate 60 `Tells the screen to refresh at 60 Frames per second make matrix 1,100,100,10,10 do `The Controls (keep in mind, the default camera is 0, so it doesn't need to be in the statements) if upkey() then move camera 1 `This says that if the upkey is pressed, move the camera 1 forward if downkey() then move camera -1 `This says that if the down key is pressed, move the camera 1 backward if leftkey() then turn camera left 1 `etc. if rightkey() then turn camera right 1 `etc. if shiftkey() `This entire statement between the if and endif tells the camera to move up when shift is pressed. pitch camera up 90 move camera 1 pitch camera down 90 endIf if controlkey() `Works the same way as above, except control moves camera down pitch camera up 90 move camera -1 pitch camera down 90 endIf sync `refreshes the screen loop ``````````````````````````` `````````Lesson 9`````````` ``````````````````````````` `***Uses same source code from above*** sync on sync rate 60 make matrix 1,100,100,10,10 randomize matrix 1,5 `Randomizes the points on a matrix between 1 and 5 update matrix 1 `updates the matrix to changes do if upkey() then move camera 1 if downkey() then move camera -1 if leftkey() then turn camera left 1 if rightkey() then turn camera right 1 if shiftkey() pitch camera up 90 move camera 1 pitch camera down 90 endIf if controlkey() pitch camera up 90 move camera -1 pitch camera down 90 endIf sync loop ``````````````````````````` `````````Lesson 10````````` ``````````````````````````` `Same source as above sync on sync rate 60 make matrix 1,100,100,10,10 randomize matrix 1,5 update matrix 1 load image "PICK ANY IMAGE YOU WANT TO LOAD THAT IS A VALID FORMAT(.jpg,.bmp,etc.",1 `This loads an image. Place the path of the image in the parenthesis after you've `loaded your desired image into the media menu.(a blue button at bottom right.Media/add/your picture) `Then assign your unique number prepare matrix texture 1,1,1,1 `This prepares matrix 1, to be textured by image 1, and the image `is cut into 1 by 1 pieces.(Can be split if desired, but not necessary ex. 4x4,3x3,etc.) update matrix 1 `We update the matrix once more, or we could have simply moved down the other `update matrix statement. do if upkey() then move camera 1 if downkey() then move camera -1 if leftkey() then turn camera left 1 if rightkey() then turn camera right 1 if shiftkey() pitch camera up 90 move camera 1 pitch camera down 90 endIf if controlkey() pitch camera up 90 move camera -1 pitch camera down 90 endIf sync loop ``````````````````````````` ```````````Finale`````````` ``````````````````````````` `Well, you've made it. Now you're ready to do some other cool stuff. |