Ω Verax's Programming Tutorials Ω

Ver el tema anterior Ver el tema siguiente Ir abajo

Ω Verax's Programming Tutorials Ω Empty Ω Verax's Programming Tutorials Ω

Mensaje  Verax Lun Ago 04, 2014 9:00 pm


Ω  SHADOW'S  PROGRAMMING  TUTORIALS  Ω

Hello everyone, and welcome to my programming tutorials!



General Information:
If you have any questions, or want to contact me, you can do so via The Discussion Thread.
Because of this, I have to ask you all not to post here, in order to keep this thread organized and tidy.

I won't add new tutorials too often here, mostly because the interest for them isn't really there. However, I do write here when I feel like it.

There will also be a Download Section, where you can download the tutorials as text files, in addition to the Source Code for what we will be programming.

I won't hand out any homework here. But, if you are to learn how to program, the best way to do it is to write programs. Therefore, I recommend you all to play around and write some programs. If you only read these tutorials, you will most likely forget most of it. If you don't have any ideas of what to code, feel free to check out some exercises form one of the links in the Resources Section.



News:
-


About Me:
My "name" is Verax, and I am from Norway. I am mostly self educated when it comes to computers and programming, and I study Photo & Video at school (at least on the paper). I have read many books on diverse topics through the time, and I work at the IT branch of a company. I am also part of a team as a game programmer, for the people who may wonder.


Schedule:
GAME PROGRAMMING:
1. Where Do We Start?
2. What is a Game?    
3. Game Loops            

R PROGRAMMING:
-



Downloads:
Game Programming #1
Game Programming #2
Game Programming #3
Game Programming #4



Resources:
C++ Exercises
Java Exercises
Graphics For Your Games




Thanks,
~Verax







Última edición por Verax el Lun Ene 19, 2015 3:48 pm, editado 6 veces
Verax

Verax

Messages : 1139
Data de inscrição : 27/06/2014

Volver arriba Ir abajo

Ω Verax's Programming Tutorials Ω Empty Re: Ω Verax's Programming Tutorials Ω

Mensaje  Verax Mar Ago 05, 2014 6:05 pm

GAME PROGRAMMING #1:

Hello everybody, and welcome to your very first tutorial in Game Programming!
Sit down, lean back in your chair, get some coffee and some music going through your earphones, and we will start.

Ω Verax's Programming Tutorials Ω Programming-and-code-13_www.FullHDWpp.com_
Game Programming.

So, you want to create games, but have no idea where to start. No worries, though!


WHAT PROGRAMMING LANGUAGE TO USE?
Many beginners often ask the question of "What language should I use?".
This isn't really easy to answer, as it really depends on if you are a beginner or a professional. You see, there are some languages that does the job better than other languages when it comes to programming games. C++ is the industry standard when it comes to huge blockbuster-games like Assassins Creed 4 and Watch_Dogs. Because of this, you may believe that you should learn C++ and use that.

The answer however, is that you should use the language you are most comfortable with. Java for example, is an unpopular choice, because it's considered as a "slow" language. However, if you actually know how to program with Java and have no idea how to program with C++, the split seconds efficient C++ code saves will work against you. You see, efficient code is important, as it is THE factor when it comes to speed and quality. So, go with the language you are comfortable with.

When you have decided what language to go with, make sure you learn it if you haven't already.
(Note!   These tutorials is for game programming, not x language programming, so please know your language well.)


WHAT ABOUT ENGINES?
Engines are the sirens song of game programmers. They are very attractive, but won't actually make you a better game programmer if you are a beginner. My advice is to stay away from them until you at least know how to perfectly use BSP Trees in 3D Game Programming. (In other words, stay away from them for now).

Ω Verax's Programming Tutorials Ω Unity
It's a trap!

If you are in the situation where you want to create a prototype fast, to see if it actually was a good concept, engines like Unity3D, Game Maker and Unreal Engine 4 will be a great tool! Also, when you have programmed a lot of games, and get tired of programming the same lines, you are ready to move onto an engine.


BE REALISTIC:
If you are sitting here now, with the great idea of remaking Final Fantasy 7 w/ multiplayer support and HD Graphics, I have to disappoint you. First off, you are most likely just one person, who don't have any idea of how to create a game like Pong. Creating a remake of Final Fantasy 7 requires a huge team, who has knowledge of how to program some...more advanced stuff.

With this said, we all have to begin somewhere. In these tutorials, we will start off very simple, and then build upon our skills. Actually, we are going to create the following games as our first major goal:

- Pong    
- Worm    
- Breakout
- Space Invaders
- Tetris
- Pac Man
- Super Mario Bros

Ω Verax's Programming Tutorials Ω Pong
Our first goal, Pong.

If we can create all this, then you can easily create a game like The Legend of Zelda or Sonic. But for now, our first goal is to create a game like Pong.


CONCLUSION:
So, now you should have an idea of where to start. Choose a programming language to use, and learn it. Stay away from engines for now. Create Pong. Sounds simple, huh?

