Let's Make a Game! Part 2!

  • Thread starter D4rkDragon
  • Start date
D4rkDragon

D4rkDragon

Lemon Dragon
Towns Folk
Hi everybody,

First, sorry for the lateness of this second part, but, I got back home, and with that, I got back the terrible connection I just didn't want to deal with. But, let's get started with what you want: Making a game, second part !

Last time, we set up basic tools such as the Haxe environment (Text Editor + Compiler), and the Flash Projector we'll use to debug our prototypes/games, as well as the Haxe Flixel toolkit. Now, we'll start a project and get working (ok, actually more theory than work, but there will be some).

1> Setting up a project
(This part applies to FlashDevelop, as I don't know how it would work with HIDE or Sublime Text/Whatever IDE you're using)
Remember when I told you to download a .fdz off HaxeFlixel's website ? Still got it ? Open it, and FlashDevelop will set everything up... and you'll be able to create a project that uses HaxeFlixel.

In order to do so, click Project > New Project... and select Haxe Flixel. Enter whatever you want as the name, and as for the package name... whatever you want, as long as it has dots. (ie. game.d4rkdragon.3dspediatutorial or com.mypseudo.gamename)
and then click "Ok".

The project has been made !

2> Let's get working with Haxe !
Okay, the project has been made, and you can already run it ! Select Neko (slower to load) or Flash and click the Debug button next to it ! FlashDevelop's log might say some weird stuff (for you), but, don't care about that, it basically means that your computer is actually doing some magic to turn that empty project we just made into... an executable program !

And, now, it's up ! Let's see... it has... nothing.

Indeed, we didn't started working on the code, so, nothing will appear on the screen.

3> Displaying text on the screen !
Not totally interesting, but it should already be helpful.
In MenuState.hx, insert this before the "override public function create()":
Code:
public var _text:FlxText = new FlxText(320, 240, 0, "Hello, can you see me ?", 8, true);

and between the brackets (in create()), we'll add this, before super.create():
add(_text);

Now, run this !

...
Some text appeared ? Good ! Wait, what, you want explanations ?

4> The Unsolved Mystery of the Text That Appeared on the Screen (< sounds like some novel/movie title)

Ok, so what the heck exactly happened ?
I'll just explain simply.

"public var _text:FlxText = new FlxText(320, 240, 0, "Hello, can you see me ?", 8, true);"
|--> To put it quite simply, it just creates a new object*, called _text, and which has the text "Hello, can you see me ?", is located at 320 (X) and 240 (Y), has a field width of 0 (with HaxeFlixel, it means auto-sized), a font size of 8, and the true at the end means that we use HaxeFlixel's embedded font.

"add(_text);"
|--> Basically, it means that we add our text to the scene*

What, it's even more confuse now ? Seems like we'll have to dig deeper into the world of programming to explain that !
*Will be covered after.

5> Objects, states, variables, methods, functions, classes... Were they drunk when they created programming ?
No, it isn't here for the sake of bothering you or just adding some colours to the IDE.

See, in object-oriented programming, we begin with the concept that "everything is an object". A player is an object, a tree is an object, a map is an object, and even the NPCs are objects.

To define that term more globally:
"Anything that has some kind of defined behaviour is an object" Think about it. The player can move, the tree can be cut down or have fruits, NPCs can talk, maps can be generated and modified, so it means that they do have a behaviour.
And here, FlxText is the base class of our object. So, let's proceed with the "class" term.

A class is a blueprint of an object. It contains informations about how it works, how it can interact, and more private stuff like health, mana, and name in the case of a player. Oh, and classes do have information about how objects are meant to be created or destroyed. (= put in memory and removed from memory)

Now that we know what classes and objects are, let's cover the states thing.

Let me tell you: this is specific to a few game engines, and states have a dramatic dark secret that will make you never look at your life the same way again: they are-- *insert tragic music* objects. Basically in HaxeFlixel, states are things like levels or menus. In a fact, some of you might have noticed the "extends FlxState" after MenuState.

It means that MenuState is an object, and that FlxState is the blueprint for it (thus linking this part to what we saw earlier).

See, it wasn't that hard ? And if you still don't get the concept, well, don't forget this is a thread, so ask me !

Let's proceed with Functions And Methods.

Remember algorithms you used to make in math classes ? They kinda classifies as function, though in math, the "function" term is exaggerated. Method would be more appropriate. So what are they ? They're basically a lines of codes. But they can be re-used. So instead of typing the same thing a thousand time, you could make a function using those lines you typed so many types and call it instead of typing all again. Oh, and methods and functions can take arguments and toy with it.

But it doesn't solve the main question: What's the difference between Methods And Functions ?
See, to put it short and simple: methods doesn't return a value, while functions must absolutely return a value.

So, you can assign a function to a variable, and the variable will take the result of the function (=what is returned).
However, assigning a method to a variable isn't advisable, and might make your program crash.

And what about variables ?
Well, let's put it short and simple again: Variables range from anything to everything. They can be numbers, characters or even a string (=a sentence). However, their range differ depending on their type. The smaller ones will take up less space in memory, at the cost of a smaller range, and so goes on. Also, variables with numbers (=int series of variable) can be unsigned, which mean that can be positive only. Apply a -1 to an unsigned int32 (long) whose value is 0, and you'll get 2^32-1^= 4294967295 (< This was the cause of the 136 year ban for Smash 4 on 3DS, where, due to ban times being unsigned in seconds, it would end up with this result. Weird if you ask)

Okay, that's all for now. I'm sorry if you expected something more practical, but I want to make sure that you understand the basics of what awaits next, as things will start to get serious from now on. Next time, we'll go further, and we'll see how to display a simple image with... a button (aka how to properly use what Flixel has to offer in term of UI)!

Oh, and don't forget to ask questions in case you don't understand something ! I'd help the best way I can !
 
Last edited:
  • Like
Reactions: 3dsatackman, AricAttack, 423 and 5 others
Back
Top