Making a simplistic video game - c

I'm thinking about creating a simplistic video game. I'm not talking about anything fancy, but about a game like this:
Since I want to learn, I would prefer not to use libraries but roll as much as I can on my own. I'd need to know how to render the car and the track, deal with collision with other cars, etc. I'm targeting Linux, Mac OS X and iOS. I fear that using a library like OpenGL makes things "too simple".
Are there any good resources out there that discuss this? Most of the tutorials / papers I have found are based around popular libraries & engines.

" I fear that using a library like OpenGL makes things "too simple" "
Don't worry, you still have plenty of work left.
In the REAL world, programmers use as many libraries as they can, that is the only way to produce a applications that focus on how things should work and not spend years on every little feature.
Start out programming above libraries, then, if you want to divide down into details, implement your own library and replace the one you used with it.
Dividing your application into self contained parts is a good practice, makes changing it without breaking everything possible.
Also, I would recommend you learn C++ first. Being able to model your problem domain with Object Oriented methodologies will help you break down the problems into solvable units.

Sounds like you're interested in learning from the level of Simple DirectMedia Layer.
If so, this might be a good place to start: http://gamedevgeek.com/tutorials/moving-sprites-with-sdl/
Probably followed by: http://www.gpwiki.org/index.php/SDL#Creating_a_Complete_2D_Engine
Also, for that particular rendering style, see:
http://en.wikipedia.org/wiki/Parallax_scrolling#The_raster_method
http://en.wikipedia.org/wiki/Mode_7
Edit:
This information about the original Doom engine may be useful:
http://fabiensanglard.net/doomIphone/doomClassicRenderer.php
Also, Chocolate Doom is a port of the original Doom source into SDL, so you'll probably learn some useful patterns studying the source for it:
http://www.chocolate-doom.org

It will be more or less impossible to develop a game without using any library. I guess you would have to go back to good old C64 days to do that. If you are interested in learning, I would look for a more low level library, which provides access to graphics, sound, ... But it should leave the logic to you.
I would propose to have a look at http://www.pygame.org/. It makes working with graphics, sprites, ... easy, is still relativly low level and Python is a great language to get started with.

Related

Where should a programmer with NO static/compiled language exp start learning Go?

I'm an experienced software developer, but I've only worked in dynamic languages (primarily Python, PHP in the past, JavaScript, and a little Ruby). Last night, I found myself reading through the tour on the Go website's tour when I realized that the language (syntax, libraries, etc.) would probably be fairly easy to learn, but my lack of knowledge about static/compiled languages would bar me from easy entry. It's not that I don't understand the core concepts of a static language, namely that function argument/variable/return types are static and that a program must be compiled before use. It's more that I don't know where to begin after writing a program. For instance, if I wrote a web application using the Revel framework, it would handle these steps for me (according to the website). Is that pretty typical of frameworks for static languages. Am I worrying too much about a small part of the process that will be quick to learn, or are the (as I call them) formalities of using a static language pretty cumbersome?
As other suggested, any tutorial on Go would work, and you probably worry too much about the dynamic -> static switch. Statically typed languages can be a bit cumbersome sometimes if you come from dynamic typing world, but you'll quickly get used to your compiler yelling at you when types are not correct, and quickly fix it. Eventually, you'll start double guessing it and write (mostly) type-correct code.
Rob Pike noticed that people coming to Go where coming mainly from dynamic languages, which means this cannot be all that hard to do the switch.
There are a lot of tutorials all over the internet titled "Go for ", such as "Go for Rubyists", "Go for Pythonistas" which can help you map your existing knowledge to Go concepts. But as other underlined, the best (only ?) way of properly learning go is to take a tutorial and dive in ! For the books, the standard Effective Go or the very good Programming in Go are very good reads, no matter your background.
Well obviously practice makes perfect, and reading through the extensive documentation. I also find this book really nice Go-lang book, it has some exercises at the end of the chapters which is nice.
Just get a basic tutorial for the language you want and follow it. You will soon pick up how to structure the program. You can then apply your current knowledge of programming to make it do what you want.

Interesting examples of Domain Specific Languages

I'm considering doing something with Domain Specific Languages for my undergraduate project. My one problem is I can't really find any interesting examples that I can root around in. Does anyone have any good examples of DSELs (preferably open source)?
Also, one area I would love to look at is solving/addressing concurrency problems (coroutines etc) with DSEL's. Are there any good examples that anyone uses of this in DSELs? If this is a stupid application of DSELs please explain why...
Another potential area to explore would database programming. Again is this a stupid area to explore with DSEL's. For example, would adding some crazy database manipulation syntax to C# say be a good project to undertake?
EDIT: General languages I would be looking at implementing in would be Java, Python, Scala, C# etc. Probably not C++ or C.
Linda implementations can be considered as eDSLs. STM implementations like CL-STM are certainly eDSLs.
Unrelated to concurrency, but extremely useful are embedded Prolog implementations, there are plenty of them for Scheme, Lisp and Clojure. Parsing eDSLs had been mentioned already - and their patriarch Parsec definitely worth digging into.
EDIT: with your list of implementation languages you're missing the most interesting eDSL opportunities. The most powerful and flexible eDSLs are made with metaprogramming. Scala-style (or even Haskell-style) eDSLs are based on high order functions, i.e., on mini-interpreters. They're more complicated in design, much less flexible and limited to the syntax of your host language.
boost::spirit if you're after C++ is an interesting example. Quote:
Spirit is a set of C++ libraries for
parsing and output generation
implemented as Domain Specific
Embedded Languages (DSEL)...
(I have no idea what you mean by "solving concurrency" though. I don't see how you can solve "concurrency problems" in general, or how a DSEL could help.)

What are some practical projects to consider in trying to learn C?

I've seen a lot of questions and answers on SO about why I should learn C. I know that it's low level, it'll give me an understanding of how things work at that level, and it'll make me a better programmer. I know some good books to be reading to help me learn C.
What I don't feel like I know are some practical projects I can work on to help me learn how the language is used. There's a lot of examples in the books I'm reading, and they're absolutely useful as far as reinforcing knowledge gained about the language itself. But I don't feel as if I'm gaining any insight into "real life" examples of what I can do with C.
My background: I'm a recent college grad who's doing application programming in C#. I'm enjoying doing programming exercises in C -- but I just feel like they're exercises. I know obviously I'm not going to become an expert right away and start doing amazing things. I just want some ideas for things I can do to help me become better but that feel like more than just exercises. (I want to clarify that I'm not opposed to doing these kinds of tasks to help me learn about the language. I just think I'd get more excited about learning if I was doing something that seemed more practical in nature.)
If this is "not a real question," I truly do apologize, and I know questions about learning C are all over SO. I'm not trying to be repetitive. I'm sold on the idea that I should learn the language, I just want to be able to have some real ideas of how I can start applying the knowledge.
See Also
What is a good first C app to build, besides “Hello World”
Here's some ideas for you to try:
Store a file containing hashes of every file in your music directory, and report on changes.
Solve a Sudoku in the shortest possible time.
Send a file using TCP to another computer. (Write both server and client).
A program that broadcasts a list of public files (configured in a text file) over UDP, and then accepts TCP connections to download them.
A command line POP3 client.
Write a memory allocator, and hook into malloc.
Congratulations on deciding to learn C. It is the most powerful language on Earth, and will give you the foundation you need to kick some programming butt.
The way to learn C would be to try out POSIX compliant samples from any operating system book.
My seven step guide to finding something code wise to do :)
find something you like or enjoy(preferably IT related)
find a problem with it, or some way to improve it, else goto Step 1
split the problem into logical parts, these will represent functions and structures, use a piece of paper if it helps you visualize the problem(this is what I some times do)
devise your plan of attack, ie: how will you implement what you came up with in Step 3
Code, Learn, Test, Learn, Debug, Learn, Improve, Learn and Code & Learn some more
Done, but not really, this is when you review what you've made, marvel in all its glory, and learn from all its mistakes and problems. see what parts you enjoyed, what parts you hated and what parts you can still learn more from.
goto Step 1, using the knowledge gained from Step 6 (and all the other steps along the way)
If you run out of things to do and want to be productive in a commercial sense, see if you can talk to people who work with computers/IT systems/etc as a daily occurrence in their job and see what happens them and try develop ideas that could improve their productivity and/or the ease with which they can perform their task(s), who knows, you may end up with some extra knowledge and some extra cash
See what are the things you enjoy doing in real life and try to use them in an application. For example if you like games, try to make a game or if you need an idea, remake a classic. If you like accounting, try to make an accounting application with a proper interface. If you are not passionate about the idea, then you'll probably get tired after a while and throw it away.
BTW, I think you're on a good path and I like the decisions you have made so far.
Write a compiler for a subset-of-C.
There are some Artificial Intelligence competitions that are both practical and fun. These will help you learn the language, encourage your understanding of any sample code, basic debugging and implementation of common algorithms.
Most importantly it's fun, so it keep will keep you motivated to keep learning.
For instance a few months ago I enjoyed the Google AI challenge: http://csclub.uwaterloo.ca/contest/
Good luck and enjoy :)

Which has a better code base to learn from: nginx or lighttpd?