But, before we create any games, we have to know what a game actually is, which will be the main subject of the next tutorial. Until then, see you!


~ShadowCodeX







Verax

Verax

Messages : 1139
Data de inscrição : 27/06/2014

Volver arriba Ir abajo

Ω Verax's Programming Tutorials Ω Empty Re: Ω Verax's Programming Tutorials Ω

Mensaje  Verax Miér Ago 06, 2014 8:09 pm

GAME PROGRAMMING #2:

Hello everybody, and welcome back! Today's topic will be, well...games.
So sit down, lean back in your chair, get some coffee and some music going through your earphones, and have a good read!

Ω Verax's Programming Tutorials Ω Programming-and-code-13_www.FullHDWpp.com_
Game Programming.

So, we have a rough idea of what we are going to do. We have chosen a language to use. We have decided if we are to go with an engine or not. We know what we are going to create. Personally, I will be using Java, I will stay away from engines and I am going to create a game. But wait! What is actually a game?

WHAT IS A GAME?
Think about it for a minute. What is really a game? I remember when I was young, I used to believe that a game was a movie that changed, depending on your actions. I wasn't too far off either.

The key elements a game really needs would be interaction, challenge, mental or physical stimulation and entertainment.
Usually, we can also add graphics, game design and sound to this.

Knowing this, the easiest way of explaining what a game is would be to think of the result if you mixed a movie and a CD together and added interaction to it.
But a game can be so much more than just that. They can tell stories that really makes you think about certain topics, they can give you emotional experiences and they can be fun to play together, just to mention a few things.

Ω Verax's Programming Tutorials Ω 9k=
Games can be emotional.


CONCLUSION:
I won't go into the depths of Game Design yet, but I want you to think.
What is a game for you? Is it just a picture on the screen refreshing 60 times each second?
Is it just a "timekiller"? Can we actually learn something from video games? Is it culture?

Obviously, when we look at Pong, we don't really see a whole lot more than graphics, challenge and interaction.
But I want all of you to open your eyes for what a game really is. The next time we will get our hands dirty with some
programming, but until then, see you all!


~ShadowCodeX







Verax

Verax

Messages : 1139
Data de inscrição : 27/06/2014

Volver arriba Ir abajo

Ω Verax's Programming Tutorials Ω Empty Re: Ω Verax's Programming Tutorials Ω

Mensaje  Verax Jue Ago 07, 2014 5:12 pm

GAME PROGRAMMING #2:

Hello everybody, and welcome back! We finally get to look at some code today!
So sit down, lean back in your chair, get some coffee and some music going through your earphones, and have a good read!

Ω Verax's Programming Tutorials Ω Programming-and-code-13_www.FullHDWpp.com_
Game Programming.

So, we know know our goal. We are to create Pong. Personally, I will be using Java, and the IDE Eclipse, and only that (with the help of Photoshop and MS Paint for graphics).

GAME LOOPS:
So, the general idea is to refresh the screen around 60 times every second. (60 Frames Per Second/60 FPS). This is done through a Game Loop. A game loop is exactly what it sounds like. Code that loops. But what to put inside this loop?

Ω Verax's Programming Tutorials Ω Game-loop2
A Game Loop.

The basics of what we have to do in our game loop would be to:
- Get User Input.
- Update the game.
- Draw the game.

Código:
while( running ) {
        update();
        draw();
    }

