Author Topic: Another "help the newbie get started" topic  (Read 18383 times)

Marker Mage

  • Newcomer
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Another "help the newbie get started" topic
« on: December 21, 2011, 11:37:50 PM »
I'm interested in learning C++ and programming games, and I think that roguelike seems like a fun genre to program for. However, I have had some difficulty in finding a good tutorial for the C++ programming language.

My accomplishments in programming so far include making a rock paper scissors game for a graphing calculator that would change the odds of each choice depending on the results of previous games (so it would catch on if you just used the same thing repeatedly), a minesweeper clone done in visual basic, and a turn-based strategy game (also in visual basic) that I had stopped working on when the teacher for the business computer programming class I was in noticed that I was behind on the work he was giving out due to me goofing off so much by working on that game. I have had plenty of time to forget much of that.

My first attempt at finding a good C++ tutorial online had brought me to http://www.cprogramming.com/, which seems to have quizzes testing knowledge that their lessons don't contain, with question 6 on their first lesson's quiz being a good example of this problem. I got a bit fed up with the tutorial and its lesson quizzes expecting me to know stuff that it hasn't told me, and went back to Google to look for another tutorial.
My second attempt brought me to http://www.cppgameprogramming.com/, which is when I learned that their code didn't work with the compiler that I had (CodeBlocks). They pointed me towards a website to get a copy of the compiler that they used. I decided to try to download their most recent version that wasn't a beta, only to encounter a 404 error... so not much luck there either.
My third attempt was searching the forum topics here for "c++ tutorial", only to find out that the search function doesn't seem to recognize "c++" as anything more than the letter c and that it doesn't matter if that c is by itself or part of a word.

And so now, I'm on my fourth attempt, asking people on a forum. I'm looking for a tutorial that I won't have to pay for and was made by someone who actually kept track of what information it gave out (this is where my first attempt failed) and will either work with CodeBlocks or link me to a compiler that isn't in beta and is able to be downloaded. If any of you can point me towards a tutorial like that, I will be thankful and get back to learning programming. If you know of a tutorial that has a focus on games, that would be even better.

So can any of you guys help me?

Hi

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 154
  • Karma: +0/-0
    • View Profile
    • Email
Re: Another "help the newbie get started" topic
« Reply #1 on: December 22, 2011, 01:33:41 AM »
Are you on windows?
You are learning C++ because you heard that it is the language for making games in?
If you are not opposed to it there is a tutorial in freebasic on making a roguelike.
http://users.freebasic-portal.de/rdc/tutorials.html
« Last Edit: December 22, 2011, 01:43:34 AM by Hi »

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: Another "help the newbie get started" topic
« Reply #2 on: December 22, 2011, 02:13:32 AM »
C++ is not an ideal newbie language. It is very powerful but will not stop you from making horrible mistakes and it has plenty of gotyas. This is because it is a derivative of C.  While there is probably not a better language out there for support and features it is probably not your best option. It is more of a hardcore programmer language.  Especially when you start having memory errors and corrupt memory heaps :)
Problems like that are absent in more modern languages with garbage collection etc.

That said, I would program in nothing else, I love C++.  http://www.cplusplus.com/doc/tutorial/ You also really need to head down to your library and grab a "modern" C++ book (>2000).  You will need it! 

I am a professional C++ developer and I use http://www.cplusplus.com/reference/ as my API reference.

Good luck.
P.s Roguelikes are much harder to program than you think. Check out libtcod roguelike library for a boost.
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Marker Mage

  • Newcomer
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Another "help the newbie get started" topic
« Reply #3 on: December 22, 2011, 03:44:01 AM »
I am interested in learning to do this stuff in C++ because it seems to have a good reputation, and I noticed that it was mentioned in http://roguebasin.roguelikedevelopment.org/index.php/Roguelike_Dev_FAQ#Which_programming_language_are_roguelikes_generally_made_in.3F. If you guys think that C++ would be too hardcore for someone who only has experience with visual basic.net, and whatever language a TI-83 graphing calculator uses, then I guess I could try learning something else first like FreeBasic.

As for roguelikes being harder to program than I think, I thought a realistic goal would be something without a magic system, without any stats other than HP, without equipment, with attacks that do only 1 HP of damage, with floors that have only one randomly generated room, without an inventory, without a save/load function, and with the intention to never show it to anyone other than close family and friends, and hope to manage it within a month. Sure, it would be much less than a roguelike, but it seemed like something that I could make and gradually modify into something that could be called a roguelike. If I am underestimating how hard it is to make a roguelike, then I am rather curious as to just how much lower I should set my sights.

guest509

  • Guest
Re: Another "help the newbie get started" topic
« Reply #4 on: December 22, 2011, 04:45:24 AM »
  Hey man there are a lot of nay sayers here about C++. I think they forget that programming a roguelike is a good way to get into programming. Making a text adventure is also a good way.

With your experience you will be fine. And if you are really wanting to be a programmer it will be very useful for you to be familiar with C++. If you have no aspirations of being a programmer some day then go with something easier.

Every programming language has its ups and downs and foibles.

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: Another "help the newbie get started" topic
« Reply #5 on: December 22, 2011, 05:37:42 AM »
C# might be a better option if you are a window user and AFAIK has console support built in (i.e no need for extra libraries) and it has garbage collection (no pointer weirdness/memory issues like c/c++) and also is quite a modern language.

And yeah a really basic roguelike is not that hard to make!
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Another "help the newbie get started" topic
« Reply #6 on: December 22, 2011, 12:15:44 PM »
Read source codes of roguelike games and try to figure out what is done and why. Pick a game that has well documented source code (although I guess only few well written roguelikes exist). I think it's a better way to learn than just learning C++ and not knowing how to proceed from there.

Darren Grey

  • Rogueliker
  • ***
  • Posts: 2027
  • Karma: +0/-0
  • It is pitch black. You are likely to eat someone.
    • View Profile
    • Games of Grey
Re: Another "help the newbie get started" topic
« Reply #7 on: December 22, 2011, 01:02:12 PM »
If you know some Basic then FreeBasic seems a good way to go to get started at least.  Start out with some of the simple language learning stuff (hello World -> sorted lists, etc) and then getting a grasp of whatever curses equivalent there is for display.  Then get an @ wandering around your screen and start adding obstacles and enemies and whatever other little things you want to play around with.  Think things through in simple steps before implementing, and save old versions of the code in case you screw up.

It's good to see you have a realistic focus on what to achieve in the short term.  Many new programmers enter in with far too grandiose ideas.  Leave those at the back of your mind whilst you pick up the basics with as simple a game as possible.  And it's not like you can't make an interesting game with such simple elements (my games Gruesome and Toby the Trapper both have all the restrictions of your realistic goal, and yet were well received as interesting and unique roguelikes).

NON

  • Rogueliker
  • ***
  • Posts: 349
  • Karma: +0/-0
    • View Profile
    • Infra Arcana
    • Email
Re: Another "help the newbie get started" topic
« Reply #8 on: December 22, 2011, 01:15:58 PM »
Quote from: Marker Mage
I thought a realistic goal would be [...] something that I could make and gradually modify into something that could be called a roguelike.
That sounds like a really good plan. I kinda learned C++ while starting to write my own Roguelike (but I took an "advanced" class simultaneously), and one trap I fell in in several areas was "this feature will become complicated, therefore the code must be complicated to prepare for the future". I have since ripped out and rewritten several big parts of the code with the motivation "ok, let's make this stupidly simple this time" and got great results from that both in terms of code and game play.

I say unless you have good experience in programming and game design, don't plan too much. Just go with the fastest solution and rewrite later when the game grows.
Happy is the tomb where no wizard hath lain and happy the town at night whose wizards are all ashes.

Leaf

  • Rogueliker
  • ***
  • Posts: 64
  • Karma: +0/-0
    • View Profile
    • Email
Re: Another "help the newbie get started" topic
« Reply #9 on: December 22, 2011, 03:52:47 PM »
Corremn++, re C#.  It's a really great language.

Also, maybe consider Java or Python.  I hear that there is a python version of that roguelike library that everyone is talking about.  I believe that it is very very easy to learn bad habits if you cut your teeth on something like C++, and you'll have a devil of a time debugging your memory leaks (which I assume isn't an issue with VB, though I've never used it). :3  I mean, if you want to do this project for the explicit purpose of learning C++, then go for it, but I predict that you'll have a harder time with the debugging, leading to frustration, and eventually to decreased chances of finishing the project altogether.

ido

  • Rogueliker
  • ***
  • Posts: 618
  • Karma: +0/-0
    • View Profile
    • Tame Tick
Re: Another "help the newbie get started" topic
« Reply #10 on: December 22, 2011, 05:37:31 PM »
I hear that there is a python version of that roguelike library that everyone is talking about. 

Complete Roguelike Tutorial, using Python+libtcod.

XLambda

  • Rogueliker
  • ***
  • Posts: 208
  • Karma: +0/-0
    • MSN Messenger - tau_iota@live.de
    • View Profile
    • The Weird Rogue
Re: Another "help the newbie get started" topic
« Reply #11 on: December 23, 2011, 12:39:52 AM »
I hear that there is a python version of that roguelike library that everyone is talking about. 

Complete Roguelike Tutorial, using Python+libtcod.

This got me started, as well. Not that I hadn't been into Python before (lol, virtually everyone at our university is), but it does a very good job at explaining the basics and giving you some code to base your stuff on.

Marker Mage

  • Newcomer
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Another "help the newbie get started" topic
« Reply #12 on: December 23, 2011, 06:00:39 AM »
I found a tutorial for making a roguelike in C++, and I've just completed the moving @ part, and I even got it to stop at the edges. I am so excited! I may even be able to make a turn-based version of Pacman before the year ends. And then I could start to slowly make it into some kind of Pacman roguelike by adding in randomized mazes, an inventory to allow you to save power pellets for later use, alternatives to the power pellet (they may even start out unidentified), and a leveling system that allows Pacman to become faster if the score gets high enough. But before I do all of that, I'm going to have to create a copy of the classic Pacman maze and get the @ to move around in it without going through the walls.

I will make sure to read up on memory leaks when I understand enough about C++ to understand the results that I get when I Google "c++" and "memory leak". Any other advice on what to look out for would be nice. For now though, I'm going to act as though any use of a goto command will result in a velociraptor attack.

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: Another "help the newbie get started" topic
« Reply #13 on: December 23, 2011, 09:28:40 AM »
Yep, I remember the feeling when I got my first '@' moving around, and bumping into '#'. Then I added 'm's that moved randomly. Keep the feeling going!! 

Memory problems are usually associated with poor use of pointers, memory allocation and arrays. Try to stick with the standard template library (stl) for containers, rather than arrays. Even though arrays are so much easier.
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Leaf

  • Rogueliker
  • ***
  • Posts: 64
  • Karma: +0/-0
    • View Profile
    • Email
Re: Another "help the newbie get started" topic
« Reply #14 on: December 23, 2011, 02:44:15 PM »
You get your memory leaks from not releasing allocated memory.

What does this mean?  I'm glad you asked! :P

Let's say you have some arbitrary collection (maybe an array, maybe a hash table, whatever) that indexes a bunch of stuff in the dungeon by x,y coordinate.

You create a monster.  Let's say it's a Dire Leaf.  And you put it somewhere in the dungeon.

(pseudocode)

cellsCollection.put( x, y, new DireLeaf() );

The Dire Leaf wanders about the dungeon for a while, scratching random bits of pseudocode into the walls.  Then a Corremn comes along and kills the Dire Leaf.  You must remove the dead Dire Leaf from your object graph.  Let's say the DireLeaf is at x,y.

cellsCollection.remove( x, y );

And you go on about your day.

WAIT STOP!  You have a memory leak!  Why?!?

When you instantiated the new DireLeaf earlier, the storage for the object is allocated off the heap, and you are given a pointer to it.  In languages like C and C++, you MUST always explicitly return this pointer back to the operating system, or the storage will never be reclaimed (at least not until the program exits or crashes).  We call this garbage collection.  The way you're supposed to do this varies between C and C++.

(assuming an object in C++): deadDireLeaf.delete();
(assuming a pointer to a struct in C): free( deadDireLeaf );

Well that's easy, it seems.  I suppose it is.

But as the code becomes more complex it ceases to be such, and the memory leaks start to creep in there.  Memory leaks are terribly difficult to debug, even with tools specially designed for it.  Even more difficult than threading bugs like race conditions and deadlocks.  What makes it so difficult is that your code just blithely goes about its day, running fine, until you have so much unfreed garbage that you can't allocate any more memory, at which point the program crashes.  And the stack trace you get has nothing to do with the actual source of the bug.

More modern languages like C#, Python, and Java do their garbage collection automatically.  Remember the "cellsCollection.remove( x, y )" from before?  That's all you have to do.  Assuming something else somewhere else in the program isn't holding a reference to the dead Leaf, the runtime will realize that the memory allocated to the dead Leaf is no longer in use and free it for you automagically.  This means you get to spend more time actually implementing things and less time trying to figure out why your program is suddenly using 4 gigs of ram after you've been playing for 5 hours.

What I think many people don't realize is that automatic garbage collection is actually /faster/ than explicit deallocation.  Sure, it consumes more CPU on average, while the garbage collector runs over your object graph marking and sweeping.  But the garbage collection typically runs at a lower priority than your program, so the collection happens at times when your program would otherwise be idle (sitting there waiting for you to press a key), rather than in the middle of that tight loop where you're deleting a bunch of objects.

Don't get me wrong.  I think explicit deallocation has its place.  But I believe that these days its place is firmly in the realm of bare-metal stuff, rather than high-level application programs.  That's also not to say that you can't still have memory leaks in languages that collect garbage automatically (all it takes is one little reference somewhere that is indirectly accessible from the top of the object graph), but it's much, much rarer and easier to find (often the bug that causes the leaks in auto-GC'd languages causes other problems as well, and the leak will magically disappear once you find and fix those other issues).
« Last Edit: December 23, 2011, 03:04:32 PM by Leaf »