[CH05] Santa Sleigh Race
miran

This was supposed to be nice little arcade race game where you race reindeer drawn sleighs against up to 5 computer controlled santas on many different challenging courses. I didn't have time to implement half of the features I planned so it turned into something quite different. The two most important things I didn't write were collision detection and artificial intelligence, so I turned the game into a multiplayer on one computer hotseat one at a time type of game. Also there is only one track and it isn't very good.

Here's the full source and Windows binary (~850 kB)! Source compiles in Linux as long as you have Allegro 4.2 and DUMB installed.

Should I finish it? Is it worth it?

Screenshot:
http://ferisrv5.uni-mb.si/~ma0747/graphics/screen_ssr.png

Billybob

I always suck at these race games. I gave it a try but quit after running into the snow on every turn... :P

Quote:

Should I finish it? Is it worth it?

Go for it!

miran

Heh, I already had to fix a couple of major bugs. Version 0.71 is now uploaded.

Sorry Mark for getting a buggy christmas present. When you're running out of time as I was, you inevitably miss even the most obvious bugs... :P

Quote:

I gave it a try but quit after running into the snow on every turn... :P

Yeah, that tells a lot about the gameplay. Santa's sleigh just isn't fun to drive. Too much understeer... :P

Jonny Cook

Well I pretty much suck at it. Cool game though, I'm going to have a look at the source. I learn the most from simple games like this.

miran
Quote:

I'm going to have a look at the source. I learn the most from simple games like this.

Please don't. This was hacked together and when it didn't work, it was hacked even more until it did work. I'm not proud of my code.

Steve Terry

It's a nicely done game, just need a smaller turn radius, shouldn't be too hard to fix the steering.

miran
Quote:

just need a smaller turn radius, shouldn't be too hard to fix the steering.

Turn radius depends on your speed. The faster you go, the bigger the turn radius. If you stand still, you can actually turn on the spot. Useful hint: you need to slow down for the turns :)

Matthew Leverton

I've driven a team of reindeer before, and trust me it is hard to turn corners with them. I think it's spot on.

miran
Quote:

I've driven a team of reindeer before

:o:o:o

Onewing
Quote:

Should I finish it? Is it worth it?

Yeah, go for it. As of now, I think it's well-polished demo, more so then you let on via the CH thread. My best lap time was 1:42 and something seconds. :)

OICW
Quote:

Please don't. This was hacked together and when it didn't work, it was hacked even more until it did work. I'm not proud of my code.

Reminds me my code of Revenge of Frosty. Since I will have relaxed I'll try your game, it sounds good.

Murat AYIK

I like games without a "Game Over" message:) My only problem was the trees inside the road, I wasn't expecting them. Also cruising southwest and reaching santa with the radar's red dot was interesting
:P

Jonny Cook
Quote:

Reminds me my code of Revenge of Frosty. Since I will have relaxed I'll try your game, it sounds good.

He asked nicely...

miran
Quote:

My best lap time was 1:42 and something seconds.

My best is around 1:25 :)

Quote:

My only problem was the trees inside the road, I wasn't expecting them.

That was on purpose ;)

Quote:

Also cruising southwest and reaching santa with the radar's red dot was interesting

Eh? You went into the void?

Quote:

He asked nicely...

Look at the code all you like, but don't try to learn from it, that's what I meant. Unless you want to learn how not to make a game. Well, actually the framework is OK I suppose, but the game itself is a hack (game.c, track.c, player.c, deer.c, sleigh.c, etc).

Murat AYIK
Quote:

Also cruising southwest and reaching santa with the radar's red dot was interesting
Eh? You went into the void?

I earned this bad habit while trying to find all the easter eggs in large games. Even when I know nothing special will happen I still enjoy it(oh my God, what have they done to me?!)

And some trivia: When I tested your game, the music I heard was cool but nowhere related to christmas. Also it kept playing after I closed the game too. Then I figured out it was a web page with a Flash game which completed loading just the moment your game's menu appeared:-/ It was one of the "build a world adding stuff in the right order" games in offtopic.

Felipe Maia
Quote:

It was one of the "build a world adding stuff in the right order" games in offtopic.

That's called Grow.