Here you can see the most simple game loop. It just press these tasks together. (User input isn't usually handled directly in the game loop).
But! We have some problems:
- Game runs at different speeds on different computers.
- CPU (can be needlessly) pegged at 100% usage.

This means that a game using this loop could run at 300 FPS on one computer and 30 FPS on another. What if we could possibly set a constant value to be the FPS?


GAME LOOPS w/ CONSTANT FPS:
But we can! Have a look at this code, which is more complex:

Código:

                int FPS = 60;
                int OPTIMAL_TIME = 1000/FPS
                long startTime;
      long elapsedTime;
      long waitTime;
      
      //Game Loop
      while(running) {
         startTime = System.nanoTime();
         
         update();
         draw();
         
         elapsedTime = System.nanoTime() - startTime;
         waitTime = OPTIMAL_TIME - elapsedTime/1000000;
         
         if(waitTime >= 0) {
         
         try {
            Thread.sleep(waitTime);
         } catch (InterruptedException ex) {
            ex.printStackTrace();
         }   
                        } else {
                        //Shit, we are running behind! }      
         
      }
   }

Woah! What happens here?
Well, we set our FPS to be 60. Then we set our OPTIMAL_TIME, which is what we will use for calculations later.
Then we create some more variables to work with. Afterwards, we set the startTime to System.nanoTime(), since I use java.
Then we update and draw. Then we set elapsedTime equal to the time it took to update and draw our game.
After that, we set our waitTime. Here we add the FPS into the calculation with OPTIMAL_TIME. Since we are working with such precise numbers, we have to divide them to get the actual seconds for the Thread to sleep. Then we check if we can sleep. If not, our Thread can't have a break in order to catch up.

This is an easy solution to our problem. However, having the FPS set as a constant, slow systems may have problems running the game, and we don't unlock the true potential of fast systems. There are ways to make it so that the FPS is decided by the speed of the system, but this makes everything much more advanced when we are going to handle our physics later on, which I am sure would confuse you a lot for now. On the good side, almost every computer today can manage to run 2D games all the way from Pong to Super Mario Bros. with ease. Therefore, we will be using a game loop like this, since it is the easiest to understand for now, and it will do the job best.


CONCLUSION:
We know have an idea of what a game loop is. It's essentially just handling the things we are to do 60 times each second.
This may still be confusing, but we are going to return to it later.

The next topics will be the hardware itself (Hertz, Bit Depth, Monitor, GPU etc.).
But until then, see you all!


~ShadowCodeX







Verax

Verax

Messages : 1139
Data de inscrição : 27/06/2014

Volver arriba Ir abajo

Ω Verax's Programming Tutorials Ω Empty Re: Ω Verax's Programming Tutorials Ω

Mensaje  Verax Jue Nov 20, 2014 8:05 pm

GAME PROGRAMMING #4:

Hello everybody, and welcome back! We are having a look at some technical stuff today!
So sit down, lean back in your chair, get some coffee and some music going through your earphones, and have a good read!

Ω Verax's Programming Tutorials Ω Programming-and-code-13_www.FullHDWpp.com_
Game Programming.

So, we basically want to run our game in fullscreen, because it allows the player be more immersed in the game. We also want our game to look good, yet be efficient. Let's have a look at our hardware and the things we can do with it!

THE MONITOR:
Your monitor works the way that it displays about 65-75 pictures every second (well, technically it refreshes 65-75 times every seconds, but you get the point). This refresh rate is what we call Hertz (Hz). Now, don't mess this Hertz up with sound & audio terminology, because in audio, Hertz refers to the sound sample rate.

Our monitor also displays colors. But, our monitor can only display this many different colors at once. How many colors the monitor can display at one time is called the bit depth. Let's have a look at some pictures:

Ω Verax's Programming Tutorials Ω 1_bit
1 Bit (2 Colors)

Ω Verax's Programming Tutorials Ω 2_bit
2 Bit (4 Colors)

Ω Verax's Programming Tutorials Ω 4_bit
4 Bit (16 Colors)

Ω Verax's Programming Tutorials Ω 8_bit
8 Bit (256 Colors)

Ω Verax's Programming Tutorials Ω Truecolor
24 Bit (16,777,216 Colors) ("Truecolor")

So, what does all this means? Well, the way we can do the math with bits is to start with 2 and give it an exponent which is the desired bit depth. This means that 1 Bit is 2 with 1 as an exponent, which equals 2 * 1 = 2 Colors. Simple, huh? Now, let's take 8 Bit. We have 2 with 8 as an exponent. 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 256 Colors. Same with 24 bit, which equals 16,777,216 Colors (Phew!). Now, NES games and Atari used 8 Bit graphics, meaning that they could only have a palette of a total of 256 colors. A link to the past, for the SNES, used 16 Bit color, which is the reason why links hair is pink - they didn't have the space for more colors on their palette. But, what bit depth is optimal, you ask?

24 Bit is very suitable for the human eye. However, not too many games use 24 bit color depth. Most games either use 8, 16, or 32 bit color. 8 Bit is very retro, 16 bit is "high retro color" and 32 bit is HD. However, 32 bit color depth has the drawback of being slow to render, but that is not really a problem with the graphics cards of today.

THE GPU:
In order to run a game in fullscreen, we need to hijack our GPU from the computer. The way we do this, depends on the language though. The reason why we have to hijack and take control of the GPU is because the GPU (Graphics Card) controls what is being displayed at our monitor. If we manage to hijack our GPU, we can then say "Hey, GPU, "insert language here" has created a new window and you are to make this window fill the entire screen and draw whatever we tell you to draw!". With the GPU hijacked, we can also get the size of the monitor and other data.

In Java, this is done by first getting the GraphicsEnvironment, which we can use to get the GraphicsDevice, which basically is a reference to our GPU. Then, in order to get the monitor data, we can use the GPU reference to create a GraphicsConfiguration and get the data of the monitor from that reference. Neat, eh? Then we can simply use this GPU reference to draw whatever we want to draw to our window. Very neat indeed.

CONCLUSION:
Now you should know the theory behind monitors and colors, and also have an idea of why we need to hijack our GPU in order to render something in our game. We haven't really used this in a practical example yet, but eventually we will get there too.

So, until next time, see you!

~Verax







Verax

Verax

Messages : 1139
Data de inscrição : 27/06/2014

Volver arriba Ir abajo

Ω Verax's Programming Tutorials Ω Empty Re: Ω Verax's Programming Tutorials Ω

Mensaje  Contenido patrocinado


Contenido patrocinado


Volver arriba Ir abajo

Ver el tema anterior Ver el tema siguiente Volver arriba

- Temas similares

 
Permisos de este foro:
No puedes responder a temas en este foro.