Saturday, September 22, 2007

Flash 9 Dance Dance Revolution

Very simple rhythm game written with help of my existing gemini lib for AS3. Game itself is 270 lines of code, including MXML. This doesn't include the libraries, but the two new classes RhythmTimeline and RhythmKeyframe are only a couple lines each on top of the existing timeline stuff.

Each keyframe has a 'radius', the distance at which a hit is viable. When a key is pressed, I dig through the behind and ahead heaps up to a given max distance (the maximum radius that you use is a good value), to build a list of possibly 'current' ones, and then I go over this list testing absolute distance versus radius to get a final list.

Most of the speed problems are due to the movement of the sprites (and the fact that I'm creating all the sprites ahead of time and not as needed - easy to fix). I really need to steal/write a good parallax scroller to do this for reals. I found when I added a clipping mask to the keyframes I lost like 20x more speed, so I left it out for now.

There are some small issues regarding visual position not syncing perfectly with the audio (it actually IS synced, but the write and flush delays are hurting it), so sometimes it may feel like you're being gypped. Also this song is probably not the best choice is it actually seems to drift in parts (the latter half of the song is almost perfectly mapped).

You can drag to scroll around the music, and hit the "a" and "q" keys on your keyboard to dance with intensity. You may need to click in the browser (anywhere) to get the keys to recognize (I know how to fix this).

Be patient if you have a slow connection, song is just under 3mb and I didn't make a loader.

Enjoy!

Silver Screen Dance

Wednesday, September 19, 2007

Introduction

Hello, welcome to my new experiments blog. Any and all posts before this were made in my livejournal before I had set this blog up. I figured I should have something specifically for code experiments so that it's separate from my personal journal.

Most all of these experiments are Actionscript 3.0+ and built in Flex 2.0+ and as such to view any of the examples, you must have the Flash 9 plugin installed. Some of the examples require additional things (web cams, mics, wiimotes, etc).

I will be posting source code for any of the projects that become mature enough to warrant posting. Source code is available for other examples on request (use at own risk).

Herd of Boxen

FROM http://oizys.livejournal.com/228030.html

Obvious next step

My particle emitter + Papervision3D

PaperVision Test 2

FROM http://oizys.livejournal.com/227760.html

Balls are out

click and drag to move the camera

3D? In my actionscript?

FROM http://oizys.livejournal.com/227335.html

I downloaded Papervision 3D today and started learning it.

So far I've made my own material (ShadedColorMaterial), based on the Lambertian reflectance half of Phong shading, and my own object with its own custom renderer (BoundingCube - has no faces but only vertexes and custom drawn edges).

My first Papervision Tests

You may find the shape/proportions of the object familiar. This is by all means intentional.

Shapes

FROM http://oizys.livejournal.com/226330.html

Last night I wrote a standardized shape baseclass with the important draw() and clone() abstracts and some handling of size/color/line etc, and then moved all my shape scraps to this.
Here is a Gear class which is derives from Star.. and a ShapeParticleEmitter that emits shapes by using their clone(). The joy of this is that you can change the "prototype" object at will and the next particle emitted will be a clone of it in its current state.

I realize there are better Shape libraries out there already (hell there are better Timeline libs out there than mine), but I like the joy of making it and of making it how I invision (plus being able to optimize it).

While digging around looking at flash stuff I found two amazing sites:
Papercritters.com - (here's my first one)

Let Them Sing it for you

Typhoon Evolution

FROM http://oizys.livejournal.com/225735.html

The latest code is a bit of a jump

Things added:

  • LoopedSequence and PingPongSequence (modifying colors globally via ColorTransform)
  • Enemy plane moves, Particle Emitters can now 'house' their particles under another container so that they can move without moving their children
  • Enemy has 4 Emitters, Player has 1 Emitter
  • Collision is now a CollisionParticleAffector, allowing you to collide particles with object sets and particle sets, with event callbacks
  • Emitters now have "ParticleEmitterBehaviors", an example one here is the TargetingParticleEmitterBehavior, making the two side turrents target the player on fire but then not do anything special
  • The mini bomber ships are particles emitted slowly with a Targeting affector that tracks the player.
Click to fire

One minor bug... if you leave the ship NOT firing for a while (like the game is running in another browser/tab) and then you fire - it eats CPU for a long time (will appear frozen). Don't do that... fire a lot... it's okay to not fire for like 10-20 seconds or so at a time.

Exploring more particle fun

FROM http://oizys.livejournal.com/225043.html

I'd gotten a little bored with all the particles moving straight, and while waiting for the motivation for my true ParticleData slice structure rewrite that will allow me true velocity/accel control over parameters, I decided to pursue the other half of particles:

Affectors.

ParticleEmitters now have an Affector stack which can have an arbitrary amount of ParticleAffector objects that evaluate for each particle.

A simple example is wind/gravity/force. This looks and feels awesome even for a simple single affector.

But shmups often have over 50% of the bullets that go no where... why would you fire like this? Why does the fire have to be stupid also? What if the fire actually wanted to kill the player?
It might look something more like this Attractor. In this example, you can hold the mouse down to reverse the attractor (To make a repulsor) - a useful weapon in your arsenal.

Oh and since I programmed all the ParticleAffector objects with the ability to have a 'global' effect or a localized (BASED ON SPRITE SHAPE!!) effect - I can easily contain this. (note, repulsor mode here makes awesome bounce shield like effect).

I think my goal is to make a shmup that makes people invent new curse words and name them after me.

Fresher pls

FROM http://oizys.livejournal.com/224933.html

Ugh sick as hell today for some reason. Forecast for tomorrow: 80% chance of fail.

Comic con was a blast this weekend - special thanks to Matt, Nessa, and Maryssa for being awesome. Special thanks to Rog and 'Rie for containing lols (Mini!).

Over the last couple days here are my advancements:

AudioTimeline Test (click around - the timeline's 'time' is being driven by the sample offset of the song: "out of sync" is an impossibility)

Full particle and collision test (the red dots are what are actually colliding - in this case a full hitTestObject calc for each - not too shabby speed wise, but I have many optimizations in mind)
Try to sneak through the big sweep attack on the last one.

Squeeky Mirror

FROM http://oizys.livejournal.com/224517.html

Cheezy CamPaint app [Requires Connected WebCam]

You can draw on top of your webcam image. Press 'v' to have an opacity slider show up (top left), press 'b' for brush size slider and 'c' for color picker. Number keys 0-9 (top of the keyboard) are quick hotkeys to set brush sizes. Spacebar clears the screen.

The primary purpose of this application is to draw a mustache and then say "It's A ME!". All other usages are not covered by warranty.

circleOfLife()

FROM http://oizys.livejournal.com/224388.html

Simple Instanced Position Test
Basically, the other (not red) objects mark themselves as "instances" of the red on, so that all I'm doing it moving the red one and the rest follow suit (in their own respective coordinate systems). Going to make a couple variations of this class/system and a couple helper instance Arrays to make grids, rings, spirals, etc.

The primary purpose of this is to cut down on the amount of mathwork the system has to do to transform a lot of points that are identical along some form of symmetry.

Imogen

FROM http://oizys.livejournal.com/224033.html

This will probably only hold feigned interest from the Computer Scientists who might read this (including my future self) but I've completed/debugged my new BidirectionalTimeline class, which allows for an impressive number of sequences within a single dimension to be sorted and evaluated in minimal time. The objective is... you have a time position, and you want to know what sequences you've completely passed, which you've not reached yet and which you are on (and where you are along them). Now you want to know this whether you're going forward or backward through time. Now add on that if you skip any arbitrary amount of time that you know exactly how many you've passed over, in which direction and where things lie now.

All in the least amount of time possible.

Now there's probably a better solution than my simplistic one, but I believe there's an inherent value that simplicity adds that is probably worth whatever small speedup there is left to ponder.

The first basic test... 50 sequences and showing you how they are sorted

The real test... 5000 sequences - the lists aren't populated because the Flex list display alone drops the framerate to around 1/50th

The solution? Two Heaps (one sorted by highest end time, one by lowest start time) and a Linked List or Resizeable Array. If you have another idea, I'd love to hear about it.

Oh also, I just watched The Prestige. Crazy awesome film but kinda creepy to think about.

Now with more bitmap

FROM http://oizys.livejournal.com/223205.html

More tests using a bitmap emitter here and here.

This time you can attempt (though futile) to catch'em all. More fun I've found is just holding down the mouse and swatting them around.

making the new BitmapParticleEmitter was about as hard as this:


package
{
import gemini.display.particle.Particle;
import gemini.display.particle.ParticleEmitter;
import gemini.display.particle.ParticleEmitterData;
import flash.display.BitmapData;
import flash.display.Bitmap;

public class BitmapParticleEmitter extends ParticleEmitter
{
public var bitmapData:BitmapData;

public function BitmapParticleEmitter(base:ParticleEmitterData,v:ParticleEmitterData = null)
{
super(base,v);
bitmapData = null;
}

public override function createParticle():Particle
{
var p:Particle = new Particle();
var b:Bitmap = new Bitmap(bitmapData);
p.addChild(b);
return p;
}
}
}

Emmitt Field

From http://oizys.livejournal.com/222886.html

Some particle emitter tests in actionscript 3.

Look, I made a simple lever - this is a simple emitter you can play with

This one might hurt a bit - but it looks pretty ^_^ (the number on the top should tell you it's averaging at 760 particles in existence at once - more than most computers can dish out at 30fps but I'm working on that). It's the same as the first with different default settings.

More to come later.

Waitwhat

I just set up this blog to house my flash/actionscript/flex experiments.
Need to first post the backlog...
(RSS feed)