EDIT:Miran, your game looks pretty good. Just make sure the next race it's not better to go off the road than in road to win :)

miran

What road? ??? There is no road in my game...

Murat AYIK

Maybe a closest_point_on_line check can turn those lines into road borders, where your speed decreases when you ride (road_width/2) away from the nearest line.

miran

You're missing the idea. All you do in that game is go from one checkpoint to another. There are no roads or anything like that. The red and blue lines are just guides that show you the shortest way to the next checkpoint.

Felipe Maia

Then why not just put the checkpoints in the map and remove the lines?

miran

Because they are guides that show you the shortest way to the next checkpoint.

Felipe Maia

Then your game is broken, cause I didn't go trough them a lot of times and made a 1m31s lap(meaning that I must have skiped some checkpoints)?

miran

Hmm, looks like you're right. You found a bug! A big one! :D

Matthew Leverton

It works great. Everyone knows the best part about racing games is figuring out a way to cheat the track. Finding ways to cheat on Micro Machines for the NES (awesome game) made me feel great.

Jakub Wasilewski

I remember an Amiga racing game (top-down view) where you could cross the finish line, then go back, cross it again to score another lap, and so on until you finish the race :). What was it's name... Carnage?

BAF

Pole Position from the Atari... plus you have the modern remakes of it and those little games you plug into the tv that have older games on it.

Thomas Harte

Well, I've started porting the various ChristmasHack entries to OS X, and have attempted Santa Sleigh Race as my first.

I had to make two changes to the code to reflect the different file structure expectations of an OS X program (i.e. one icon representing a bundle) compared to Linux/Windows (i.e. lots of files thrown into a directory completely visible to the user) and the work already done within Allegro to help with that. At the top of load_track in track.c, I substituted the following:

#ifndef ALLEGRO_MACOSX
  get_executable_name(path, 1024);
  TRACE("exe: %s\n", path);
  replace_filename(path, path, file, 1024);
  TRACE("track: %s\n", path);
#else
  strcpy(path, file);
#endif

Very similarly indeed, I modified init_framework in framework.c to:

#ifndef ALLEGRO_MACOSX
DEBUG
  /* Construct aboslute path for the configuration file. */
  get_executable_name(config_path, PATH_LENGTH);
  replace_filename(config_path, config_path, "allegro.cfg", PATH_LENGTH);

DEBUG
  /* Construct aboslute path for the datafile containing game data. */
  get_executable_name(data_path, PATH_LENGTH);
  replace_filename(data_path, data_path, "game.dat", PATH_LENGTH);
#else
  sprintf(data_path, "game.dat");
  sprintf(config_path, "allegro.cfg");
#endif

As I'm no artist whatsoever, I've just reused the Windows icon. OS X likes to have a 128x128 icon around, but I've done nothing about that.

A compiled version, alas slightly too big to attach, is available at http://members.allegro.cc/ThomasHarte/osx/SantaSleighRace.zip. I still don't trust that the Allegro XCode template is embedding the Allegro framework, so this binary may require Allegro to be installed. I need to look into that more properly as it affects every binary I release.

The only thing I noticed that seemed odd about the game is that if you start a new game and press up/down without any prior attempt to turn then the sleigh moves straight up and down the y axis. Possibly something isn't initialised somewhere?

Other than that I found it to be quite fun, if very difficult. Would it not be possible to move the camera out a little?

Billybob

If only I had OS X in VMWare...

Matthew Leverton
Thomas Harte said:

I still don't trust that the Allegro XCode template is embedding the Allegro framework, so this binary may require Allegro to be installed.

I prefer just using the command line for this.

# make -f makefile.linux
# cd ..
# fixbundle SantaSleighRace -e

Then, go into the Resources folder, create "SantaSleighRace" (same as executable name) and copy all the data files in there. The changes you made to the source obviously still apply.

I also manually copied the icon file (after creating it with Icon Composer) into the Resources file and updated the plist file accordingly. I think fixbundle is supposed to be able to do this, but it never worked for me.

If you want to compare my bundle with yours: SantaSleighRace

Thomas Harte
Quote:

Then, go into the Resources folder, create "SantaSleighRace" (same as executable name) and copy all the data files in there.

Oh, I've patched my copy of Allegro so that I don't have to live with its stupid internal folder naming. So that's one obvious area in which our application bundles vary. Otherwise I note you have the framework embedded whereas I definitely do not, and I'm following that observation up in the correct forum.

miran

Mac OS X is confusing :P

Thomas Harte
Quote:

Mac OS X is confusing

Well, I'm annoyed now because Firefox 1.5 has once again decided that switching from one tab to another means the tab switched to should be reloaded - throwing away my post. It's a good thing I'm not a violent man or I might not have a computer any more.

Anyway, blah blah blah OS X is very straightforward and easy for the end user, bundles make a lot of sense but Allegro is confusing.

A bundle is just a hierarchy of folders and files - like any other folder in the filesystem - except that it is graphically represented to the user as a single icon and if you double click an application bundle then the binary at a particular place in it is launched. Most frequently OS X applications come as .DMG files, which are virtual disk images. You mount the image (by double click), drag the included application bundle to wherever you want to keep it (usually /Applications - some DMGs come with symbolic links to /Applications in them so that you only have to drag the icon about two centimetres even if the other convention of whacking icon sizes up to full size in DMGs is followed), then unmount the disk image (drag the drive to the trash or right click and select eject) and, probably, throw the DMG into the trash too. To uninstall you drag the application bundle to the trash.

Also not uncommon is to see applications distributed as .zip or .sit, which are usually just the application bundle in a more traditional archive format. In the Mac world .sit was a de facto standard before they realised that they weren't somehow masters of the universe able to live in their own bubble with their own standards, etc.

It isn't just applications that are bundled. Ordinary data sometimes is also - for example XCode projects are. So rather than the VC6 collection of a .dsw, a .dsp, a .ncb, etc, you just see one "file" in your project directory.

Bundles are not an OS X invention. They were in NextStep and, presumably independently as both arrived in 1989, RISC OS. Due to their NextStep heritage they also exist in GNUstep. Because the folder conventions are preserved, it would be perfectly feasible to produce an Allegro based fat binary that supported both GNUstep and PPC OS X out of the box as long as you didn't rely very heavily at all on any other common APIs being in place. OS X does retain a lot of its NextStep heritage, e.g. the base class for applications is still NSApplication, the thing representing a bundle is still NSBundle, and most things other than specifics of the widget set are carried over. My guess is that Intel OS X will expect to find its application binary in the same place in the bundle as you'd place an intel GNUstep though, so this possibility probably won't hang around for very much longer.

In a sense the Application framework provides a third option for linking. Frameworks are essentially similar to DLLs and SOs (albeit better at versioning) and may be dynamically linked against as you'd expect. If you build a BSD style lib<whatever>.a then you can statically link against that. But you can also dynamically link against a framework and then include it in the bundle. That gives the usability advantages of static linking in that the user doesn't have to install any special frameworks or in any other way maintain multiple "files". It also means that a competent user could update the embedded framework with a newer version if they chose, so brings LGPL compatibility.

Allegro has been a confusion. As you see, Matthew prefers to use the commandline and does a reasonable amount by hand. I prefer to use XCode, the Apple |DE. As it turns out the project template provided by Allegro doesn't embed the framework even if you've built it to be embeddable. You'll see I've posted instructions to fix that to the Installation, Setup & Configuration forum + a substitution project template for users of XCode 2.0 or above. Now, when I press XCode's build button (or hit command+b!) it does everything necessary and leaves me with a perfectly formed bundle - no manual copying or editing of anything. So the process is really as simple as it could possibly be.

To Matt:

As you're at the commandline, have you performed

export MACOSX_DEPLOYMENT_TARGET=10.2
export NEXT_ROOT=/Developer/SDKs/MacOSX10.2.8.sdk

And added -L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 to your linker somewhere so that you aren't just building for whatever version of OS X you have and upwards?

Matthew Leverton
Quote:

As you're at the commandline, have you performed

No, I was unaware of any such options.

However, I think I am on gcc 3.3 via gcc_select. (I should be, unless I switched back to 4.) That's all it takes with Allegro to get it backward compatible with older versions. I know Peter Hull has an older version of OS X, and he was able to run my programs that were compiled with GCC 3 (but not 4).

Thread #555208. Printed from Allegro.cc