Primary goal is to learn from a popular web server codebase (implemented in C) with priority given to structure/design instead of neat tricks throughout the code.
I didn't include Apache since its code base is an order of magnitude larger than the two mentioned.
Ngxinx might just be the best straight-c code-base I have encountered. I have read large chunks of Apache, and I always came out feeling unclean, it is a monolithic mess.
You will not just learn about web-servers by exploring Nginx, but pretty much the best practises for writing networked software under Unix and straight-c, from code architecture to meta-programming techniques.
I have heard nothing but good things about Lighttpd, however it is limited in scope compared to Nginx. therefore I would invest time in nginx if I was you. Although lighttpd's limited scope might be beneficial to you, as a first target to study.
Neat tricks always happen in any codebase worth its salt, to be honest. Nevertheless, the answer you probably don't want to hear is that it would probably be good to study both so you can kind of learn through the intersection. The alternative might really leave you stuck in a box of the "lighthttpd" way or the "nginx" way, etc.
I didn't include Apache since its code base is an order of magnitude larger than the two mentioned.
Actually Apache code is quite readable. It has large code base because it does lots of things. But it is well structured and quite easy to understand. You can also check APR library (Apache Portable Runtime) which has plethora of small things to learn from.
IMO if you want to learn programming, you should start with lower profile projects - and not HTTPd, but something simpler.
Both nginx and LightHTTPd (just like Apache) are production quality software, meaning very steep learning curve. And the learning unfortunately often means digging archives to see why it is that way - that comes with age to any mature project.
If you are simply into C and learning design, you might want to check the FreeBSD or its derivatives. In my experience it is a better place for starting: there are lots of tools and libraries of all calibers there. And their TODO lists are never empty, what serves well as a guide to where to start.

What's the easiest way to Create a User-Friendly front end for a C program on Linux platform

I have a small course project that would best have a user-friendly front end.
It's a network sniffer, I coded the program with C and Linux. And now I am hoping to make it more ``user-friendly".
In c: Getopt
In c++, if relevant: Boost program options
Try to behave like other programs (at the very least provide a useful --help message, and print some sort of simple usage description for invalid arguments). I find the easiest way to understand how to use a program is when its manual page, or even --help message gives examples of common usage cases.
If by user friendly you mean you want to make a gui for it then I would definitely recommend GTK. GTK is one of the more widely use Xserver tool kits and it is written in C. Another plus is that it is written in an object oriented manner. IMO being exposed to how OO programming is accomplished in C is a great thing for all CS students.
If your sniffer has a command line front end, have a look at Eric S. Raymond's The of Unix Programming. In chapter 10, there's a whole section on how to name and format your command line arguments. There's also a POSIX standard for utility syntax.
These approaches won't directly make your program user friendly, only research on your users and analysis of your interfaces will help with this. However, providing an interface that works in ways that users expect will certainly help.
Im no expert in UI Design, or anything in that matter, but taking an interest in the quality of User Interface Design, I came across Aza Raskin, an interface design expert that is head of design for Mozilla Labs. I have followed some lectures and conventions that Aza has done on UI Design, and he said something that is simple, yet makes more sense then anything I have ever learned with UI Design...I may butcher it but its along the lines of
If The User has to think about the design,then it is a bad design
This may seem like an insult to everybody's intelligence, but it makes sense. Something that is user friendly cant be ambiguous to the user. This means that when a user is performing some task/operation, the UI should be presented to them corresponding to the current event or situation.
The UI should be designed so that anybody who picks up your software should be able to navigate through it. This DOESNT mean that they should understand the underlying problem domain, but it does mean that if asked to find a certain functional part of the software, that they could generally navigate themselves there.
Some things to things to think about when using your software:
1) -Do you ever ask yourself, "Do I go here or here?
2) -Do I use tools like bold fonts and italicizing to show emphasis?
3) -Am I sacrificing anything by making certain features "idiot proof"(Read Below)
4) -Am I trying to do too much anywhere just to save time(programming time)
These are just some things that can help straighten out some of your design decisions. In no way is this following any pattern. Like I said, my education in this field is minimal, it is just an interest I have followed.
Regarding #3, It is important that you don't sacrifice any feature or design decision when implementing certain accommodations. If you have something where 99% of your users are using a certain feature, but 1% can be expected to make a different decision, then take this into consideration. Don't sacrifice the design for the 99% of the users to accommodate the other 1%. This doesn't mean don't accommodate the other users, I just mean don't sacrifice the integrity of the design.
If you don't need to interact with the app "live" or only need limited interaction as a command line app then you can write a frontend using PyGTK. If you need to access C libraries then you can use Cython to load and call them.
But regardless of what you choose, be sure to find a professional interface designer. A bad interface can destroy the potential popularity of any app.

Resources