Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

27. October 2011

 

Yeah, I really took my sweet time on this one, but things are better the longer you wait, no? Smile

 

 

In this chapter we get the ball rolling, literally.  Additionally we add collision detection and realistic rebounds.  On the C++ front, we introduce and discuss the various types of casts in C++.

 

For those of you that haven’t read it yet, the Pang C++ Tutorial table of contents is right here.

 

For those that have been following along, Pang Part 7 is here.  As always, full project source is included at the end.

 

 

And here Pang, the worlds most over-engineered pong clone in action!

 

pang7

Programming , ,

25. September 2011

 

Ok, it actually has been live for a couple days and I forgot to post an update here, oops.

 

 

In this chapter we add animation to our PlayerPaddle class, including player keyboard input.  We cover off topics such as running at the same speed on multiple machines, dealing with protected member variables and using asserts.  Now, I’m off to write part 7.  I swear this is going to make the Guinness world record for the longest Pong tutorial ever!  I hope it’s been useful, please let me know any questions, recommendations or comments you have.

 

 

I proudly present Game From Scratch C++ Edition Part 6.

, ,

15. September 2011

 

I recently had a user who tried to run Pang on MacOS and there were a few incompatibilities.

 

So today, I fired up my trust old iMac and created my first ever C++ Application in XCode 4.1 and I have to say, it really wasn’t all that pleasant of an experience!

 

 

First off, about Pang.  There are a few small changes that don’t work on the iMac using GCC 4.2.  First is there is no tchar.h header file.  On the same thought, Microsoft’s _tmain is not portable and the entire targetver.h header file doesn’t work.  Reality is, none of these are really a big deal as we are not using any Windows specific features, nor are we supporting Unicode parameters to our main(), so it is all a pretty easy fix.  Simply delete all of these includes, remove targetver.h completely and change make to a traditional main().

 

 

Code wise, there was one gotcha.  GCC 4.2 does not support calling a nest enum’s name.  For example if you have the following:

struct Colour { enum DefinedColours { Red, Green, Blue }; };

 

You can’t do this:

Colour::DefinedColours::Red;

 

Instead you have to do this:

Colour::Red;

 

Which is a shame as I find the one much more readable than the other, but no big loss.  Going forward I will be compiling on both Windows using Visual Studio and Mac OS using XCode/GCC 4.2, so if you are following along using a Mac ( or GCC with CodeBlocks ) the code will be guaranteed to work.

 

 

Now, about XCode.  I will admit this is my first real experience with it.  I played around with 3.x when I first looked into iOS development but never really got a chance to try out 4.1.  I like the idea that they went to a single Window, as a VC developer  XCode 3.x was very alien.  That said, this is about where my likes end.

 

Nothing was intuitive, intellisense ( or whatever it is called in non-Microsoft parlance ) is SLOOOOOOOWWWWWW, the interface is extremely cluttered, the project/scheme system seems odd ( with time this might improve ), the debugging experience was not fun ( weird focus issues with my running application ).  Then worst of all, I had to spent a good 20 minutes figuring out where the hell my compiled application even ended up!

 

Through this experience, as a complete newbie I had to Google a lot and I noticed two trends.  First, all the documentation for earlier versions is useless… its like every single keyboard shortcut and menu was changed completely.  Second, the hate seems to be pretty universal!  Every time I would Google something, half of the answers would be “screw it, stick with 3.4” or similar.

 

That leads me to my question to you Mac C++ developers out there… Does Apple have a bit of a turd on their hands with XCode 4.x, or will it get better as I get used to it?  If not, what IDE are you all using for C++ development on Mac?

 

 

Anyways, long story short, from Pang part 5 on, Mac/GCC will compile unchanged out of the box.  That said, this tutorial is still going to focus on Visual C++ Express as the IDE of choice.

Programming ,

13. September 2011

 

 

I was trying to figure out a way to work a “Johnny Five is Alive!” Short Circuit reference into the title and failed hard…  anyways, the next chapter/part of Game From Scratch C++ Edition is now live although I promise you I will be doing edits. 

 

 

In this part we create a game object manager, aptly called GameObjectManager to organize and manage game objects.  It may seem like a bit of a waste of time but trust me, in time this little class is going to seem exceptionally powerful!  On the bright side, it will give you more exposure to the standard library classes, especially std::map and std::for_each, both of which you will use over and over again from this point on.

 

 

Is it massive overkill for a pong clone?  Yes, very much so!  But truth told, this series is little about the actual game and more about how to create a “real” game instead of a demo.  So, even though this game is quite trivial in it’s scope doesn’t mean we can’t have a certain amount of complexity.  When we are done this process my ideal is you can walk away and make just about any type of game, not just a trivial pong clone.  This is why at times things may seem a bit overkilled.

 

Truth told, I don’t know if I blew the difficulty curve on this post.  I feel compared to the last post, I may have ramped up the difficulty and done a poor job of explaining things, please let me know if this is the case!  If things are confusing or unclear or just simply wrong, let me know and I will address them!

 

 

Well, without any further ado, I present Game From Scratch   C++ Edition     Part5.

Programming ,

5. September 2011

 

