Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / [Tutorial] Creating Your First RPG

Author
Message
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 20th Mar 2007 11:08 Edited at: 21st Mar 2007 09:11
Creating Your First RPG Tutorial

This tutorial is made for DarkBASIC Professional and may not work in DarkBASIC Classic.

In This tutorial I hope to cover various aspects of creating an RPG.

= Complete
= Coming Later

Setting Variables
Setting Types
Creating Arrays
Creating Functions
Creating a Game Menu
Creating my First 3D object
Making my object move
Creating The 3D World....

And once this list is done i may continue to add to this tutorial hopefully

Part I: Setting Variables

Open up DBpro click File>New Project name it RPG, once you have done that carry on.

Almost EVERY game needs to set variables. They are good for RPG’s to be the stats, FPS’s for Ammo etc and a lot more.

For our stats we’ll start with setting simply the Health Points, the Magic Points and the Power.



This will set our variables to 100, 100 and 10. But what if we want to use decimals in a variable? We set it to a float variable. The most common way is like this, using a # to make it a float.


But what if you just want to type HealthPoints instead of HealthPoints# every time you want to use the health? Easy! Just set it to a float at the start and the variable type is a float.



What if we wanted to make the variable store words? We make it a string
First way, use a $ at the end second way use as string at the end


Or



Now what if we want to display the amount of the variable on screen? We use the print command.



But that just doesn’t work! So we use the command Suspend for key so that the program waits for you to press a key before it ends.



Now we want to print HealthPoints so we use



What if we want to have it display Health Points: 100.50910 then we have to use a sring and a float. Either we use a variable to store Health Points: or we simply write it.



That didn’t exactly work. Because the variable HealthPoints is after a string and it is not a string itself we need to put it inside a str$() so it reads the number as a string



Using decimals for Stats is kind of strange in my opinion so lets change to using integers (Numbers Without Decimals) two ways



Or



Well that’s about it for variables your code should show



Hope you enjoyed part one 

Part II: Creating Types

Creating types in DBpro can be very useful for things. For example if we wanted the player to have Health, Magic Points, Stamina and Power then we could make a type for this. To create a type we need to define a name like so



So we have created a type. Now we need to store some variables in this type so we will setup the stats I mentioned above as integers, which means they will be numbers, with no decimals.



You will notice that I have added Endtype to the end of the code so that it closes the type and doesn’t store anything else inside the type.

With this type we can re-use the health variable because it is only part of this type. For example we could have our player type as above, and then copy and paste that type and rename it Enemy, then you will have two different variables.

Now to show you how to assign this type to a name. To do this we use this.



Now we can use the Health variable and all the other variables like so



This is exactly the same as variable usage except our variables are a bit different
Well that’s all for Types.

Part III: Arrays

Arrays are another useful way to store variables. A use in an RPG would be to use it for a monster spawn.

To create an array first we use Dim to open the array, and then assign a name, followed by the number of pockets in the array.



So say we used this as an array for 5 spawns. This array could store data for 5 monster spawns with 10 monsters in each spawn. So lets start by creating a monster called Fire Bird in spawn 1. Also we will add some other monsters. Lets Create spawn 1 now.



This will create an array with 10 monsters all in spawn 1 named as shown above. This can be useful in some areas, however we will get to that later.

That’s all for Arrays.

Part IV: Creating Functions

First of all click on the Files tab in the DBpro Editor then click Add New then call it functions.dba then carry on

Function is a command that lets us make our own commands. We can make a function to set all our variables for us. Lets do that! We use Function then the functions name we will use Set_Variables() the () on the end means there are no parameters. If there were parameters there would be something between ( and ) then we insert the code that we want the function to use underneath the first line and once that’s there we close it with Endfunction so lets make the lesson from part one into a command.



But now if we want to use the variables HealthPoints and all the other ones outside of the function we can’t because its local to the variable. To fix that we make it a global variable which means you can use it throughout the code because its global to the whole code.



Not to difficult? We will put our functions in Functions.dba and our Main code in RPG.dba. Now to use it we put Set_Variables() at the top of the page your code should be:



Hold up! When we press a key there is an error saying “You Have hit a FUNCTION declaration in mid-program!” so we make it end the program before it gets there.



You will notice that after Suspend for key I have put End which ends the program. Well before after Suspend for key it was carrying on but there was no code so it ended but this time it carried on to the Function which hits an error. Now when it carries on it will hit the End Command and end the program.

Functions are a good way to organise code nicely. Instead of a whole list of coding it just has a couple of function names as the code and the rest at the bottom which can fold up.

We will be using functions in the rest of the tutorial so make sure you understand them before you continue.

Well that’s the end of part two your code in RPG.dba should be:



And in Functions.dba should be:



Hope it helps

Part V: Creating a Game Menu

In this part we will be using a Function to create a menu to start our game. We will create it using a Function we will make called Make_Button(x1,y1,words$)

Lets start. Make a Function called Make_Button(x1,y1,words$) in functions.dba



To make a button we will use the command Box to create a box around the button and the command Text to create the words on the button



This function uses the parameters x1,y1 and words$ to get the position for the button and the writing to put on the button, then it sets x2 and y2 to those values which get the text width and text height of the buttons text and add 4 so it makes the button bigger than the text. Then it uses a box which is made with x1,y1,x1+x2 and y1+y2. x1+x2 will make the box bigger than the button likewise with y1+y2. Finally it uses the command text x1,y1,words$ to position a piece of text to x1,y1 and prints the variable words$.

Now to test our button we do this

In RPG.dba under set_variables() we put a loop which will keep repeating the commands inside the loop



This makes the button at position 200,200 with the text Start Game on it.

Now we want to do this, Check if the user clicks on the button, If so then go into the game.

For this we make a variable inside this function called Clicked, which will determine whether the button is clicked. To check if the button was clicked we use an If statement and the command Mouseclick() as well as a few other commands.

Ok so we need to create this now. Inside the function Make_Button() we will put this code



This will check if the mouse is in the button. If it is in the button and then you click it will set Clicked to 1. Also you will notice I have added Endfunction Clicked well this is because if an If statement is called then we want it to return the value of clicked.

So now we can tell when our button is clicked. Lets get the If statement that asks if the button is clicked, and then tell it to exit the loop and enter the main program loop.



You will notice that I added Cls just before the main loop. What this does is clears the screen of all the currently displayed 2D images. So when we click the button, it will clear the menu, and go into the main game loop.
Now when you click on a button it should go to a blank screen.
That is the end of this part your final code should show:



This is all we will need, we won’t need our other variables anymore so we will create our type up the top like so.

That’s the end of this part on creating your menu. If you want to add more buttons just use that same code except make the effect that they have a little different for example lets just add a Quit button for fun



So now when we click on the Quit Game button it ends the program. That’s the real end of this part.

Enjoy


RPG Engine Work in progress!
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 21st Mar 2007 03:57
Pretty cool so far!

Its very very very much like my rpg tutorial You go through most of the same steps.

-Mansoor
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 21st Mar 2007 06:42
yeah sorry Xeno if that offends you, it is going to go a bit further than yours possibly although i don't know and no im not challenging you.


RPG Engine Work in progress!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Mar 2007 08:34
I think if you have to explain arrays in detail to someone then I doubt they're ready to make an rpg.

Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 21st Mar 2007 09:10
it says creating your "First" RPG so it covers all that stuff to show them how to do it.


RPG Engine Work in progress!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Mar 2007 16:48
Not saying you should stop, not by any means, but I think an RPG is a much larger scale game than needed for a first time demonstration of using the above mentioned topics.

Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 21st Mar 2007 20:40
Yeah but this tutorial is made for people who just started and want to learn how to make a basic RPG...


RPG Engine Work in progress!
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 22nd Mar 2007 00:10
Its cool Kieran I didn't take any offense. I'm glad to see another rpg tutorial in the works since I stopped mine.

-Mansoor
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 22nd Mar 2007 21:01
ok good to hear Xeno


RPG Engine Work in progress!
steel gollum
17
Years of Service
User Offline
Joined: 30th Jan 2007
Location:
Posted: 28th Mar 2007 21:26
kieran you know the make_button function thingy, well i was wondering if ther is a way to make buttons pop up while playin the game like near a door to open it or close it? if so could you tell me it please.
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 5th Apr 2007 10:53
ummm yeah that can be accomplished using the make_button function, you need to call make_button when you are in a certain range of the door, for example say the door object is number 5 and player is number 1

make object collision box 5,100,100,100,100,100,100
if object collision(5,1)=1
make_button(1,1,"open/close door")
endif

something like that so when you get within an 100 unit radius of the door the button should display

this code is untested so im not sure whether it will work, if you cant figure it out i can help you further

Login to post a reply

Server time is: 2024-09-25 21:21:38
Your offset time is: 2024-09-25 21:21:38