csanyk.com

video games, programming, the internet, and stuff

Review: Pitfall! & Pitfall II: Lost Caverns

One of the most popular and successful games on the Atari 2600 was Activision’s Pitfall!, designed and programmed by David Crane. A proto-platformer, it featured running and jumping adventure in a jungle setting. Coinciding with the iconic blockbuster movie Raiders of the Lost Ark, released one year previously, it was arguably better at capturing the fun and spirit of an Indiana Jones adventure than the official Raiders videogame released by Atari.

As Pitfall Harry, you explore a jungle and found treasures such as gold, silver and diamonds, while avoiding obstacles and deadly animals drawing inspiration from Tarzan and Indiana Jones, such as snakes, scorpions, and crocodiles. Due to its brilliant technical execution which pushed the limits of the 2600 hardware, Pitfall! was one of the top titles of its era, and is still remembered fondly by retro gamers today.

Pitfall! gave us running and jumping, and swinging on vines, but didn’t really have platforms per se. There’s just two elevations to run along: a flat ground level, sometimes with holes to jump over, or vines to swing on, and an underground level, sometimes with ladders and holes connecting the two. The jump mechanic was a bit primitive, and limiting, compared to later platformers — Harry can only jump up or forward, and once you press the jump button, he always jumps the exact same height and distance, and he cannot change course in midair. While this limits the type of platforming action the game can offer, it was nevertheless enough to create an enjoyable, challenging game. A bit monotonous, perhaps, compared with later Super Mario platformers that would follow a few years later, but if we look to Mario in 1981, his jumping physics were also limited in much the same way.

The way the underground level relates to the above world is strange and mysterious. Pitfall! doesn’t scroll, so when Harry runs past the edge of a screen, the game advances one screen and we find him in a new “room”. But when he crosses the edge of the screen while underground, he advances several screens. Thus, the underground is a potential shortcut, allowing Harry to skip over screens and bypass the challenges there, hopefully to pop up closer to the next treasure. This isn’t really explained to the player, who has to discover it and puzzle through it on their own.

As well, Harry can run both left and right, and it’s not entirely clear which direction he should run — due to the direction of rolling log obstacles, it seems to be the intent that you should run to the right, jumping the logs as they approach you. But it’s a bit easier to run left, going with the flow of the logs — and there are treasures to be found either way. These ambiguous choices of this helped give Pitfall! a depth and replayability it would not otherwise have had.

The sequel, Pitfall II: Lost Caverns, released in 1984, was equally well-received, and in a number of ways was an even greater technical feat. In this installment, we to get see Pitfall Harry swim, and catch a ride on a balloon, and a larger variety of dangerous animals that Harry must evade. There’s even dynamic background music that plays throughout the game, changing situationally — pick up a treasure and the music becomes happier and more adventuresome; get injured and the music turns sad. Go for a balloon ride and hear a bit of circus trapeze music. By 1984, games were starting to come with soundtracks, but this sort of dynamic music was still years ahead of its time.

The game also features an innovative waypoint system that replaces “lives” — you can fail as much as you need to, but the game won’t end; instead you’ll be returned to the last checkpoint you touched, and resume from there. In virtually all games up to this point, games granted the player a number of lives, typically three, and allowed extra lives to be earned somehow. Pitfall II was one of the earliest, if not the first, to do away with this, and allow the player to explore and take risks without the threat of a “Game Over” ending the fun. Decades later, this checkpoints without lives system has became a preferred method for making difficult platformer games that aren’t excessively punishing or unnecessarily frustrating.

There were a number of other games released in the Pitfall series on other consoles, but after the disastrous 1986 NES port, Super Pitfall, I had lost interest in the franchise and moved on to other things, so I never played any of the other games.

Of the two VCS titles, most fans seem to prefer the second. But while I do find it to be the more technically impressive of the two, I find that I prefer the original. I feel that Pitfall II suffers a bit from repetitive sequences where you have to pass the same enemies an excessive number times. Toward the end of the game, you have to climb upward while evading level after level of condors, bats, and scorpions — and each enemy requires near-perfect precision. Make a single mistake and you go all the way back down to the last checkpoint. There’s something like 20 creatures in a row that you have to run under, and it’s frustrating and tedious. There’s no other way to get past them — no ducking, no shooting, just time your run perfectly and get under them, or jump over them, and if you screw up even once, it’s back to the last checkpoint to start over. This has always struck me as poor design, rather than a fun challenge, so I’ve always felt like the original had the superior design, even if the sequel may have had a lot of cool, innovative features.

Still, both games are among the best made for the VCS, and are historically significant innovators that established and advanced the platformer genre

Ludum Dare 36 is at an end

Ludum Dare 36 is officially over with the close of the feedback phase tonight — a bit anti-climactically, as there was no ratings given this time around. Only comments were given, through the new Feedback Friends site.

The ratings system was given a rest as it’s been decided by the powers-that-be that it isn’t working any more, and has more problems than it was worth. But I really liked to have a quantifiable method of comparing my games to others, and seeing my progress from compo to compo. Of course, I fully understand that the numbers are highly subjective and that the ratings shouldn’t be taken seriously, for many reasons (judges being biased, judges not being able to cover the entire competition, etc.) but none of that really mattered to me.

I would have really loved to have known how Ancient Technologies would have done in the rankings if they had done them this time. While I think the lack of originality in creating a simulation in homage to Atari 2600 Asteroids likely would have hurt it overall, I think it would still have fared decently as a well-crafted interactive experience, and done considerably better than my previous submissions in many categories.

I hope they have a new and improve rate and rank system in place by LD37. The most important thing about the rankings system was that it made it easier to find good games. No matter how many times I sift through the submissions, I always miss some great games. I know because I always find out when the rankings come out and I look through the top 10 or 20 games, find some titles that I never spotted even when I looked through every page of submitted games, and invariably these are pretty well done, the 48 or 72 hour creation time notwithstanding. I did find a few games that I felt were well worth playing, some of them truly great, but I’m sure I missed many others, and that’s too bad because without the ranking system, I don’t know how else I’ll find them.

As for the comments, I gave 85 comments, earning me 163 “coolness” points, and an overall balance of 105 coolness; the top-ranked coolness game on the Feedback Friends site had 121 net coolness, so I feel like I was pretty cool this time around.

I figured out that a comment’s point value basically varies by 1-3 points, depending on its length. Follow-up comments on an entry where you’ve commented already earn you 0 points, no matter how long they are, so they’re encouraging you to review as many games as you can, but not to have lengthy conversations with any one creator. To get the most credit for your feedback, then, your first comment should be a long-ish, multi-paragraph length. A quick one liner will only get you 1 point; a few sentences will give you 2 points.

My game Ancient Technologies received 37 comments, all of which were very favorable, and I think objectively speaking this game was my best-made effort I’ve created to date. I think a lot of LD48 reviewers are just naturally friendly, encouraging, and generous when leaving comments, and are reluctant to say that they don’t like a game. Even when I’ve played a game that was just terrible, I often see many positive comments and compliments. But I, for one, think that if there’s a problem with a game that it should be talked about honestly. Otherwise, feedback only serves to stroke the ego and doesn’t help you get better where you need to.

I get bug reports pretty reliably, which is very good; but if something sucks, people don’t seem to be willing to say that. If there’s serious design or implementation problems beyond a simple bug, people don’t seem to be forthcoming with that kind of criticism. If the game crashes, or if some feature described in the game description doesn’t work, or if there’s an obvious glitch with the sound or visuals, I’m sure to hear it; if I just made a game that sucks, wasn’t well designed or implemented, or wasn’t very fun, people don’t want to say that.

I guess that it’s refreshing in a way, considering how oftentimes comment sections are cesspools of abuse, and I’m not saying that I want to see abusive comments on my games; but I would definitely appreciate if players who give feedback on my games cared about them enough to offer suggestions on how to make them more fun, and to do that by pointing out a problem with the game and a proposal for how to fix it, wouldn’t be bad. Even if the suggestion isn’t one that I agree with, I’d rather hear that. Better some negative points than all positive encouragement, yet empty of criticism.

 

Top plays from Ludum Dare 36

In no particular order, here are the best-made games that I’ve played from Ludum Dare 36 so far…

Anachroma by Zillix

Anachroma by Zillix

Anachroma is a delightful puzzle platformer where the puzzles are defined by the topology of the level and the rewards are color-based, and unlock more new puzzles. I really got into this one.

Cognizance by Managore

Cognizance by Managore

Daniel Linnsen’s done it again, with a fantastic platformer mechanic involving a rotating gear wheel that can climb walls and interact with its environment to power treadmills and other cog wheels in order to move platforms and solve puzzles.

Canoe and Spear by BluShine

Canoe and Spear by BluShine

This is a fantastic single-screen death match, basically a tiny Towerfall: Ascention with a unique canoe paddling mechanic. Toggle left/right arrows to paddle/steer, and fire a spear with the Z or X button. Up to 4 players can play head to head, or you can play vs. AI. Built in PICO-8.

Invent the Wheel by Delicious Code

Invent the Wheel by Delicious Code

This simple game is surprisingly fun and addictive. All you have to do is draw a circle, and the resulting shape will roll down a hill. The faster it rolls down the course, the better your time. The more round the shape is that you draw, the better it will roll. It also seems to help to draw as large as you can.

Supercontinent LTD

Supercontinent LTD

A point and click mystery that you solve with a little hacking and social engineering via telephone. Great atmosphere and mood created by the graphics and sound, and the dialog system is fantastic as well.

The Leak by cabbage_

The Leak by cabbage_

A little adventure/RPG that you can play on a real Game Boy(!!)

Old Man’s Sky by Geared Games

Old Man's Sky

A parody of No Man’s Sky, or a de-make in the style of the Atari 2600, Old Man’s Sky pretty well skewers No Man’s Sky for being a pointless game about infinite sameness, as you go from world to pointless world, exploring and finding only differently colored versions of the same old stuff, over and over again. Never do you encounter anything truly interesting, nor does anything really happen. Still, it’s oddly beautiful, in its own way.

Kites by VitasaMode

Kites

A beautiful homage to Missile Command, set in ancient China. Fire rockets to stop a never ending flock of kites. The kites don’t seem to do any harm, other than if you let the blue ones fly over your city, you lose points. And if you accidentally hit a red one, you also lose points. The art direction is very nicely done.

Review: No Mario’s Sky/DMCA’s Sky

In my last post, I talked about the recent copyright and trademark infringement takedown actions initiated by Nintendo against No Mario’s Sky and various other games hosted on GameJolt.

Here’s a review of No Mario’s Sky/DMCA’s Sky.

No Mario’s Sky was made in a weekend for Ludum Dare 36. It is a mashup of Hello Games’ No Man’s Sky and Nintendo’s Super Mario Bros. The theme for Ludum Dare 36 was Ancient Technologies. It’s unclear how this game relates to the theme. However, due to the popularity and familiarity of Mario and No Man’s Sky, the game got quite a lot of attention in very little time, and was picked up by websites such as Kotaku and Polygon.

The premise of the game is that Mario is looking for the Princess on an infinite series of procedurally generated 2D Mario worlds. The worlds wrap around a circle, giving them the appearance of planetoids. Once you’ve satisfied your curiosity on one world, you can summon your spaceship and take off in search of another world. Apart from the color scheme of each world, there’s not all that much to differentiate them, which may be due to the game being developed in just 72 hours, or may be a deliberate commentary on the procedurally generated sameness that many players of No Man’s Sky have complained about.

No Mario's Sky

From a Mario standpoint, the game only borrows the titular character, the goomba enemy, and the basic concept of jumping on platforms and enemies, collecting coins, and hitting platforms from below. No sprite artwork is taken from Nintendo’s games, as all sprites and tiles appear to have been re-created by the ASMB development team, and while the Mario and Goomba characters are recognizable, they are not in any way confusable with Nintendo art assets. There are is no brick breaking, no super mario mushroom, no star man, no fire flower. Again, this is likely due to the compressed schedule under which the game was created. Each world plays its own variant of the Super Mario Bros theme music, which is again a re-done composition, not the original music ripped from the Nintendo game.

In short, from a copyright infringement standpoint, this game is in a gray area, but pretty safe, in that nothing is actually copied directly from the Nintendo games. This game is about as much a Mario ripoff as KC Munchkin was a Pac Man ripoff. (Atari successfully sued Philips to stop the sale of K.C. Munchkin, even though the game was not Pac Man, but the case was bullshit and probably would not have succeeded were similar suit brought today.)

If ASMB had avoided use of the Mario name, perhaps renaming him something recognizable, like “Mustachhio”, say, and if the music had been done in a way that was recognizably Mario-eque without khaving the same melody, probably Nintendo would not have had any copyright leg to stand on, and the game could have remained as-is. From a trademark standpoint, though, it probably does run afoul of Nintendo’s trademark on the Mario Bros. franchise, given that it uses the Mario and Goomba name.

While the game is fairly bland as-is, the concept is certainly fun and held promise. Were the game to be developed further, to better incorporate the Mario characters and play mechanics, it could have been a lot of fun.

DMCA’s Sky removes the Mario and Goomba artwork, replacing them with a generic space man and alien, and the music has also been replaced, but otherwise the game is much the same. Interestingly, the jupm, coin and 1up pickup sounds remain recognizably Mario, but again do not appear to be direct rips from original sources.

DMCA's Sky

I suppose Hello Games could also make an IP infringement claim if they wanted to, and force the game to remove the procedurally generated planet hopping, at which point the game wouldn’t have much left in it anymore. Notably, so far at least, they haven’t.

It turns out, though, that when you break down just about any video game into its fundamentals, pretty much every game is based on, or borrows from, concepts that came from some other game. And — this is the important thing that must not be lost sight of — concepts are not subject to copyright. Only actual works are copyrightable.

Despite this, much of the charm of No Mario’s Sky was in its mash-up-ness, and this charm is effectively stripped from it by removing the Mario references. So clearly, the game derives some value from referencing the source material that it is based on. I don’t think that can be denied. I have a harder time seeing how this game harms either Nintendo or Hello, however. It was available for free, not for sale. It isn’t reasonably mistake-able for a real Nintendo game, and if that were a risk it could be prominently disclaimed on the title screen that it was not in any way connected to Nintendo, who retains full ownership of the “real” Mario characters. I see little evidence that the existence of this game or the numerous other Nintendo-IP infringing games done by fans over the years (including ROM hacks, homebrew games, de-makes, and homages) has in any way diminished the Nintendo brand or harmed Nintendo as a business.

The takedown of unauthorized fan games isn’t anything new — it’s just the latest in a string of consistent defenses of Nintendo’s IP rights. It’s clear that Nintendo is aggressive in protecting their IP rights, and have always been. This has been in part due to their corporate culture, but also in larger part due to the nature of IP law. We could as a culture elect to shape law differently, if we could agree to.

Nintendo’s takedown of videos on youtube and elsewhere, of people playing their games who do not participate in or follow the rules set forth by Nintendo in the “Nintendo Creator’s Program” is ridiculous — it’s not a copyright infringement for me to play a video game, or to talk about a videogame, or to record me talking about a videogame while playing it, and footage of said videogame that I create should legally be my sole creation (while the characters owned by Nintendo and other IP-holders are still retained by those holders).

If I want to make a video of a videogame for purposes of review, criticism, or parody, I shouldn’t have to obtain the permission of the IP rights holders of the videogame, nor should I have to share revenue with them. They earned their revenue already through sale of the game, and did none of the work to produce the video, so why should they be entitled to a share of revenue generated by the video?

Likewise, if I want to make a videogame that references other videogames, much as a work of literature may reference other works of literature, creators should have some right to do so. Exactly how this should work out so that the original creator’s rights are protected and respected isn’t very clear, however. Ultimately, the power seems to fall to those who have the deepest pockets with which to pay the most and best lawyers. As as a result, the culture, and the game playing public, is poorer for it.

Mario on iOS, Nintendo copyright takedown

Nintendo announced the first (authorized) appearance of Mario on iPhone a few days ago:

There’s much to be made of this.

Ten ago, while the Wii was selling phenomenally well, there were some wild rumors about Nintendo and Apple teaming up to bring games to the Apple TV device. But, while tantalizing, these rumors never panned out, nor really made sense. While both companies were extremely successful on their own, they didn’t really seem to need each other, or have any reason to cooperate. Nintendo software licensees could have certainly helped put Apple TV in many more homes, but what could Apple have offered Nintendo, who weren’t having any trouble selling the Wii?

