Red Danger (Game) (Composition by Tap5a)

Author: Tap5a
License: (unknown)
Date: 2010.10.19
Compatibility: 10.5, 10.6
Categories:
Required plugins:
(none)

I did this for my software studies course assignment. We were supposed to use Processing but I wanted to try making some interactive piece with Quartz Composer.

It uses Image Pixel patch for collision detection. I realized it's really not a good way to do it because it's so slow but it works somehowly. So if somebody knows a better way to do it I'm more than happy to know :D

PreviewAttachmentSize
Red Danger.qtz45.5 KB

benoitlahoz's picture
Re: Red Danger (Game) (Composition by Tap5a)

This is very addictive !

It runs at 60fps on my MBP 13" (only motherboard graphic card). Did you try using the HitTest tou find in the private patches ?

gtoledo3's picture
Re: Red Danger (Game) (Composition by Tap5a)

This runs very quickly on my MBP as well (+60fps).

I didn't look at it too much, mainly played it, but I will suggest that using the stock core image kernel where you are using a gaussian to work around the RII bug will possibly be slightly quicker since all it does is perform a color change. You can always take out the color change portion of the kernel and just use it to pass image, which would possibly be even faster.

The place where you stand to gain most optimization is in the pixel test, as you note. You can "downsample" the image you send your Image Pixel test by a 1/2 or 1/4 and then correct for it w/ the math you have going on with the Rendering Destination Dimensions. You can do that by placing a lanczos scale transform, an image resize, or even another clear/ render in image/ billboard macro that downsamples in between your Red Circles and Edges macro and Collision Analyze. This may make things slightly less accurate, technically, but if objects are sufficiently large (eg., a few pixels in w/h) it may speed things up and not impact game play.

That iterated grid may be taxing on older computers. It is an extra step of rigamorole but it may be better on performance to place the iterated grid macro in a Render In Image patch with a sample and hold on the output, which would then connect to a Billboard.

At the start of the composition, the sample and hold would be set to sample the iterated grid image, then the interpolate (or whatever) would trigger sampling to false, at which point one would set something else up to shut off the iterator. I would tend to think that the cached image would be less taxing on older machines, but iterator is pretty optimized for this type of thing in SL. Then, you would setup a macro to make it so that when Rendering Destination changes (someone changes window size), Sample and Hold flips back on, as well as the iterator.

That's all theoretical, and may not optimize, but would be things to possibly examine and test. Great classwork!

psonice's picture
Re: Red Danger (Game) (Composition by Tap5a)

Cool, pretty fun game! I really love how playing these in safari enables the cheat mode too ;D

My method of doing collision detection for this type of game worked like this: (I've note looked at your .qtz, apologies if this is similar/worse to what you've done :D )

  1. Render the whole game board (minus player sprite) in image
  2. Crop a small area that lies under the player sprite (this gives you the area of the map covered by the player, much better than a single pixel in the centre)
  3. Use a CI filter to detect collision object colours. So in this case, it would output white if it detects red, or black if it detects the white background.
  4. Use the area maximum patch to get a single pixel showing the max colour. This is now white if there's a collision, black if not.
  5. Use image pixel to get the collision state.

First two on this page should have something similar: http://psonice.untergrund.net/games.html

dust's picture
Re: Red Danger (Game) (Composition by Tap5a)

this is fun... i got to about two hundred points with the arrow keys and couldn't do much better with the mouse. see pic for my high score. might be kind of cool to add some sort of gun or maybe after every 100 points you turn red for ten seconds or something so you don't die. after 300 points it gets crazy would be nice to get a reword and chillax for a few seconds before you die ? just a thought.

PreviewAttachmentSize
red.png
red.png57.1 KB

Tap5a's picture
Re: Red Danger (Game) (Composition by Tap5a)

Thanks guys for your comments and great ideas for optimization and future development! Oh and yes it seems that Image Pixel patch is not working inside browser... I'm not (yet) very deep in Quartz Composer so how do I get access to private patches?

BTW my high score is 443 and I've deal with my class that if someone gets over 550 I'll offer free pint but that might be little hard over internet so you just get big respect :D

psonice's picture
Re: Red Danger (Game) (Composition by Tap5a)

There are 'safe' and 'unsafe' patches in QC, and only 'safe' patches will work in quicktime or safari. Everything will work in QC itself or in an app that uses QC.

The 'unsafe' patches are basically the ones that could potentially pose a security risk - i.e. you wouldn't want a patch that can read files from disk, and a patch that can send information to the internet, working together, in your browser. It'd be possible to search for bank details and upload them to a criminal's webserver. Quite why image pixel is unsafe I don't know, maybe it's possible somehow to read pixels from outside the qtz rendering area?

If you really want to use these unsafe patches in the browser, you can get a plugin from here on kineme.net (can't remember the name, but it's bound to have 'unsafe' in the name somewhere). Just remember that installing this opens up your computer to a bunch of security risks, so only use it if you have to. It's safe to use say on a machine being used for an interactive museum exhibit that's not on the internet, but perhaps not for your own mac :)

usefuldesign.au's picture
Re: Red Danger (Game) (Composition by Tap5a)

My highest score was hands free while I was hovering over the nodes in Editor to read the code! About 280. PPC doesn't seem to slow this down enough to be easy, adjusting smooth might make it easier so there is less of that 'asteriods' momentum slide ;-)

BTW there's an QC Asteroids one of the first comps I ever saw and thought oh this Quartz Composer paradigm is pretty cool.

Tap5a's picture
Re: Red Danger (Game) (Composition by Tap5a)

Thanks Psonice for very good explanation about safe patches! Makes sense. This everything is so new to me.

And Benoitlahoz where I can find that Hit Test patch you're talking about?

smokris's picture
Re: Red Danger (Game) (Composition by Tap5a)

psonice wrote:
If you really want to use these unsafe patches in the browser, you can get a plugin from here on kineme.net (can't remember the name, but it's bound to have 'unsafe' in the name somewhere).

We've retired the "unsafe" patches, and rolled that functionality into KinemeCore in a more generic way. Install it, open up KinemeCore preferences, and check out the "Unsafe Mode" tab.

psonice's picture
Re: Red Danger (Game) (Composition by Tap5a)

Hit test is a 'private' patch. These are hidden, secret patches that apple don't want you to use (sometimes because they're broken or only work in a particular case, sometimes because they're not 'final' and may change in a future QC update and break your work). They're often really, really useful though!

To enable them, open the hidden, secret QC prefs (hold down the ALT key while opening the normal prefs). Under the (Editor) options, tick 'reportPrivatePatches'. Restart QC, you should find a LOT more patches in the library.

Tap5a's picture
Re: Red Danger (Game) (Composition by Tap5a)

Wow, didn't now about secret patches. Thanks very much for your help!

dwskau's picture
Re: Red Danger (Game) (Composition by Tap5a)

I was part of a group project for a digital image processing class. We used the concept of this game to produce one played using video as input.

To play find something green you can hold in your hand.

PreviewAttachmentSize
EnemiesFinal.qtz46.2 KB

dwskau's picture
Re: Red Danger (Game) (Composition by Tap5a)

Forgot to upload sounds, put them in the same directory as the qtz.

PreviewAttachmentSize
Sounds.zip102.57 KB