Author Topic: Programming Code needed to make game?  (Read 9122 times)

0 Members and 1 Guest are viewing this topic.

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Programming Code needed to make game?
« on: September 17, 2009, 10:43:43 PM »
I can't seem to find good tutorials online, so I'll just throw this one out there.

What's the coding needed to make a game (please explain the structure as well for me!)?  I am currently considering these three languages:

C#
C
Java

This fact about C kind of concerns me, but I don't know if it would have an effect on any of my projects...

Yeah, I'm a Wikipedia freak...  get over it...


Things I need to do...

I would like to make the game somewhat of a cross between "Cave Story" and Metroid Games...

Features from Cave Story:
Doors/Teleporters
Dialogue/Signs
Boss Health Bars

Features from Metroid:
Metroid has a different door system from Cave Story, so I do want Metroid-style doors as well.  However, of the doors that do not require any upgrades to get through, I shall use Cave Story's occasional Metroidish doors (imagine the Blue Doors in Super Metroid, minus the hatch).
Stackable upgrades?

Features from both:
Platformer
Doesn't Metroid have a shaking display during the Self Destruct sequences (in Super Metroid, at least)?  I KNOW Cave Story has this at its last area...
Enemies (DUH)
Upgrades, of course
Multiple Endings...


So, how overambitious is this sounding? :XD:

BTW...
www.en.wikipedia.org/wiki/Cave_Story
http://www.miraigamer.net/cavestory/

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #1 on: September 17, 2009, 11:20:42 PM »
Oh dear.  I forgot...  we could use a starting point to make things less complicated...

Let's see...  music programming can come later (note that we DO need support for any (or all) of these three formats:  .xm, .it, .mod).

Let's start with a basic platformer tutorial with the doors implemented as well.  That seems like a reasonable start.  Note that I only need to see one target language, not all three.  If I can gather enough information for any one of the three languages, I will use that one.

Offline GuyPerfect

  • Posts: 363
    • View Profile
Re: Programming Code needed to make game?
« Reply #2 on: September 18, 2009, 04:55:31 AM »
Unfortunately, computers aren't abstract enough to understand what it means when you say "do some platforming." You need to break absolutely everything down into individually representable steps that a computer can understand. In this case, a "platforming tutorial" isn't likely to exist because the topic even in its most general form is too complex to cover in a succinct manner.

As a developer, it will be your task to identify how you want your platforming to function, then to design a system and implement it. Older games like Super Mario Bros. use a simple block terrain setup, and newer games generally have geometric objects interacting with line segments or polygons.

A subset of the greater platforming concept, and probably the one you'll want to look into first, is collision detection. I've written an article for what I'm doing in my Metroid project, but it all still depends on how you want it to function in the first place.

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #3 on: September 18, 2009, 05:03:09 AM »
If you can spare the time to look at it, I really like the terrain set up and the physics in Cave Story (which is a great game, btw, plus it's free).  I don't need anything TOO complicated with the terrain set up.  Probably will use blocks, as long as I can do some ramps angled like the ones in Lemmings 2.

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #4 on: September 18, 2009, 05:12:54 AM »
OK.  Got a basic drawing of what the terrain might be like (I will do a lot of editing to it, though, later...).   If I do more complicated terrain, I'll probably make a system of invisible collision detection areas so things don't need to get too complicated.  Every angle in here is what we may see in the final game.  There may be slightly less sloped areas, but...  shouldn't be too difficult once we have these.  The staircase if probably off proportion.  Colours aren't final yet...  at all.

NOTE:  The dark green area is actually a little background.  And again the final game won't look so cruddy, I just was trying to use MS Paint to get the idea across.

Online Simon

  • Administrator
  • Posts: 3877
    • View Profile
    • Lix
Re: Programming Code needed to make game?
« Reply #5 on: September 20, 2009, 12:13:40 PM »
What is your current experience with compiled programming (i.e. not scripting) languages?

If it's rather scarce: Pick any compiled (or to byte-code compiled) language, google on how to install a compiler for it, and play around. Write a program that reads a file and writes it somewhere else (Dullstar file copy deluxe v1.0), and write the guess-the-number game, and write tic-tac-toe with a computer opponent. Or similar text-based games.

See if you like it. If you do, look around for a graphics library for your chosen language, and program a demonstration with colored shapes. And then Pong, or Snake, or Minesweeper, or... anything you want, it's programming for a hobby after all.

Then learn another language, and how to think in it. You want to be able to decide on which tool (language) to use for which job.

-- Simon

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #6 on: September 20, 2009, 06:13:31 PM »
My current experience?  Not too much.  Why?  Most tutorials you find with a google search are crap.

Online Simon

  • Administrator
  • Posts: 3877
    • View Profile
    • Lix
Re: Programming Code needed to make game?
« Reply #7 on: September 21, 2009, 01:37:58 AM »
That's fine. So which language are you going to play around with?

-- Simon

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #8 on: September 21, 2009, 01:39:19 AM »
The ones listed in the topic's first post.

Offline Adam

  • Posts: 424
  • Just one more level....
    • View Profile
    • Lemmings Forums
Re: Programming Code needed to make game?
« Reply #9 on: September 21, 2009, 01:01:43 PM »
Right, normally a user would go through the warning system if they made a post which broke the rules. However, the severity of this, combined with the fact that this user has signed up JUST to slate Dullstar leaves me with no choice but to request a ban. I don't have the priveleges to ban this user myself, but I have requested such action be taken.

Thank you to the people who reported this post. Dullstar, I would just ignore this troll... it's a shame there isn't an option on SMF called "Tachy goes to Coventry." - it would be perfect for ADmiral.

Offline The Doctor

  • Posts: 301
  • Jason the Human
    • View Profile
    • zapzupnz.com
Re: Programming Code needed to make game?
« Reply #10 on: September 25, 2009, 12:17:06 PM »
I suggest you use an object oriented language (C++ or C# or Java … you know I'll steer you toward C# and Java but it's up to you), and then make a class diagram. For the purposes of what I'm going to talk about, we'll talk about C# and .NET/Mono.

In that way, you can draw a class diagram. Do an abstract one (not a strict UML one) to get the basic concepts down to a T. Decide what your classes will be.

Classes should reflect real world objects. When you try to think of classes for a game, imagine it as a board game, it helps. For example, you have a player. That's one class. You have the game field, that's another class. You have items, that's a class. You have enemies, you can have an enemy class. You'll also have the game as a whole, that's a class in itself.

When you do this, think about inheritance. Inheritance is when a class can be based off another class. Rather than have a billion classes for different kinds of items, perhaps you could have a single item class. Each different kind of item could inherit from the generic item class. Therefore, you re-use code efficiently.

Code-wise, when you instantiate a class (turn it into an object in memory) you can use constructors. Constructors plus inheritance equals code reuse if done properly.

You should learn about the object oriented programming paradigm as a concept rather than jump into programming without it. Learning an object oriented programming without learning object oriented concepts means you'll write a semi-procedural program which is event-based but not object oriented.

The reason I promote object oriented languages and concepts to you is that it can dramatically simplify the development process. Procedural programming has its advantages too, but for the purposes of your game, I think OOP would be simpler.
This Lemmings forum is simply *fabulous*!

Offline ccexplore

  • Posts: 5311
    • View Profile
Re: Programming Code needed to make game?
« Reply #11 on: September 25, 2009, 08:38:05 PM »
While I agree that ADmiral's posts were incredibly rude, unhelpful and uncalled for, I do think that it could be helpful and more fun if Dullstar starts off not with a programming language, but something more along the lines of GameMaker etc.  There are still elements of programming involved, but such tools are much more directly geared for creating games, so I think it would be a perfect stepping stone for someone like Dullstar, being able to make some games and getting a sense of how programming works, before he moves on to a true general purpose programming language.

I've seen a whole bunch of beginners like Dullstar who hasn't done any programming but has been able to pull off a bunch of decent amateur games with tools like GameMaker, so it's definitely a proven route to go I think.

The only issue is that Dullstar only has Linux not Windows, and most of these game-making tools I think are only available in Windows rather than multi-platform.  Although some of them might work well enough with WINE though, you'll have to try and see.

As for tutorials, you'll never find a single tutorial that can cover "how do you make a game" because making a game is a complex undertaking no matter what.  Just like there's no hope of someone learning to write an essay if he still hasn't mastered the alphabet, basic vocabulary, and sentence structure, etc., tutorials can only help you cover the fundamentals of programming.  So I don't suggest Googling in that direction because you won't get very far.

Offline The Doctor

  • Posts: 301
  • Jason the Human
    • View Profile
    • zapzupnz.com
Re: Programming Code needed to make game?
« Reply #12 on: September 26, 2009, 01:10:07 PM »
A game making suite is indeed a good idea. However, that issue of Dullstar using Linux is a big point because Dullstar is looking to create games that are cross platform from the word go, rather than after tedious porting. Those game making suites lock you in to a specific platform nine times out of ten.

I think using something like GameMaker is a good idea for a prototype, but I still encourage Dullstar to learn programming concepts properly along side, so that in the future he can … well … tediously rewrite! Hehe.

I'm not sure what kinds of game making suites exist outside of the Windows world. The few I do know about still require some level of programming expertise (such as Unity player, which requires knowledge of Objective-C but runs of a few platforms).
This Lemmings forum is simply *fabulous*!

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #13 on: October 12, 2009, 04:10:00 AM »
So far, of the ones I've tried, it appears the best one is C...  is there a way to get the object oriented part with the same (or at least similar) syntax to C?  C# just seems, well, harder to write in than C.  Or is it already object oriented?  Argh, what a great hour to be on on and off checking Wikipedia!

Offline GuyPerfect

  • Posts: 363
    • View Profile
Re: Programming Code needed to make game?
« Reply #14 on: October 12, 2009, 04:23:02 AM »
Object-oriented more or less just means that the elements you declare have code attached to them. So to declare something like "Object Q;" where Q is something like, oh, an apple-to-orange converter, you might also be able to say later "SomeVariable = Q.ConvertToOrange();"

When classes are not available for use like that, you simply need to write functions that take structs as one of their arguments instead. Declaring "Struct Q;" could later be used as "SomeVariable = ConvertToOrange(&Q);" and you're at the same spot as you are in the previous example.

For anything you're likely to be using classes for, you should easily be able to do the same thing using structs as arguments to the functions that would otherwise have been menthods of the classes. Unless you intend to delve into things like inheritence or abstraction, you won't benefit from using classes in the first place.

Personally, I dislike classes and object-oriented programming based on a matter of principle. Though it unarguably increases productivity when writing functional code quickly (such as would be the case in a business environment), it requires a considerable amount of processing overhead and unnecessary memory management when the program actually runs.

Remember: from the perspective of the CPU, there's no such thing as object-oriented programming. That chip simply takes one instruction at a time and processes it. You can do that with structs. You can't do that with classes. Structs have inherently higher performance.

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #15 on: October 12, 2009, 04:25:04 AM »
So, I can write a game in C?

Offline ccexplore

  • Posts: 5311
    • View Profile
Re: Programming Code needed to make game?
« Reply #16 on: October 12, 2009, 08:55:25 AM »
Object-oriented more or less just means that the elements you declare have code attached to them.

That's a rather shallow way to define OOP.  I'd say you aren't really using the full power of OOP if you aren't making use of features like information hiding and inheritance.

it requires a considerable amount of processing overhead and unnecessary memory management when the program actually runs.

Depends on the language.  C++ supports a majority of OOP features, but since it does allow objects to be stack-allocated, you don't have to hit the heap if you don't need to.  As far as I can tell, the "processing overhead" and "unncessary memory management" you're thinking of are specifically regarding languages like Java and C# that does garbage collection and doesn't support stack allocations.  Those features are not prerequisites for OOP.

Remember: from the perspective of the CPU, there's no such thing as object-oriented programming. That chip simply takes one instruction at a time and processes it. You can do that with structs. You can't do that with classes. Structs have inherently higher performance.

For someone telling me to read the C spec, this has gotta be the most misleading statement I've ever heard.

CPUs deal with primitives like bytes, "words", floating point values, and addresses (which you can think of as pointers).  Structs are nowhere at the level of such primitives, any more than classes.  Some struct member access may be translatable into a single CPU instruction depending on the CPU, but so can some cases of accessing a class member variable.

As for "inherently higher performance", I think you may be way overstating the supposed overhead of classes.  For a language like C++, where structs are actually equivalent to a special case of classes, there should be close to 0 extra overhead, and for languages like C# and Java that doesn't allow (or greatly restricts) stack-allocated structs to begin with, you simply don't have a choice to begin with.

Besides, even if we're doing the "worst case" comparison of a heap-allocated, garbage collected language with C, the overhead might not matter if your performance bottleneck is not directly in your own code, but in things like graphics processing.  Even the most efficiently written machine code might not matter if there are simply too many pixels or polygons or textures etc. to be processed by your graphics card for whatever it is your game is trying to do.

Another way to look at this is, consider making a game in something like GameMaker.  Now I don't claim to know exactly how GameMaker works, but most likely it'll be interpreting rather than compiling any script/code that your game project may contain, and we're not talking about any fancy JIT optimizations either, just a simple interpreter.  Yet it has been adequate performance-wise for beginners to make games with.  I'm also aware of commercial games created using languages like Blitz 3D, which are compiled but not efficiently so (I can say with personal experience since I've seen the disassembly), and they perform just fine for the games in question (I should note that they are 3D games too).  I think it's fairly safe to say that someone's first game is not likely one that will require every bit of performance to be squeezed from the computer.

So, I can write a game in C?

Oh yes, definitely.  In fact I would guess that assembly, C, and possibly C++ covers like 99% of all commercial games past and present.  C's capabilties as a general-purpose programming language was never part of the question, it was just a matter of which language suits you best.

Offline GuyPerfect

  • Posts: 363
    • View Profile
Re: Programming Code needed to make game?
« Reply #17 on: October 12, 2009, 06:13:01 PM »
Example 1:

Q.ConvertToOrange();

What is Q? Let's say Q is a pointer to an element in an array of classes of type Convertor. Depending on the inheritence used, significant memory allocation may be required when initially declaring the object, as all applicable parts of inherited classes need to be declared as well. Do this every time a function is called and you can bog things down rather quickly.

Is ConvertToOrange() a method in class Convertor? Is it native or is it inherited from another class? Is it overloaded according to this context and instead pointing to a different function than the one in the class definition? After the indirection is applied, is the ConvertToOrange() method still in the picture at all?

When processing ConvertToOrange(), are the member elements of Convertor native to the actual object called or were they inherited from a different class? Are they able to be accessed by the Convertor class at the time the method was called?


Example 2:

ConvertToOrange(&Q);

What is Q? Q is a pointer to something. For all intents and purposes, let's call it a struct of type Convertor. Structs, when declared, simply allocate the number of bytes required to store the struct in memory. Even in dynamic array situations, this can be done quick and painlessly using a single call to malloc().

Since ConvertToOrange() is a function on its own, and one that accepts a pointer to Convertor as its argumnent, it is guaranteed to unambiguously represent a single process, which is defined in the body of the function itself.

The members of the Convertor struct are merely offset from the location of the struct itself in memory, and are always accessible.


For someone telling me to read the C spec, [...]

You have a funny way of saying "Don't waste your time reading my posts," but I kept reading anyway.

Online Simon

  • Administrator
  • Posts: 3877
    • View Profile
    • Lix
Re: Programming Code needed to make game?
« Reply #18 on: October 12, 2009, 07:28:54 PM »
Several valid points, but a straw man argument as a whole, IMHO.

Making a class Convertor and derive every single thing from this is seldom a good choice. Of course the memory grows for an object of a thrice-derived class. Virtual methods are sometimes the very best thing for a job, and C++ is at least as fast with these as a C equivalent of virtuality. If one needs it, it's there. But if the code gets unreadable, it doesn't have to be used.

A struct on the stack/heap is the very same thing as a class on the stack/heap. I assume you know the byte alignment for C++ classes without or with inheritance, thus I don't know how you think C structs and C functions are significantly faster than C++ classes with member functions. Assuming you pass pointers and references, and not by value.

The same argument you bring here can be turned this way: Why do you use a slow, overhead-rich higher-level language than assembly?

The answer is: Because you like to think in C. I like to think in C++. A lot of my programming is of procedural nature, still, as C++ supports several styles other than pure OO. I also believe to know when I have to use bit-fiddling to speed things up. Which comes up every now and then, but not often.

-- Simon

Offline ccexplore

  • Posts: 5311
    • View Profile
Re: Programming Code needed to make game?
« Reply #19 on: October 12, 2009, 08:33:45 PM »
Example 1:

Q.ConvertToOrange();

What is Q? Let's say Q is a pointer to an element in an array of classes of type Convertor. Depending on the inheritence used, significant memory allocation may be required when initially declaring the object, as all applicable parts of inherited classes need to be declared as well. Do this every time a function is called and you can bog things down rather quickly.

You seem to be confusing declaration with initialization.  If your Q has a lifetime outside of the scope of the function this line of code is in, then you would've needed to do something like new Q().  This would be no different than if you malloc the struct-equivalent and run some additional code for whatever initialization you need to do to make Q usable.  In both cases the work is done only once, not every time you call the member function.  As for initializing the applicable parts of the inherited class--if you truly needed to use inheritance in the first place, then you would've had to do the same initialization work if you implement it using structs and function pointers anyway.

If your Q's lifetime can be confined to the scope of the function, so that you can stack-allocate Q in a language like C++, then this is no different from using struct.  The constructor is there because you may need to initialize the values of certain members in order to use the object.  That same initialization would've been needed if you use a struct.  If you can leave the constructor with no code, then a decent compiler should easily be able to inline it to no code if given the information (eg. you define it inline in the header file).

Languages like C++ even allows your Q's lifetime to be "static", ie. essential available for the entire duration of the program's execution.  Those are either stack-allocated or allocated at the static data section of your program's memory, and works similarly to the stack-allocated case.

Is ConvertToOrange() a method in class Convertor? Is it native or is it inherited from another class? Is it overloaded according to this context and instead pointing to a different function than the one in the class definition? After the indirection is applied, is the ConvertToOrange() method still in the picture at all?

It sounds like you don't realize that all this consideration you're mentioning are resolved 99-100% at compile time by the compiler, at least for the languages I'm thinking of.

When processing ConvertToOrange(), are the member elements of Convertor native to the actual object called or were they inherited from a different class? Are they able to be accessed by the Convertor class at the time the method was called?

You're referring to information hiding.  This has nothing to do with run-time performance, it's just semantics enforced by the compiler to keep you from depending too much on the existing implementation of some class or interface.  For the languages I know, none of these considerations required any runtime processing AFAIK, unless you're thinking of something like Reflection in Java, which is not the usual way you'd be accessing class members in the first place.

ConvertToOrange(&Q);

What is Q? Q is a pointer to something. For all intents and purposes, let's call it a struct of type Convertor. Structs, when declared, simply allocate the number of bytes required to store the struct in memory. Even in dynamic array situations, this can be done quick and painlessly using a single call to malloc().

But you're forgetting that depending on how you're using Q, you may need to set some of its member variables to some appropriate values before you start passing a pointer of it to functions like ConvertToOrange.  So you're implementing the so-called "extra" processing yourself.

Since ConvertToOrange() is a function on its own, and one that accepts a pointer to Convertor as its argumnent, it is guaranteed to unambiguously represent a single process, which is defined in the body of the function itself.

This has nothing to do with performance, since again the compiler can figure out how to do the right thing at compile time.  This works because with inheritance and virtual functions, the class data contains an array of function pointers representing the true destination addresses to call.  The compiler simply emits code to index into the array and execute a CALL into the address given by the function pointer.

If there is no inheritance involved, then you wouldn't need to make the member function virtual in the first place, and the compiler can just call the member function directly.  Depending on how often the call occurs, the overhead of the extra indexing from using a virtual function may be negligible.

Quote
The members of the Convertor struct are merely offset from the location of the struct itself in memory, and are always accessible.

Again, this has nothing to do with performance.  The reason for restricting access to certain members is when they are not part of the interface your object wishes to expose, but instead are implementation details that are subject to change.  If you have full control of the source code of the class, you can always elect to make everything public and named uniquely.  Some languages also gives you a way to access a member hidden by the name of another member in a derived class (eg. casting).

[edit: and one more thing, since you referred to memory layout also.  Class members are not stored that much differently than struct members.  You may not be able to accurately "predict" their exact locations if you merely read the source code of how the class is declared (because of all the extra "hidden" memory for virtual function pointers, if you elect to use it, plus members inherited from base classes), but otherwise, if you account for the extra stuff (none of which is code, which is never stored with the class data if that's your mental picture), it's no different from a struct.  Besides, C doesn't guarantee any alignment for individual struct members either (your compiler might, but that's compiler-specific.  Some compilers even have switches or preprocessing directives for setting the alignment to use).  In any event, it would not be good practice for portability if you have any need to know exactly how the compiler lays out the members of a struct or a class.]

For someone telling me to read the C spec, [...]

You have a funny way of saying "Don't waste your time reading my posts," but I kept reading anyway.

I don't know what you mean by this, but the fact is, during the last argument over C, your responses show it is you in fact who fails to understand some of the finer points in the C spec, and I'm not sure you still quite grasped that.  Your current foray into OOP shows you seem to have even less understanding of how OOP languages get compiled.

You're right that with the greater semantic complexity of OOP languages, you can more easily write code that have more overhead than you realize, but that's as much a lack of understanding of how the OOP features work.  You told me you shouldn't blame C for the user's incompetence, so I'd say you shouldn't blame an OOP language for the user's failure to understand how its features work.  In any event, if you're talking about micro-managing performance at the individual CPU instruction level, then you would've been arguing for using assembly language, not C.

And the final pointer about where the actual perf bottleneck is still holds.

Offline ccexplore

  • Posts: 5311
    • View Profile
Re: Programming Code needed to make game?
« Reply #20 on: October 12, 2009, 09:17:43 PM »
Several valid points, but a straw man argument as a whole, IMHO.

Ha, maybe I should've read your post first before responding to GuyPerfect's stuff point-by-point, since that's exactly what it is.  I'm starting to think GuyPerfect purposely do this just to waste my time because he thinks I can't resist going through his posts point-by-point.

Actually, the real issue is that comparing C with OOP, rather than a specific OOP language like C++/Java, is kinda pointless because there are many many ways the concepts and constructs of OOPs can be implemented by the compiler.  Also, many of the languages have other features that are more of concern when we're talking about performance.  For example, we can talk till the cows come home about how much performance impact the OOP overhead incurs in Java, but then we'll be forgetting that Java compiles to bytecode that is in turned interpreted (with some JIT magic every now and then)--that aspect of the language already puts Java at a disadvantage performance-wise regardless of OOP.  Similarly, C++ gives you a remarkable amount of flexibility over how much OOP feature you want to include in your classes, which can pretty much render a lot of the comparisons somewhat of a moot point.

And let's be clear here that I have no problem at all with GuyPerfect sticking to C.  In fact, given some of his forays into explaining OOP, I'm not sure how confident I'll be if he does try to program in something besides C. ;)

Offline GuyPerfect

  • Posts: 363
    • View Profile
Re: Programming Code needed to make game?
« Reply #21 on: October 13, 2009, 01:13:39 AM »
I assume you know the byte alignment for C++ classes without or with inheritance, thus I don't know how you think C structs and C functions are significantly faster than C++ classes with member functions.

For C versus C++ specifically, the difference in performance in the example I gave is negligible. It is worth noting that my post was not made to be specifically for C or against C++ or any combination thereof.


The same argument you bring here can be turned this way: Why do you use a slow, overhead-rich higher-level language than assembly?

I use assembly any time I code something to work with a specific target platform, such as video game systems. I use C in a general-purpose environment because it can be compiled for various architectures and easily modified to suit alternate uses.


You seem to be confusing declaration with initialization.

When authoring the post, I'd assumed that none of the objects used were initialized. When referring to inheritence, declaration itself needs to look backwards all the way to the top of the chain to make sure all the needed memory is allocated.


It sounds like you don't realize that all this consideration you're mentioning are resolved 99-100% at compile time by the compiler, at least for the languages I'm thinking of.
From a strictly OOP point of view, I refrained from making such assumptions. I had JavaScript in mind when making my post, which can reorganize the object collection on the fly and adapt with changes to accessible members and methods... and even generate its own code to run and switch between data types, though that's not OOP stuff.

You dismissed additional arguments claiming the compiler would handle things, but don't assume that compilers will be used.

For what it's worth, to explain that C++ essentially converts OOP code to procedural code at compile time is not a good way to support the OOP argument.


Besides, C doesn't guarantee any alignment for individual struct members either (your compiler might, but that's compiler-specific.

I didn't mean to suggest that the programmer knows where the elements are, as, like you said, he may not. What I meant is that the code will always say Address + Offset to retrieve any elements of a struct regardless of where or how it's used.


You're referring to information hiding.

I was referring to the literal removal of certain elements or methods depending on the state of the object hierarchy. This is namely an issue with JavaScript, as I'm not even sure C++ can mess with things like that.


Ha [...]

Another good spot to stop reading, but I'm so deviant!


In fact, given some of his forays into explaining OOP, I'm not sure how confident I'll be if he does try to program in something besides C. ;)

Your mother smells like burnt cabbage and you shower with your socks on.

...What? My argument is valid! Take me seriously!

Offline ccexplore

  • Posts: 5311
    • View Profile
Re: Programming Code needed to make game?
« Reply #22 on: October 13, 2009, 01:24:58 AM »
In fact, given some of his forays into explaining OOP, I'm not sure how confident I'll be if he does try to program in something besides C. ;)

Your mother smells like burnt cabbage and you shower with your socks on.

...What? My argument is valid! Take me seriously!

Okay, fair enough, I probably was thinking too much about C++ when reading your examples.  I do agree that some OOP languages will pretty much give you no choice but to take a near-worst-case overhead on every object.  But from what has been cited so far, it seems that for any arguments about perf hits from OOP that applies to a specific OOP language, invariably you can find other features in that language, unrelated to OOP, that also do not compare favorably with C performance-wise.  Some such features may even be of more concern performance-wise compared with the OOP overhead in that language.  (Especially if you include interpreted languages into the mix, which totally throws off the comparison just from the interpreter processing alone.)

So I think it's not so much a question of OOP, as it is simply that in a sense, C abstracts away low-level machine code the least of all high-level languages, and as a result has the least potential of introducting overhead that can be unnecessary and possibly performance-impacting in specific cases.  OOP is merely but one of many possible features in a high-level programming language that could introduce such overhead.

========

On a somewhat unrelated note, I'm not sure this would make a good argument to turn someone away from learning OOP.  They don't have to use an OOP language if the performance tradeoff is unacceptable for specific projects, but learning the underlying concepts I think is still useful.  Interesting for example that you mentioned Javascript--if Dullstar needs to do that sort of programming on a web page in the future, C would not really be a choice anymore, and then he'd still need to understanding the basics of OOP so that he can learn to use something like Javascript.

Offline GuyPerfect

  • Posts: 363
    • View Profile
Re: Programming Code needed to make game?
« Reply #23 on: October 13, 2009, 01:36:16 AM »
Of course, this is all ignoring the fact that most game process threads aren't limited by the efficiency of their code, but rather simply have a target time of whatever the display rate happens to be.

I was also thinking of JavaScript being executed from file in much the same way your typical Perl or PHP script would be... That is to say, not necessarily used on a web page.

Offline Mindless

  • Posts: 719
  • Inactive - may respond to PM.
    • View Profile
Re: Programming Code needed to make game?
« Reply #24 on: October 17, 2009, 01:06:48 AM »
First off, this whole thread is ludicrous.
Secondly, I didn't write this for my health (honestly, I don't know why I'm wasting my time), and I don't plan on wasting my words/time further if this post doesn't sink in.

@GuyPerfect:
Using JavaScript as your token OOP language and making statements about OOP based on how JavaScript works is ridiculous.  Using that logic, I could make similarly ridiculous statements about how horribly inadequate procedural languages are because "it doesn't work that way in Brainf*ck."

OOP is a design choice.  I can write C++ code until the cows come home and never design a single module using OOP.  Some would even go so far as to say, "If you are a class provider, your classes are not object-oriented until someone else benefits from re-using them."

@dullstar:
GuyPerfect was completely correct in his intentions when he said
If you're only looking into programming because of the end result of what you could do with it, you've already doomed yourself to fail.
Computer programming isn't something you pick up one day because you think "oh, it'd be awesome if I wrote a video game," and you go straight off to write this game.  No, you start off writing "hello world," and a few years later you'll have completed the mindset necessary to program a complex game.

You compose all these threads talking about how you'd like to do all these things, but it ends up being all talkWhere does that get you?  Browse Sourceforge for a while and the endless lists of projects with a project summary and no source code, and you'll discover that the answer is NOWHERE.

If you're going to program something, you go off into a cave and program away until you have something to show for your efforts.  Until then, there's no purpose in talking about what you think would be awesome to do.

In short, talk is cheap.

Do I think this post is harsh?  Yes.  Then why am I posting it?  Because you're not getting the point:  You have the most posts of anyone on the forum, so stop posting and go actually accomplish something.

Offline ccexplore

  • Posts: 5311
    • View Profile
Re: Programming Code needed to make game?
« Reply #25 on: October 17, 2009, 02:29:32 AM »
To be fair, I believe Dullstar did start some basic programming exercises like writing a calculator in C# or something like that.  I guess you can say he's trying to jump the gun on doing much more complex programs, and is probably getting lost because he hasn't even started to think about all the subtasks involved.  And as you have suggested, it's also likely that he doesn't quite grasp how programming is like the art of learning to write an essay (nay, maybe more like a novel).  There're a lot of fundamentals you need to address first, such as vocabulary, grammar, sentence structure, sentence/idea organization, and so forth, all of which you need to be on solid footing first before you're truly ready to write great essays/novels.

I myself have relatively limited experience specific to programming games, so take my suggestions with a grain of salt, but I think here are some possible intermediate steps toward getting the mastery required to start writing games for real, besides the obvious of getting solid footing on the fundamentals of programming (for which I suggest taking a programming class for real if you're truly serious into it):

1) Get some basic exposure into 2D graphics programming.  At the end of this, you should be able to write a program that displays a bouncing ball bouncing around a screen or a window.  Don't worry if it looks bad (eg. the screen flickers a lot because you have to keep erasing and re-drawing the ball); just get it to the point where it resembles the description in the preceding sentence.

2) Get some experience into programming the logic, aka game mechanics, of a game, that is, the rules and behaviors that define the interactions between all the entities in your game:

    a) as a first start, I believe you should deal with simple games that are based on real-life games like card games, or board games.
       - The simplest one is to do a 2-player tic-tac-toe app ("2-player" means you don't even need to think about truly advance subjects like AI).
       - Then try to go on with a card game, whichever one you like, again limiting it to all-human interactions with the computer's main role to make sure the rules of the game are followed, to display the progress of the game, and to keep track of scoring (if any).
       - Then if you want, you can move on to a board game like Checkers, Chess, or Othello, again make it all-human so you don't deal with AI.

   Nice thing about these sorts of games is that you can even get by without worrying too much about graphics.  At the extreme, you can make those games entirely out of ASCII art and other textual representations basically (although you might be stretching it a little with Chess...)

    b) As a next step, if you're thinking of computer games, you need to get familiar with what basically are fundamental object-oriented programming (even if you insist on sticking with C structs and function pointers; don't fool yourself into confusing the syntax with the design principles).  It's no accident that a lot of OOP programming classes tend to introduce the ideas by having you write some sort of, if not necessarily a game, then possibly a simulation of real-life things, because in a sense it's one of the things the OOP paradigm is intend to address.  This helps you get familiar with the idea of how you can represent an entity in your game with a collection of data associated with the entity's current state, and methods that you invoke to manipulate the entity (changing its state as a result) and for managing interactions amongst entities.

I don't have a solid idea of what can serve as an "end-game" program for this stage of learning.  I'll let you know if something good comes to mind.

3) Now it's time to go back to graphics, in particular more advance things like bitmaps, collision detection, and animation.  This will take a lot of learning if you intend to write all of this from scratch, so be very patient.

Also a good time to learn about handling keyboard input.  This is much easier than graphics so you should be able to learn both at the same time.

The end game program for this stage of learning should be a program where you can use the arrow keys to move an animated sprite around the screen/window.

=======================

At this point I'd say you're probably 60% on your way towards being able to write your own games for real.  Congratulations!  There's of course a lot more that can be addressed (you'd noticed that I haven't talked about sound or music or even using the mouse; and I've stayed away from 3D and AI for obvious reasons).  If you're serious about it, you may want to consider buying books on game programming, or even just scour your local library for some (although the disadvantage with the local libary is that you may end up with lots of old books with specific techniques geared towards old computers like DOS).

This reminds me, I actually have a book on DOS game programming from like 15-20 years ago.  Maybe I should take a look at it and at least give you an outline of how the book addresses the various areas pertinent to game programming.  I won't recommend the book itself because it's written for the DOS era so a lot of the technical details are not as applicable today, even if the concepts still are.

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #26 on: October 17, 2009, 02:45:40 AM »
Good thing is, no mouse needed in my game projects, only a keyboard!

HOWEVER, at last, something to use to tell what concepts to use.
Unfortunately, I don't know of any programming classes around here, and even if they were something tells me they wouldn't accept people my age, so I'll teach myself.  I might get a book sometime about it, though.
The basic point is, they should be playable within the limits of an SNES controller.  If it can't, there is a problem (that doesn't mean it will be SNES controller compatible, but it will mean that the controller has enough buttons,  :D).

Another little note:  They have been planned 2D anyways.  AI will eventually be needed, but we'll not have anything terribly strategic.  I'll eventually provide basic concepts, but that can wait until we have the ability to move the character around.  I'll have a lot more to program next week, though, because the marching season will be over PLUS a four day weekend!

Offline Dullstar

  • Posts: 2092
    • View Profile
    • Leafwing Studios Website (EXTREMELY OUTDATED)
Re: Programming Code needed to make game?
« Reply #27 on: November 19, 2009, 05:19:03 AM »
I found some decent tutorials, and have a progress report in the form of an image.
Not completely done with the tutorials either...  at least the Python ones are going pretty fast.

Also, I'm going to provide a link for the tutorial - http://rene.f0o.com/mywiki/LectureThree
They also have basic Python tutorials, but as I look into basic stuff from any site, I see nothing more than the stuff I used to write that Python command line calculator.  (I skimmed through Lectures 1 and 2, nothing much I didn't know, although there is something that is somewhat complicated that I'm not sure if it's going to be useful or not, as I recall it saying it doesn't even work in some other programming languages, so I'm just going to come back to that if I need it)