Fast forward to 2016, and the successor to the Wii, the Wii U, is widely regarded as a misstep for Nintendo, and now it appears maybe they do need some help. But rather than looking for it in the living room, where they are poised to launch their next-generation NX console in a few months, right now they are going straight for the pocket. Meanwhile, Apple’s huge hit from 2006, the iPhone, has been a juggernaut for much of these last ten years. And here is where Apple and Nintendo can help each other out.

It’s the first time in decades that Nintendo has put software out on a platform that it does not own. This could be seen as a concession that Nintendo is no longer dominant in gaming hardware, or simply an acknowledgment of the vitality of the mobile gaming market. While Nintendo have been hugely dominant in the handheld market since they released the Game Boy in 1989, smartphone and tablet devices have in the last decade created an even bigger market for games. With the massive success of Pokemon Go earlier this year, the writing was on the wall, and Nintendo making this move now only makes sense. In fact, it’s probably overdue.

Entitled Super Mario Run, it appears to be an endless runner type game rather than a typical 2D platformer. Due to the iPhone touch screen being the only controls, and a desire to make the game playable one-handed, this design addresses the constraints imposed by the user interface in about the only way that would work well.

Nintendo also made headlines this week by issuing takedown notices for a large number of unauthorized games that infringe upon Nintendo-owned trademarks, particularly Mario and Pokemon. It is not surprising at all that this should happen, but still disappointing for people who built or enjoyed those games. While many of these games may have been derivative and inferior games done in homage of, some were parodies or innovative or just fun, well done fan homages.

It’s too bad there doesn’t exist a legal framework in which fan-made games can co-exist peacefully with official releases by commercial studios, but licensing is only a solution if the IP-holder embraces it. Nintendo are within their rights to take these actions to protect their trademark and intellectual property rights, of course, and perhaps it is necessary for them to vigorously defend their trademarks or risk losing them entirely, but it’s nevertheless possible to set up a legal framework by which these unofficial games could be allowed. While it’s entirely ridiculous in my opinion for Nintendo to claim copyright and trademarks on speed run, Let’s Play, and review videos featuring their products, something like the Nintendo Creators Program would make a lot of sense for fan-produced games.

What might such a program look like? I would propose something like the following…

  1. The fangame creator would acknowledge that Nintendo created and owned whatever they owned.
  2. The fangame creator disclaims that Nintendo do not have any responsibility for content the fangame, and that the fangame is not an official Nintendo release.
  3. Any revenue derived from the fangame would need to be disclosed and shared with Nintendo.
  4. The fangame could be nixed by Nintendo (pulled from release) at their sole discretion at any time.

I very much doubt that a company like Nintendo would ever agree to such terms, but it’s too bad. Apart from perhaps Nintendo, everyone is worse off because of it.

The irony of this situation is that Nintendo can copyright and trademark its characters, but not the mechanics or genre of game. (Nor should it.) Someone can invent the infinite runner, and Nintendo can decide to do a Mario infinite runner game, and not owe anything to the inventor of the infinite runner game. So can anyone else. And Nintendo can make a running and jumping platform game, and anyone else can too, duplicating the Mario mechanics and rules system entirely if they should wish to, but simply can’t use the name Mario or the likeness of any of Nintendo’s graphical or audio assets.

GameMaker Humble Bundle – super cheap and source code too!

GameMaker Humble Bundle pay what you want, but for just $15 you can get licenses for GameMaker: Studio Professional and the ability to create games for HTML5, Android, iOS, and Windows UWP, which together normally cost several hundred dollars. The total value of the entire bundle is $1885, making this one of the best value bundles I’ve seen in the history of the Humble store.

Additionally, you can also get a number of commercially released indie games that were built in GameMaker, and for a few of those games, you even get the source code. It’s very exciting to be able to look at source code written by professionals to see how it’s done. Titles offering their source code include: Extreme Burger Defense, Freeway Mutant, Shep Hard, Angry Chicken, Galactic Missile Defense, Uncanny Valley, Ink, 10 Second Ninja X, Cook, Serve, Delicious!, Flop Rocket, Solstice, and Home.

The sheer cheapness of this giveaway leads me to wonder whether the release of GM:S 2.0 may be immanent. Time will tell. In the mean time, this is a spectacular value bundle and well worth buying for the project source alone.

GameMaker Marketplace new checkout system now allows direct downloads!

Yesterday, 9/7, I noticed a big spike in downloads of my GameMaker Marketplace assets. I also happened to notice when looking around on the Marketplace that they’ve changed the checkout so that you can download the .gmex files directly through your web browser, bypassing the My Library interface in the IDE.

As I’ve remarked several times in the past year, My Library is crippled by terrible performance when the user’s purchase manifest exceeds some number that is far too low. Allowing purchases to be downloaded directly through the browser makes a lot of sense, and is probably the simplest solution to the performance issues, which still plague GM:S as of 1.4.1760.

It remains to be seen whether this spike in downloads will be sustained as the new normal, or represents pent-up demand for users who were reluctant to buy due to the poor performance of My Library. Despite the seeming smallness of this change, I’m really excited that YoYoGames have made it, as it alleviates a significant pain point that I’ve been complaining about for well over a year, and means that I’ll likely be making more use of extensions in my projects.

Graph showing sales spike on 9/7/16. Could this be due to the change in delivery method?

On 9/7, 18 downloads. The other spike earlier in August was due to my Ludum Dare 36 sale, when I put my paid assets on sale for $FREE

Update: 9/8 saw another 18 download day.

Tutorial: GameMaker Object with multiple collision zones

GM Version: GameMaker:Studio 1.4 (concept should work in earlier versions)
Target Platform: ALL
Example Download: https://csanyk.com/cs/releases/games/LD48-36_AncientTechnologies/LD48_36_Ancient_Technologies_csanyk.gmz
Links: http://ludumdare.com/compo/ludum-dare-36/?action=preview&uid=10473

Summary:

How to make an object that handles multiple collision zones by using multiple sub-objects

Tutorial:

I used this technique in my recent Ludum Dare game, Ancient Technologies. The project has a TON of extraneous code in it, some of which is pretty messy, so I’ll replace the download link with a cleaner example project of just this technique in coming days.

If you look at the Atari 2600 console in this game, it is actually multiple objects, made to look like a single object. This enables each switch to have its own collision detection and mouse events.

I accomplished this with a few simple techniques that work really well:

The console itself is the main object. Then there are 6 objects for the 6 switches on the console.

I then took the image I wanted to use for the sprite, and cut out all the different clickable regions, putting each into its own subimage by itself. Then once all the subimages were created, I removed each subimage into its own sprite, and set the collision mask to cover just the pixels in the image

Atari 2600 clickmap sheet

As you can see, this approach results in a lot of “wasted” space in the sprite sheet in the form of transparent pixels, but if you’re concerned about this, you could always achieve the same effect by using sprite origin and sprite offset to position the images without all the whitespace in the sprite sheet. I skipped using sprite origin because I didn’t feel like bothering with counting pixels and setting each sprite origin differently. That would have been tedious, and if I had ever needed to change the sprites, could have thrown everything off and required extensive rework to recalculate again. If your sprites are tiny, it probably doesn’t matter too much, but if they’re quite large, then you should probably use sprite origin/offset.

(Note: With the small pieces, you’d need to use origin numbers that are larger than the dimensions of the sprite itself, or possibly negative values for the origin. You’d also need to carefully calculate the distance to set the origin so that the images all line up precisely. The goal is to make all the images align when each instance’s x and y are identical. This makes them easy to move around together as a group, without having to deal with offsets and so on. To make everything align easy, I created sprites that have the same height and width, so that getting them to align takes no extra effort or calculation at all.)

Next, use the “main” object to generate the collision zone objects, in the create event:

Note the example code below isn’t exactly the code in my project, but is cleaned up a bit for easier comprehension.

///oConsole Create Event:
power_switch = instance_create(x, y, oPowerSwitch);
tv_type_switch = instance_create(x, y, oTVTypeSwitch);
left_difficulty_switch = instance_create(x, y, oLeftDifficultySwitch);
right_difficulty_switch = instance_create(x, y, oRightDifficultySwitch);
select_switch = instance_create(x, y, oSelectSwitch);
reset_switch = instance_create(x, y, oResetSwitch);

Since these objects all use sprites that are the same size, they all line up together when their x,y position is the same. Now you have an easy way to place just the main object and have it create all of its collision zone objects, perfectly aligned.

If the main object needs to be able to move, you just need to update the x,y of all the objects whenever you need to.

Another great thing is that each of these instances can have its own animation which is completely separate from the rest of the collection of objects. This means you can do really sophisticated animation rigging.

Also, you can access the instance variables of the collision instances by using the main instance, like so:

oConsole.power_switch.position = UP;

is (essentially) equivalent to:

oPowerSwitch.position = UP;

This allows you to use the collision zone instances’ instance variables like you would use properties of a helper class in another language, which may make accessing these variables easier if you’re used to other programming languages.

As well, if each of these switch instances were of the same object, using the id returned by instance_create() would allow you to differentiate between them. This could be useful for, say, a battleship with multiple turrets that are all of the same object type.

Finally, you’ll want to be mindful that if you destroy the main object, you’ll likely want to destroy all the sub-objects. Perhaps not — maybe you’re doing a spaceship with an escape pod or a rocket with multiple stages that break away. But in that case you’ll wan to be sure that once the main object is gone, you are handling whatever remains somehow.

Managing complexity when implementing complex conditionals

Programming is in large part about managing complexity and imposing structure onto a problem domain in order to make it simple (simple enough for a machine to be able to do the solution, as well as simple enough for human programmers to be able to build it).

Something struck me about a technique that I used when I was developing my game last weekend.

The code that handles the setup of the simulated atari 2600 console is full of conditionals like this:

if PowerPlug.is_plugged_in && (console.switch_power.position == POWER_ON) 
 && (TV.switch_power.position == POWER_ON) && Cartridge.is_plugged_in && 
 Joystick.is_plugged_in 
{
 //simulate the game 
}

So one thing that I had to deal with as I was building this was all the preliminary stuff’ you know, to create all the objects that needed to be checked in the conditional statement above. Rather than do that, all at once, and have a lot of conditions that could have bugs in them, any one of which could make the thing not work, and be hard to figure out since multiple bugs could end up canceling each other out, or mask one another in some way, I opted to simplify things at first:

if true
{
 //simulate the game
}

The advantage here is obvious. It’s simple, and you KNOW that conditional is always going to evaluate to true! So you can get right into working out the code inside the branch, without worrying for now about the conditional logic that would cause it to execute.

Once that was working, I added in stuff:

if PowerPlug.is_plugged_in
{
 //simulate the game
}
else
{
 if PowerPlug.was_plugged_in_previously
 {
 kill_game();
 }
}

Then from there it became easier to elaborate on the conditional:

if PowerPlug.is_plugged_in
{
 if Console.switch_power.position == POWER_ON
 {
 //simulate the game
 }
}
else
{
 if PowerPlug.was_plugged_in_previously
 {
 kill_game();
 }
}
 
//etc.

(Note, the above isn’t the exact code from my project, which is a bit messy at the moment as I have some refactoring to do, but it illustrates the point.)

I found that by coding it in this way, I could iterate and test each little piece of the logic easily, and make sure it was working before trying the next piece.

I found that doing it this way made it much, much easier to handle the complex nested if business, and as well I found it easier to know which branches of the complex conditional tree the next bit of code needed to belong in.

Now that I did it this way, it seems obvious, nothing of great insight… but 6 years ago I would have tried to code the whole thing out, and then pulled my hair out swearing at myself when it didn’t work as expected, and I had to untangle all the logic to figure out wtf it wasn’t working.

Back I would have thought then that a really superior version of me who I aspired to be would be able to code out all the conditions in one go without making a mistake. Today a really superior version of me knows better.

This is a good lesson to hang onto. And to pass on.

Of course, there’s also often ways to avoid having to code conditionals at all, but that’s a topic for another post.

csanyk.com © 2016
%d bloggers like this: