19
\$\begingroup\$

I am a first year college student in India and want to make a small game as a this semester project.

I am quite good at C and am learning it rapidly but I wanted to ask if developing a game entirely in C (no C++ or C#) I'd love to use these but for college projects, we have strict requirements of using only C.

What I am looking for is a simple top view driving game. It won't have anything fancy and even the visual things will be powered by simple characters. For example, user controlled car can be represented by ▓ and edges of road by series of |'s. What do you think?

\$\endgroup\$
6
  • 1
    \$\begingroup\$ related: gamedev.stackexchange.com/questions/371/… \$\endgroup\$
    – Tetrad
    Commented Feb 14, 2011 at 22:37
  • 9
    \$\begingroup\$ SDL is written in C. OpenGL is C. What more do you need? \$\endgroup\$ Commented Feb 15, 2011 at 17:34
  • 3
    \$\begingroup\$ Also, Quake is all done in C. \$\endgroup\$ Commented Feb 15, 2011 at 20:35
  • \$\begingroup\$ Do yourself a favour and use the Allegro libraries ;) alleg.sourceforge.net \$\endgroup\$
    – o0'.
    Commented Feb 16, 2011 at 10:01
  • 2
    \$\begingroup\$ RollerCoaster Tycoon was done almost in pure assembly, so why not? \$\endgroup\$ Commented Feb 16, 2011 at 21:16

10 Answers 10

25
\$\begingroup\$

Writing games in C is possible. For example, Quake II is written purely in C, so writing other games in C should be no problem at all. It may be the better choice if you're more proficient and comfortable in C than in C++.

\$\endgroup\$
10
  • 2
    \$\begingroup\$ @Ishan Sharma: Actually, a lot of game (engine) development is still don in C, or at least very C:ish C++. Nothing says that your C++ game will be better (or even better written) just because it's C++. \$\endgroup\$
    – void
    Commented Feb 15, 2011 at 9:41
  • 6
    \$\begingroup\$ @void: That's only true if the programmer in question has no idea about how to use C++ effectively. C++ programs written where the writer has a basic grasp of object orientation are far more secure and reliable than equivalent C programs. \$\endgroup\$
    – DeadMG
    Commented Feb 15, 2011 at 17:58
  • 9
    \$\begingroup\$ @DeadMG [citation needed] \$\endgroup\$
    – Bob Somers
    Commented Feb 16, 2011 at 7:36
  • 7
    \$\begingroup\$ @Bob Somers: Easy. Compare std::string to char*. std::string always cleans up it's own memory in any situation, allocates the right amount every time. char*, you might forget to free, or double free, or not allocate enough memory. Whoops. Basic logic says that C++ programs are better and more secure than C programs. \$\endgroup\$
    – DeadMG
    Commented Feb 16, 2011 at 12:17
  • 14
    \$\begingroup\$ @DeadMG A good programmer can write good, secure code in any language. Conversely, a bad programmer can write awful, insecure code in any language. A poor carpenter blames his tools. \$\endgroup\$
    – Bob Somers
    Commented Feb 20, 2011 at 3:57
13
\$\begingroup\$

I work on a AAA MMORPG codebase that is pure C, so yes.

\$\endgroup\$
2
  • 6
    \$\begingroup\$ I guess that puts you at Cryptic. Do you use a scripting language of any sort? \$\endgroup\$
    – Dan Olson
    Commented Feb 15, 2011 at 20:18
  • 3
    \$\begingroup\$ We have an internal expression language that used by designers for basically everything, and we use a mix of Python and Lua for some stuff (offline processing, map-reduce on game DBS for stats), but no Real Scripting Language in the game itself. \$\endgroup\$
    – coderanger
    Commented Feb 15, 2011 at 21:49
6
\$\begingroup\$

Yes, it's perfectly possible. Many OS-level APIs like POSIX and Windows, DirectX and OpenGL all have C-compatible interfaces.

\$\endgroup\$
0
6
\$\begingroup\$

Fabien Sanglard has written an article about his 3d engine in C. On reddit, this article has created an interesting debate.

Languages are only tools... So use them wisely. To create a good game, it can be easier to use XNA or Unity3D. Mastering C is a good first step, but you must learn C++, D, python, lua ... C++ is a very difficult langage. So use it carefully.

\$\endgroup\$
3
\$\begingroup\$

C is great for game development.

I'm working on a 3D platformer, and I've never had any problems with the language. The only problems are collision detection and shading, I just know nothing about them, they would still occur in any other language.

In fact, I find it much easier than languages like C# and Java. I always iterate on entities using pointers (an example from my code), and fread saved a lot of time making the map loader.

If you want object orientation and modularity, you can make structures of function pointers.

\$\endgroup\$
1
\$\begingroup\$

Without a doubt. A lot of libraries useful in game development (such as SDL, PhysFS, etc...) have C APIs, which helps a lot.

You may wish to look into embedding a scripting language such as lua if you wish to do any extensible, high-level programming. Many people are beginning to see the appeal in programming a C framework that uses lua for things such as AI, events, etc...

Good luck.

\$\endgroup\$
1
\$\begingroup\$

Simple answer for this question is: You can do simple text based game like this in every programing language. Even pascal, basic or x86 assembler :]

(and do not need anything else)

\$\endgroup\$
0
\$\begingroup\$

Yes it is possible, but it may not be the most desirable course of action. A number of people recognize these days that C and C++ both aren't ideal for a number of tasks, and high level game logic often falls into that category.

If you insist on C instead of C++ (which makes no sense to me, but to each their own), you may be best off using Lua in conjunction with C.

For your college projects that require C this won't be an option, but for spare time projects it would be a good way to learn.

\$\endgroup\$
2
  • \$\begingroup\$ Lua is good at development time, but before the release everything should be ported to a native language for higher performance. \$\endgroup\$
    – Triang3l
    Commented Sep 10, 2012 at 11:00
  • \$\begingroup\$ @Triang3l I don't agree at all. What you describe is premature optimization. Using a native language do NOT guarantee that your code is faster. The correct way to do this is to profile your code, find bottlenecks and improve that code. There are lots of examples where developers tried to write their own C code to replace Java code and the C code became significantly slower, or where developers tried to replace C code with significantly slower Assembly code. Do not underestimate the developers of a high level language and the run-time environment for it. \$\endgroup\$ Commented Nov 22, 2019 at 8:56
0
\$\begingroup\$

Of course you can. Many games have been programmed in C (DOOM comes to mind). SDL is a game programming library written in C.

Of course, it may be a little more difficult than using C++ for a big project, but it's possible.

\$\endgroup\$
0
\$\begingroup\$

I think it is possible to make a complete c games. I have made a game ( which is similar to 'space impact' of nokia 1110 mobile ) in my 2nd semester project using turbo c compiler. I think you can try this way ( as a first year college student ) without knowing any others.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .