Statistics | We have 1675 registered users The newest registered user is dejo123
Our users have posted a total of 30851 messages in 1411 subjects
|
Who is online? | In total there are 31 users online :: 0 Registered, 0 Hidden and 31 Guests None Most users ever online was 443 on Sun Mar 17, 2013 5:41 pm |
Latest topics | » THIS FORUM IS NOW OBSOLETE by NickTheNick Sat Sep 26, 2015 10:26 pm
» To all the people who come here looking for thrive. by NickTheNick Sat Sep 26, 2015 10:22 pm
» Build Error Code::Blocks / CMake by crovea Tue Jul 28, 2015 5:28 pm
» Hello! I can translate in japanese by tjwhale Thu Jul 02, 2015 7:23 pm
» On Leave (Offline thread) by NickTheNick Wed Jul 01, 2015 12:20 am
» Devblog #14: A Brave New Forum by NickTheNick Mon Jun 29, 2015 4:49 am
» Application for Programmer by crovea Fri Jun 26, 2015 11:14 am
» Re-Reapplication by The Creator Thu Jun 25, 2015 10:57 pm
» Application (programming) by crovea Tue Jun 23, 2015 8:00 am
» Achieving Sapience by MitochondriaBox Sun Jun 21, 2015 7:03 pm
» Microbe Stage GDD by tjwhale Sat Jun 20, 2015 3:44 pm
» Application for Programmer/ Theorist by tjwhale Wed Jun 17, 2015 9:56 am
» Application for a 3D Modeler. by Kaiju4u Wed Jun 10, 2015 11:16 am
» Presentation by Othithu Tue Jun 02, 2015 10:38 am
» Application of Sorts by crovea Sun May 31, 2015 5:06 pm
» want to contribute by Renzope Sun May 31, 2015 12:58 pm
» Music List Thread (Post New Themes Here) by Oliveriver Thu May 28, 2015 1:06 pm
» Application: English-Spanish translator by Renzope Tue May 26, 2015 1:53 pm
» Want to be promoter or project manager by TheBudderBros Sun May 24, 2015 9:00 pm
» A new round of Forum Revamps! by Oliveriver Wed May 20, 2015 11:32 am
|
|
| On-Forum Tutorial series: Coding | |
|
+3The Uteen Brennus jaws2blood 7 posters | Author | Message |
---|
jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: On-Forum Tutorial series: Coding Wed Jul 25, 2012 11:36 pm | |
| An on-forum tutorial series for coding, because I have very little time to dedicate my c++ experience to thrive in a major way (OpenGL implementation, SDL fiddling with, OOP, etc, etc) Therefore, i am hoping that an on-forum tutorial series will spark interest in at least basic programming. For now we'll focus on c++ (it's not so bad once you get into it) Lesson1: C++ is a computer language which simplifies hardcore programming (01110100 01001000 01001001 01010011) In order to use c++, you must either use a compiler, or some kind of command line type of interface (what is there when you don't have an operating system) I, for the sake of your mental health, recommend using a compiler. Several compilers I know of, which are used often, are - Microsoft Visual Studio (express version is free), Code Blocks (totally free), and MinGW (minimalist GNU for windows) Once you have downloaded your preferred compiler, please read it's documentation and make sure you try to recognize anything that may set it apart. For this series, I will be using Visual Studio. The first thing you want to do is set up a new project, and if you're using VS, select Win32 console application, name your project, and press ok. Now for actual coding, in your shiny new project, you will start by first setting up a main function. It should look like: - Code:
-
int main() { return 0; } This function(yes, basically what the name states, a function) acts like a starting point, it defines the entry point for the application. It is invaluable in coding and should always be in every program you compile. The int you see means integer, or whole number. It is the type of the function, other function types include float (decimal number), char (a character, like a letter) and void(no return) we will go in more detail with void and stuff at a later date. The return you see is what tells the function to go back wherever it came from(another function, a variable, or in this case nothing) the number is what it takes back with it. As for the { }, they represent start and finish of the function. So think of boundaries. Now that we learned about that, let's make your computer do something magical and wonderful, we're going to make it say Hello :tongue:. First, we must add something to our program so that we can make use of this black magic. This something is, <iostream>(again, we'll discuss this in detail at a later date) to make use of <iostream> we will have to include it by putting #include <iostream> into our code. Another thing we'll need is using namespace std;(for right now this is just magical) Note: #include goes above all, and then using namespace std; comes next, always. so now we have: - Code:
-
#include <iostream>
using namespace std; int main() { cout << "hello"; return 0; } Now that we have, TEH POWUH, we will say hello. To do this, type cout << "Hello"; in your function. As you can probably imagine, anything typed between in the " " part will come up on your screen, ANYTHING, it's TEH POWUH! Also, cout means ComputerOutput. So now: - Code:
-
#include <iostream>
using namespace std; int main() { cout << "hello"; return 0; } now if you run this program (in VS, it's the green arrow next to the word "Debug"). Absolutely nothing happens :cry:. Well this is because your computer did this program really fast and closed right up pretty much as soon as it opened. To stop this, we have to make the computer unable to finish unless you type something. To make use of this fun fun, we use cout's evil twin brother, cin(ComputerInput). So back to the code, in order to make the computer wait for you and use cin, we will put cin.get(); right above return. cin.get(). will proceed no matter what you press. so here's our code now: - Code:
-
#include <iostream>
using namespace std; int main() { cout << "hello"; cin.get(); return 0; } And woopty Belgiuming doo, your computer says hello until you press something on your keyboard :D. One final thing, if you are using VS, you must also have #include "stdafx.h" in your code. Next lesson we'll learn about more, so stay tuned for more mind boggling ,amazing, spectacular, awesomeness. Only on, the Thrive forums! please post all questions below. If you read none of this, stare at the pickle of shame, STARE AT IT. You lazy Belgium waffle. | |
| | | Brennus Newcomer
Posts : 67 Reputation : 0 Join date : 2012-07-04 Age : 27 Location : Canada
| Subject: Re: On-Forum Tutorial series: Coding Thu Jul 26, 2012 12:25 am | |
| This is really useful, thanks for posting. Please do more. | |
| | | The Uteen Sandbox Team Lead
Posts : 1476 Reputation : 70 Join date : 2010-07-06 Age : 28 Location : England, Virgo Supercluster
| Subject: Re: On-Forum Tutorial series: Coding Thu Jul 26, 2012 12:27 pm | |
| | |
| | | ~sciocont Overall Team Lead
Posts : 3406 Reputation : 138 Join date : 2010-07-06
| Subject: Re: On-Forum Tutorial series: Coding Thu Jul 26, 2012 3:56 pm | |
| I may make a an attempt at this soon. | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Fri Jul 27, 2012 4:58 pm | |
| Lesson 2: Now that you know about the int main() function, it is time to go over other functions(a set of statements), variables, and statements(instructions). In C++ there are over 140 predefined functions already available for use. However, in the development of Thrive, it would be likely that you would often times have to make your own functions. To make a function, you must first make a prototype for that function at the top of your source code under the #include stuff, and above your int main() function. A prototype outlines what type the function will be, the name, and the argument(info in parentheses which can be used) of the function. It looks like the following: - Code:
-
void GiveMeMySandwich(void); The first word you see (void, a data type) is the function type, the second word(s) is the name(no spaces allowed), and in the parentheses is the argument. Data types(like void) define what kind of function a function is,and what it returns, or what value is possessed in a variable or argument. here are the major types: void - Valueless(nothing). with this as your function type, your function returns nothing to the function that called(used) it, therefore the return(); statement(a line in code in a function) is not used. int - an integer, or whole number, as a function type an integer is returned. there are sub-types for int, but we won't discuss them right now bool - a Boolean, basically true or false. As a function type, true or false is returned. float - a decimal number, you can return decimals. double - what are often called "real numbers", double allows for a decimal or whole number to be used. As a function type a decimal or a whole number can be returned is returned. char - a character (letters and stuff) as a function type, a character is returned. So now that we know all that, let's make ourselves a function, first, make sure you're typing outside of(more specifically below) the int main() function. Next put the function type you put in the prototype(in our case, void.) The name(i put GiveMeMySandwich) and an argument( two empty parentheses because our argument is void). After that, put an opening bracket ( { ) and on the next line a closing bracket ( } ) so now our code looks like: - Code:
-
#include <iostream>
using namespace std; void GiveMeMySandwich(void);
int main() { cout << "hello. "; cin.get(); return 0; }
void GiveMeMySandwich() { } As of right now, our function does nothing. In order to make our function do stuff, we must fill it with statements(instructions), and then have our main function call(use) it. A statement you already know is cout <<, so let's use that: - Code:
-
void GetMeMySandwich() { cout << "You now have a sandwich."; } NOTE: you must use ; at the end of every statement to signal to the computer you are done with that instruction.Now to tell main to use the GetMeMySandwich function. To do this, you type the function name, and give it an argument(if it can use arguments, our function doesn't) and type it out as a statement in main. So let's see our code now: - Code:
-
#include <iostream>
using namespace std; void GetMeMySandwich(void); int main() { cout << "hello. " GetMeMySandwich(); cin.get() return 0; }
void GetMeMySandwich() { cout << "You now have a sandwich."; } Alright, looking good so far. In case you're wondering cout << endl; is how you make the next statement come up on the next line(it's like telling your computer to press enter.) Now for my last part of today's lesson, variables. A variable is a letter, or word which holds certain information depending on it's Data type (i covered that earlier). you construct a variable with, a data type, the name, an = operator, and a value relevant to the data type. So a variable would look like: - Code:
-
int number = 3; NOTE:you can always just make a variable(no = 3 or whatever), and assign it something whenever you want in the shown way.variables can be used pretty much like a specialized container. For example, if you have a container for trading cards, you cant stick baseballs in that container, just trading cards. to define what kind of container you're using, you use the previously mentioned data types. In our above case we said we wanted to store integers, so integers(whole numbers) like 3 are all that can be stored in our variable. To give you a sense of one of the ways we can use variables, lets make our program have main give GiveMeMySandwich a number and display it. first, we must change the prototype and actual function to accompany integers. so now our prototype is: - Code:
-
void GiveMeMySandwich(int); as you may tell, we will be using arguments to carry out this process. Now remember that statement in main where we called our custom function? well, now we must give it a value in its argument part. So let's put something like 7 in there: - Code:
-
int main() { cout << "hello."; GiveMeMySandwich(7); cin.get(); return 0; } Since that's all done, we're going start making our actual function now. Go to your custom function, and in the argument make your variable by putting something like int number in the following way: - Code:
-
void GetMeMySandwich(int number) now to display our number by adding another cout statement: - Code:
-
void GetMeMySandwich(int number) { cout << "You now have a sandwich"; cout <<"here is a number for no reason" << number; } Our final source code: - Code:
-
#include <iostream>
using namespace std;
void GetMeMySandwich(int); int main() { cout << "hello. "; GetMeMySandwich(7); cin.get(); return 0; }
void GetMeMySandwich(int number) { cout << "You now have a sandwich"; cout << endl; cout << "Here is a number for no reason: " << number; } And WooHoo! your own function and variable. Stick around for the next lesson, because i'll be talking about something every video-game uses/needs, OOP(not POOP). Too long? Didn't read? PICKLE OF SHAME!:
Last edited by jaws2blood on Wed Aug 15, 2012 2:34 pm; edited 1 time in total | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Sat Jul 28, 2012 10:56 pm | |
| Attention, lesson 3 might be a little delayed due to a busy schedule. | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Mon Jul 30, 2012 6:28 pm | |
| Lesson 3: Today we're going to learn about OOP(Object Oriented Programming). OOP is vital for video games, why? Because, it organizes all those different components in your video game in a nice, clean way. OOP does this through the use of classes(a collection of variables and things), and then objects(uses a class to define it's properties.) Here's an example of a class: - Code:
-
class gun { }; The class has nothing in it right now, but what you see is the basic structure of a class. As you may notice, the structure of it is really simple. we type the keyword class(to tell the computer we want to make a class) and then the name of the class, followed by brackets( { } ) to put our stuff in, then a semi-colon to say, we are finished making a class. Quite often(all the time), you're supposed to put your classes into a relevant header file. A header file ( .h ) is not to be confused with a source file ( .cpp, has functions in it ). I will go into further detail with header files some other day. So with our class we can outline the properties of different objects we create in the world, for example, with the gun class i would identify RateOfFire, Damage, and Range(real games have way more than just that): - Code:
-
class gun { int RoF; int Dam; int Range; }; Another thing that goes into classes is the methods(functions done by an object belonging to the class). So for gun, we would have things like void shoot() or something. Thing about methods is you don't code these special functions in the class, rather you code them outside of the class. Next thing to know is you can make stuff in your class public and private. Public and private will be covered next lesson so disregard it for now. As for giving the variables we made values, we can allow objects to do that through methods and functions. We do this by first making a method in our class to set a certain variable's value, then a method to get the value. So you end up with something like this: - Code:
-
class gun { private: int RoF; int Dam; int Range; public: void SetRoF(int rof); int GetRoF(); void SetDam(int dam); int GetDam(); void SetRange(int range); int GetRange(); }; Next, we're going to make special functions that will allow us to use the methods. We do this with the Scope Resolution Operator( :: ). When you use :: , you give the function a type, then you put the name of the class you wish to mess with, :: , and then the method. Like any other function, it must also have the brackets ( { } ). next, we will make statements that allow us to do what we want the method to do. so for setting say, RoF, we may try something like this: - Code:
-
void gun::SetRof(int rof) { RoF=rof; } and for GetRoF, this: - Code:
-
int gun::GetRoF() { return RoF; } We are making the get function have int as it's value because, we will be returning the value of RoF(an integer) to the function that wants to know it. Now let's do the things shown above with all the other methods. - Code:
-
void gun::SetRoF(int rof) { RoF=rof; }
int gun::GetRoF() { return RoF; }
void gun::SetDam(int dam) { Dam=dam; }
int gun::GetDam() { return Dam; }
void gun::SetRange(int range) { Range=range; }
int gun::GetRange() { return Range; } in order to make use of the "set" functions i made here as soon as i make an object, we'll use a constructor(method that runs when you create an object) to tell objects to use certain methods as soon as the object is made. We'll do this through arguments so what we will do is make variables that our code can mess with. So, for RoF, i could do rof, for Dam, i could do dam, and for Range, i could do range. So in our constructor's (which is made by simply typing the name of the class, and parentheses for the arguments btw) arguments we would type int rof, int dam, int range. Then we will identify what the method does with a :: function. for the statements, we copy all the statements from the sources we need( SetRoF, SetDam, and SetRange) and jam them into our constructor's statements. So our constructor function looks like: - Code:
-
gun::gun(int rof, int dam, int range) { RoF=rof; Dam=dam; Range=range; } Now for the other thing you do besides make classes in OOP, make objects. Making objects is simple enough, you simply state the class, then state the name of the object, and then any arguments. So let's say i want to make an ak47 in my game. What i would do is somewhere along the lines I would type: - Code:
-
gun ak47(600, 33, 300); Through that statement I would create an object that is named ak47, which is a member of the gun class. The numbers in the arguments for ak47 are RoF(600) Dam(33) and Range(300). Now i know you're probably wanting something you can do with this, well, let's make program. We could make a program that tells people information about the ak47. To do this, we will need cout <<. Here's where i want to explain something, notice how the whole lesson i didn't mention #include <iostream> or using namespace std like in previous lessons? Well, that's because I don't need them unless I want something to do with input or output(the io in iostream) And i can make the inclusion of things from namespace std as painless to the program as possible by specifying what I want, where I want it. How? simple, we take what we want from the std namespace using :: . Instead of the class being on the left, and some method on the right, we'll have the namespace (std) we want to use on the left, and on the right we'll have what we want( like cout ). we can then put our std::cout or whatever in the function where we want to use it in as a statement. After we have put std::cout in the function, we then do this to output certain characteristics of the ak47 object: - Code:
-
std::cout <<" The ak47's rate of fire is: "<< ak47.GetRoF() << endl <<" with an effective range of: " << ak47.GetRange() << "meters"; And huzzah! We're done. You can obviously screw around with this stuff and make say, a class for certain animal parts, then objects belonging to that class of animal parts. or something else Thrive related. Stick around, and you'll learn more and more, and the possibilities will never stop expanding! If you broke my heart and didn't read this, pickle. OF SHAME!
Last edited by jaws2blood on Tue Jul 31, 2012 5:53 pm; edited 1 time in total | |
| | | Brennus Newcomer
Posts : 67 Reputation : 0 Join date : 2012-07-04 Age : 27 Location : Canada
| Subject: Re: On-Forum Tutorial series: Coding Tue Jul 31, 2012 1:37 pm | |
| Once again, this has been useful, thanks! | |
| | | nziswat Newcomer
Posts : 40 Reputation : 1 Join date : 2012-06-29
| Subject: Re: On-Forum Tutorial series: Coding Tue Jul 31, 2012 9:58 pm | |
| This is kinda relevant but are you planning on becoming a coder for this game?
| |
| | | Brennus Newcomer
Posts : 67 Reputation : 0 Join date : 2012-07-04 Age : 27 Location : Canada
| Subject: Re: On-Forum Tutorial series: Coding Wed Aug 01, 2012 12:44 pm | |
| Me? I'll be learning C++ for a while, and I'll contribute some code here and there when I can. I may be able to contribute a lot, I may not be able to contribute much at all (such is life), but I will be contributing code. | |
| | | nziswat Newcomer
Posts : 40 Reputation : 1 Join date : 2012-06-29
| Subject: Re: On-Forum Tutorial series: Coding Wed Aug 01, 2012 10:01 pm | |
| - Brennus wrote:
- Me? I'll be learning C++ for a while, and I'll contribute some code here and there when I can. I may be able to contribute a lot, I may not be able to contribute much at all (such is life), but I will be contributing code.
well both of you guys really. | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Sat Aug 04, 2012 8:43 pm | |
| I'll help a little bit here and there but, I can't code the whole game, or allot. I don't really know if thrive is ready for code yet tbh, there's still basic code stuff to think about and design. As for people who want to learn, lesson 4 is coming soon, so stay strong. | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Sat Aug 04, 2012 8:48 pm | |
| - Brennus wrote:
- Me? I'll be learning C++ for a while, and I'll contribute some code here and there when I can. I may be able to contribute a lot, I may not be able to contribute much at all (such is life), but I will be contributing code.
How much you contribute will come down to how much time you have, and whether you're a math guy or not. | |
| | | The Uteen Sandbox Team Lead
Posts : 1476 Reputation : 70 Join date : 2010-07-06 Age : 28 Location : England, Virgo Supercluster
| Subject: Re: On-Forum Tutorial series: Coding Sun Aug 05, 2012 6:16 am | |
| Good job, two more already. Seems to make sense, although I'm a bit confused on why double is a boolean. | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Wed Aug 15, 2012 2:31 pm | |
| - The Uteen wrote:
- Good job, two more already. Seems to make sense, although I'm a bit confused on why double is a boolean.
Oh my, sorry about that, typo, double can return decimals or whole numbers. | |
| | | ido66667 Regular
Posts : 366 Reputation : 5 Join date : 2011-05-14 Age : 110 Location : Space - Time
| Subject: Re: On-Forum Tutorial series: Coding Wed Aug 15, 2012 10:37 pm | |
| TL;DR
I am a hoples case, Aye? | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Thu Aug 16, 2012 11:42 am | |
| - ido66667 wrote:
- TL;DR
I am a hoples case, Aye? ಠ_ಠ | |
| | | jaws2blood Newcomer
Posts : 62 Reputation : 3 Join date : 2011-12-18 Location : USA
| Subject: Re: On-Forum Tutorial series: Coding Thu Aug 16, 2012 2:19 pm | |
| Lesson 3 reference:
In lesson 3, i made use of public: and private: When you have things under public, it can be used and changed anywhere in your code. But with private, things under that can't be used and changed as easily unless you use certain methods(shown in lesson 3). Quite often you'll have different variables like health and stuff under private. And public would have the methods to set and show the values of the private variables.
lesson 4 should be coming out today. | |
| | | Carnifex Newcomer
Posts : 37 Reputation : 8 Join date : 2012-08-13
| Subject: Re: On-Forum Tutorial series: Coding Fri Aug 17, 2012 4:28 am | |
| Appreciate the tutorials. I don't require them but they seem to be very easy and clear for people who are thinking of picking up programming. | |
| | | Sponsored content
| Subject: Re: On-Forum Tutorial series: Coding | |
| |
| | | | On-Forum Tutorial series: Coding | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |