AuthorTopic: making video games, where do you start?, how do you stay focus?  (Read 29629 times)

Offline Beoran

  • 0010
  • *
  • Posts: 112
  • Karma: +1/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #30 on: August 02, 2008, 04:06:41 pm
Next installment: a bit about loading libraries, modules, sub-modules and constants.

Ok, so you're probably roaring to go, and actualy do something that is actually related to game programing. Well, we're almost ready to start... but first, I have walk a last side-road for a while, sorry for that. :)

As you may have realised from looking at what puts 3.methods wrote on the screen, there is a huge amount of commands available to Ruby. So much, in fact, that probably no one would need all of them, and that the name of the command would have to become very long and perhaps confusing if all those commands were available directly.  To prevent this mess, related commands (procedures, functions) are grouped together into neat packages called "modules" in programmer lingo.

A good example of modules is the Math module. It contains more advances math commands, like trigonometry, or  the square root which is abbreviated to sqrt like this:
puts Math.sqrt(4)
-> will write 2.0 to the output.

"Math" is a module, an it contains several math related commands, like Math.cos Math.sin Math.tan Math.sqrt . So, what Math.now means to Ruby is, look into the Math module, for the sqrt command, and do what it must do. It's actually quite similar to
s = "Bob"
puts s.length
Where you put the text bob into s ,and then tell ruby that it has to look up the command/method length into the commands that are related to text strings, and hen do what it has to do for that string.

OK, but what if you get tired of always writing the name of the module in front of the command? Well, then you can do it like this:
include Math
puts sqrt(2)
the include command will take all commands that are in the Math module, and mke them direcly available, so you don't need to type the name of the module anymore.

Now, a bit about constants.
What's a constant? Well, it's much like a variable, that is , a named location where a value has been stored. However, different from a variable, you don' t want it to change. An example might be the value of PI, you know from the formula of the circle circumference is 2 times the radius of the circle times pi. Well, in Ruby, this value is in the Math module. Try this:
puts Math::PI
-> 3.14159265358979

The value of PI is something that's not supposed to change, so, that's why it's a constant. You use the :: in stead of a . to look up the value of PI in the math module, because PI is not a command, just a constant, and it would confuse Ruby if you mixed up the two of them. How does Ruby know that PI is supposed to be a constant and not a variable? Well, simple, it looks at the first letter, and if that's a capital letter, it treats the thing thus named like a constant.

Did you notice the name of the Math module is also a capital letter? Yes, it's a constant , because, you probably don't want to change the contents of that module (the functions that it contains).

One other problem with the huge amount of commands potentially available to Ruby  is speed. The more commands that Ruby has to know about, the more time it has to spend looking them up, slowing down things. Just like a clerk in a big book shop will need more time to find a book than one working in a tiny book shop. So, that's why all of these commands have been split up into different parts, called "libraries". Almost all programing languages do split up their functionality over libraries, so you can make the program run on a "need to know" basis, which is good for speed and simplicity. Libraries also allow many different people to work on ading new commands to a programmin glanguage.

A good example of a library is of course the rubygame library, which contains a lot of commands needed for working with the screen ,audio, etc, for making games. Normally the commands in that librar are not available until you install that library, and also tell Ruby to use the library inside your program.  You'll have to tell Ruby that you really want to also use the commands related to game programming in rubygame, in the "rubygame" library. You do that like this:

require 'rubygems'
require 'rubygame'
Rubygame.init
Rubygame.quit

This program does nothing but start up Rubygame and close it down again, but it should run without giving any errors if rubygame is installed correctly.

The require 'rubygame' command tells Ruby that you really need the Rubygame library, and makes it so that Ruby will look up commands in that library.  The name of the library is between quotes, because names of libraries need to be text strings in ruby. You also need a require "rubygems" before that, because the Rubygame library itself needs some stuff that's inside a different library called "rubygems".  Once the rubugame library has ben loaded, the Rubygame module that is inside the rubygame library, and all the commands it knows about became available for use.

Which means were're almost ready to start displaying something on the screen! :)

But perhaps it's better if I let you digest al the stuff I wrote above before I continue. I eagerly await your questions. :)
« Last Edit: August 02, 2008, 04:09:03 pm by Beoran »
Kind Regards, Beoran.

Offline PypeBros

  • 0100
  • ***
  • Posts: 1220
  • Karma: +2/-0
  • Pixel Padawan
    • PypeBros
    • View Profile
    • Bilou Homebrew's Blog.

Re: making video games, where do you start?, how do you stay focus?

Reply #31 on: August 02, 2008, 04:16:59 pm
Cents follow:

First you can't make the game without the game engine but how would you know how the game engine should work if you don't know what sized sprites your going to use and how many of them without drawing the graphics first?  How do you stay attentive drawing the graphics?
You can usually have two kind of game engines: those that are limited to what the hardware allows, and those that try to hide hardware limitations to the programmer. The number of frames, etc. should not be a limitation, though. At worst, you'll have (on gaming hardware) restrictions such as "16x16, 32x16, 16x32, 32x32, 64x32, 32x64 or 64x64 only", and have may end up with a 24x24 sprite on a 32x32 frame with 70% of the pixels being fully transparent.


Quote
(I'm thinking of making this game for either a Sega Genesis or a Super Nintendo)
I'd say forget it, esp. for the SNES, because it has really ugly programming (assembler only) and unless you're a veteran programmer, you'll completely get overwhelmed by technical details even with something "as simple" as the game engine of (say) Cave Story ... The Nintendo DS (and the PSP to some extent), on the other hand, show similar hardware than those beloved 16-bit consoles, but with 32-bit CPUs that can be dealt with like a PC, with "higher" level language (C, C++). Not that it will make your work as easy as in a flash game, but well, playing a game on a gaming system is definitely more fun than with a keyboard ;)

Quote
How do you come up with a system of designing the game that allows you to do EVERYTHING?!
You don't. Not that way, at least. You can come up with an engine that handles 90% of your ideas, and you write custom code for the remaining 10%. Then you ensure you can "register" custom code to the game engine and make it trigger your custom code e.g. when the player enters a given area.

Quote
I have a lot of crazy game ideas that don't involve just having enemy sprites walking on a non-moving background layer.  For example, having a wall in the background crack and then the ceiling collapse on you, you can't achive with just the "sprites on one playfield background" kind of engine.  It wouldn't work because it will require the top of the background to be turned into two backgrounds and the second will be also as much as part of the game as the first background.
In a game engine, i'd be handling a situation like that by first editing the map (e.g. so that a previously solid area now is no longer solid) and generating sprites/polygons for the cracking wall.

Quote
What about compressing graphics?: If you do all the decompressing before you start the level you might run into RAM limitations; if you do real-time compression you might have som miserable slowdowns (unfortuanately, a lot of Snes games relied on this method, I heard from someone); and if you don't use compression you might run into ROM problems.
Guys handled that with extra hardware ... cartridge shipping RAM plus ROM and a decompressing "DMA" chip that moves and unpacks at once while the (slow) CPU of the console does the rest. Honnestly, if you instead opt for the DS, you'll have 4MB of RAM, +640KB of video ram and plenty of CPU time to unpack the next sequence... Alternative is to have some kind of "intermission" sequence where CPU needs are limited (e.g. a 'boost up' in a shoot'm'up where there are no ennemies to avoid) so that you can focus on unpacking the rest of the level. That's something you'll work on *wayy* after, anyway. This is typically a "technical detail" that you can handle later, just having two playable zones during your demo times.

** edit after a couple of PM exchanged with Beoran **
C/C++ is afaik "state of the art" (maybe the "Golden Way" too) to squeeze the best of your modern handheld gaming console (GBA, DS, PSP), but that golden way is made of spiky tiles that may throw you deep into the pitfall of segmentation fault that only meditation of the guru can avoid. Put otherwise, it's certainly not the easiest thing to start with if you have no previous experience on game programming.
« Last Edit: August 02, 2008, 07:23:56 pm by PypeBros »

Offline Beoran

  • 0010
  • *
  • Posts: 112
  • Karma: +1/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #32 on: August 02, 2008, 06:10:36 pm
Pipebros:
Just a few nitpicks here, and I don't want to sound to harsh, so please don't take offense, ok? :)

The "level" of a language is how much work it takes out of your hands and does for you. C is not a high level language. It is a low-level language, since it almost does nothing for you implicitly. C++ is the a low level language C with a lot of high level stuff bolted on in a rather tricky way.  Of the currently top 10 popular languages (Google TIOBE Index), only Python or Ruby are truly high level and feature-complete languages. All other popular languages are either low level (C),  middle-level(Java,C#, Javascript) or miss some useful features (PHP, Basic) or are quite tricky to program in (C++, Perl).

IMO, C or C++ are only about 2 times faster to program in than assembler. Ruby and Python are easily 10 times faster to develop in than in assembler. That's why I went ahead with my series above as intro to game programing in Ruby for Dragonboy and other interested people here. Ruby or Python really are the fastest ways to get started with game programing and get something done, barring things like Gamemaker or RPG Maker (which also uses Ruby, in it's latest version, by the way). Dragonboy was already and understandably losing his patience with assembler, and thats why I chose to recommend him to start with Ruby (or Python) in stead. Although it cannot completely remove the learning curve, it will lead to encouraging results that much quicker, at least, I hope. :)
Kind Regards, Beoran.

Offline Luzeke

  • 0010
  • *
  • Posts: 116
  • Karma: +0/-0
  • I draw, therefore I ink.
    • View Profile
    • inkBot

Re: making video games, where do you start?, how do you stay focus?

Reply #33 on: August 02, 2008, 08:25:55 pm
Removing the learning curve is a bit pointless though, since it's the curve in which you learn, hence the name.  ;)

Anyway, I use Multimedia Fusion 2 for my own projects. It's available from www.clickteam.com and the standard version costs $100. So it's not free, but not expensive. Any sort 2D game is possible to do with it, and there's a fairly large community for it too.

I'd also recommend this book, On Game Design. It's a great book about game design, we had it in our first course on the university and I've probably read through it about a dozen times or more. Definitely a good read if you're into games. The author is also a really nice guy.  :)

Good luck with the game making man!

Offline dragonboy

  • 0001
  • *
  • Posts: 28
  • Karma: +0/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #34 on: August 03, 2008, 01:49:24 am
Sorry, my family keeps asking me to do stuff.  I downloaded the program but the RubyGames doesn't show up in my folder.

edit: wait I found it but it says "can't reconize file type" when I click on it, and besides all these little glitchy files are slowing my computer down.
« Last Edit: August 03, 2008, 02:10:39 am by dragonboy »

Offline Beoran

  • 0010
  • *
  • Posts: 112
  • Karma: +1/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #35 on: August 03, 2008, 08:35:22 am
Dragonboy, normally, installing  Ruby and Rubygames does not slows your computer down. Software that isn't used does nothing. I installed Ruby using the one click installer on one of my company' s PC and it's easy and fast. Probably there is something you didn't quite understand. Which is not a problem, I'll try to make it more clear to you. :)

First of all, to install ruby, look at the instructions here:
http://ruby.about.com/od/tutorials/ht/installrubywin.htm

You simply ave to download the ruby ine click installer from the link I ssent you before, and then double click on it, then the installer should appear on the screen, and you'll just have to click next, next, etc. After you installed Ruby, were you able to find SciTE in the start menu? You may need to look a bit around in the menu or scroll it a bit.

If you want to get some live help with installing Rubygame, you can try to connect to IRC using http://www.mibbit.com/
Choose Freenode.net from the drop down menu, fill in Dragonboy as your nickname, and #rubygame in the chanel box.
To ask questions about installing ruby, you could do the same but fill in #ruby as the channel name. 
IRC is a kind of chat that is very popular with computer programers, so I reccomend you use it. I'll be hanging around
a bit on both #ruby and #rubygame channels the next few days, so you can also ask me there. But I'm in Europe, so keep in mind the time difference.

I have some questions for you as well:

Do you have a basic understanding of how to work with your operating system (windows?), how to work with files, copy them, and uncompress zip files, and how to install applications? If you're unsure about all these things, please ask me, or please read the online help of your OS, or borrow a book about your OS in the library, or look at one of the many tutorials like this one: http://www.helpwithpcs.com/courses/windows-xp-tutorial-desktop.htm

Do you understand what I'm writing or is my English too bad or too difficult for you? I'm not a native English speaker, so perhaps I used some words that are wrong? Don't be afraid to ask! What are you using, Windows XP, or Windows Vista? Were you able to install the Ruby one click installer? Did you understand the instructions on how to install Ruby and Rubygames?

Anyway, he most important thing is to hang in there! :) You will have to learn if you want to program games, and it will take some time,
but I can assure you it's all worth it. I'm sure you can do it as long as you keep it up. :)
Kind Regards, Beoran.

Offline dragonboy

  • 0001
  • *
  • Posts: 28
  • Karma: +0/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #36 on: August 03, 2008, 05:54:17 pm
I downloaded and installed Ruby Games several times.  I did all what the "how to download/install Ruby Games" said.

I've found the icon for Ruby Games but my computer doesn't know what it's supposed to "open with."  My computer was never good at detecting file types for some reason.

My folder is already full of tons of copies of the same stuff.


EDIT: Is it the SciTE thing?  I clicked on the SciTE thing and it looks like a notepad only with a "language" menu list.
« Last Edit: August 03, 2008, 05:59:06 pm by dragonboy »

Offline Beoran

  • 0010
  • *
  • Posts: 112
  • Karma: +1/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #37 on: August 03, 2008, 07:14:46 pm
Ah, I see. I think you installed Ruby correctly, but didn't  know how to get started with it.

Yes, to start programing, you need SciTE, that "notepad-like" program! Programming is done by writing texts in a sort of "better" notepad, and then letting the programming language run (= execute, do what you tell to do in your program) them.  Go back and read the message above, from Saturday 2 august at 07:56:21 AM about how to use SciTE for programing in Ruby.

In short, try to write things like

puts 123

in that "notepad thing", SciTE, save the file as program1.rb, and then you can run the program you just wrote and saved by pressing F5, or going in the menu and doing Tools->Go. Something (unimpressing) should happen, and the 123 will appear in a sepaate window. That is the output of your program. Please tell me if you have any problems getting this far.
Kind Regards, Beoran.

Offline Beoran

  • 0010
  • *
  • Posts: 112
  • Karma: +1/-0
    • View Profile

Re: making video games, where do you start?, how do you stay focus?

Reply #38 on: August 07, 2008, 07:20:58 am
Dragonboy are you still with us? Is anyone else interested in me continuing my tutorials this thread?  If neither is the case, then I'll let this thread rest for now.
Kind Regards, Beoran.

Offline Helm

  • Moderator
  • 0110
  • *
  • Posts: 5159
  • Karma: +0/-0
    • View Profile
    • Asides-Bsides

Re: making video games, where do you start?, how do you stay focus?

Reply #39 on: August 07, 2008, 07:31:32 am
I really am. But I guess if I'm all there is yeah, time to pack it in.