You may have noticed many times on my blog that I am not the biggest fan of C++.  I hands down believe that it is one of the dumbest languages a user could learn with.  A good majority of programmers should never be exposed to C++ and should be happy if fate affords them such a luxury.  I also think a lot of C++’s use in game programming is as much a matter of traction as any other logical reason.  So why the hell do I talk about it so much?

 

Well one of the reasons is because so many (new) developers give a lot of other new developers the horrid advice that they should start with C++ that you need to actively educate people why this is a mistake.  However, there is another reason for C++’s coverage… it is important and it’s importance is on the rise. Amazingly that rise in popularity has nothing to do with (specifically) game development!

 

You see, the revolution in mobile computing coupled with the rise in indy developers has created a perfect storm of sorts for C++ developers.  You see, of all the mobile platforms out there, they all support their own native language ( iOS = Objective C, Android = Java(ish), Palm == HTML5/Javascript while Windows Phone 7 == C#/Silverlight ) yet all of them support C++ ( although WP7 requires a special relationship with Microsoft for C++ access ), to say nothing of Symbian… mostly because it’s dying off. 

 

Therefore, if you want to write portable code that runs across most of the mobile phones on the market today, C++ is your go to language.  Operating in a resource constrained environment is exactly where C++’s strengths come into play.  Unfortunately you are going to end up doing some device specific code in whatever the native language is, but on all devices this amount of native code is getting smaller in size.  For the most part you can make 99% portable C++ code, something you can’t currently do for smartphones in Java, C# or ObjectiveC.

 

That said, if you are willing to spend money, you can use C# across platforms in the form of Unity or Monotouch/Monodroid but that requires additional expense.  Besides, I recently took a look at Monodroid and I simply cannot imagine how anybody is using that platform for production code, at least on Windows the developer experience was frankly atrocious.  If I was doing a cross platform 3D game ( that I expected would make at least 400$ ) I would be ( and am ) using Unity, but I can understand why you would choose otherwise, especially if you were working on a 2D project.

 

If you are a new developer, I still recommend you stay the hell away from C++.  I just wanted to make it clear C++ has it’s uses and in my opinion is only going to get more popular, a comment I would have never expected to have made just a few years ago! As I have said many times C++ is just another programming tool and sometimes that tool is the most appropriate one for the job.

 

Given it’s justified rise in popularity among indy developers, combined with the fact that beginning programmers are going to ignore my advice and start with C++ anyways, I am going to introduce a bit more C++ specific content on this site.  The C++ of today is much different than the C++ of 1983, yet unfortunately a great volume of the information on the internet doesn’t reflect this fact.  I hope to address that to the best of my (meager) ability.

Programming ,

Month List

Popular Comments

Actually running your PlayN game
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


6. November 2011

 

 

Hmm, kinda realized I missed this part in my recent PlayN installer post.  After you go ahead and create your game, it creates a new project hierarchy and… then what?  This post shows the various ways you can start your game.

 

Assuming you used my installer to install PlayN, you can run your game from the command line using the following steps.  I will assume your game’s name was “mygame” in these examples and that you installed to c:\playn.

 

 

 

Running the desktop Java app with Maven

 

 

cd playn\playn\mygame\core

..\..\..\maven\apache-maven3.0.3\bin\mvn install compile exec:java

 

 

Running the HTML target with Maven

 

cd playn\playn\mygame

..\..\maven\apache-maven3.0.3\bin\mvn package  ( wait, this takes a bit )

..\..\maven\apache-maven3.0.3\bin\mvn –Ptest-html

 

This will currently through a bunch of errors in your face since the Flash build seems to currently be broken, ignore them.  Once you run that second command, a web server Jetty will be downloaded and installed.

 

Now open a browser and go to http://localhost:8080 to see your game running in a browser.

 

When done, you can use CTRL+C in the dos window to get Jetty to stop.

 

Running the Flash target with Maven

 

You can’t, it’s currently broken, I’m looking into it and will update with details or a fix if possible.

 

Running the Android target with Maven

 

This process is a bit too involved and requires other steps ( like configuring the emulator or a physical device, which we didn’t do during the initial install.  I will cover this in detail in a later post.

 

There is a problem in that the fact Flash is broken, and before Android in the build order, your Android target will never be built!  This can easily be fixed by opening pom.xml in your game folder and remove the line <module>flash</module>.

 

Running the Java and HTML targets with Ant

 

If you have Apache ant installed, you can also use it to run Java and HTML targets. Currently you cannot run Flash or Android this way.

 

Running desktop:

cd playn\playn\mygame

ant

 

Running HTML:

cd playn\playn\mygame

ant run-html

 

Just like with Maven ( but a whole lot quicker ) it runs Jetty and you can reach your website using a browser.  However, unlike the maven install, for some reason the ant install is in a subdirectory, so your URL is http://localhost:8080/mygame.

 

 

Of course, if you are using an IDE like Eclipse or NetBeans, they can automate many of these tasks.  If you add Maven’s bin folder to your PATH variable, it will save you a ton of typing.  Of course you could also make a simply script to run your game in a much more terse syntax.

Programming

blog comments powered by Disqus

Month List

Popular Comments