Archive

Posts Tagged ‘Flash’

Chromatic Restitution!

December 13th, 2010 No comments

Chromatic Restituion

Last Game Demo Festival (GDF4, if i’ve decremented correctly) I thought up a neat but simple game idea, and my implementation was truly terrible. The result? A submission known as Worst Game Demo Ever (WGDE) which shames me even today.

The problem was of course laziness.
At least some representation of physics was important to the design, and I had a very specific use of sound in mind. Without those it wasn’t so much a game demo, and very much wasn’t the one I’d intended.

I tried again with GDF5, but decided to try a physics library and settled on Box2d for flash. It wasn’t as difficult as I’d expected! I’m happy with how using it turned out. There were some strange issues that were almost definitely due to my misuse of the library, but avoidance solved those as it does most things.

In order to add a certain potential for complexity, each x position was to play a different note on collision. I totally (sorta) accomplished this using frequencies, sine waves, and the SampleDataEvent. For consistency in representation, the sound generated is stereo – loudest on the side it’s closest to (this is not the case in the example below).
Click the grey box below and then hit keys to play sounds:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

 

Once sounds and physics were basically implemented, I added the import game-elements including and consisting solely of an ability to accrue points. The point system works as follows:

	var coeff = 1;
	var bonus = 0;
	var base = 10;
	switch( e.value ) {
		case 2:
			coeff = 1.2;
			break;
		case 1:
			coeff = 1.4;
			break;
		case 0:
			coeff = 1.6;
			bonus = 5*(++explosionChain);
			if ( ballPool >= maxBalls )
				ballPool++;
	}
	var p:Number = base*coeff+bonus;
	points += p;
	dispatchEvent( new GameEvent( GameEvent.SCORE_CHANGE, points ) );
 
	// Make it harder
	if ( points > 25 ) {
		maxBalls = 2;
	}
	if ( points > 100 )
		maxBalls = 3;
	if ( points > 200 )
		maxBalls = 4;
	if ( points > 350 )
		maxBalls = 5;
	if ( points > 600 ) {
		maxBalls = 6;			
	}

Pretty simple! The more times you hit a ball, the more points you get. If you eliminate a ball, you get a bonus proportional to the length of your elimination-chain (the number of balls you have eliminated in a row).
At certain score levels, your number of maximum balls in current play increases. If the number of balls in the ball pool is greater than or equal to that value on an elimination, a ball will be added to your ball pool. This is done so that players can’t simply eliminate the last one ball over and over.

 

So that is Chromatic Restitution! It’s closer to what I’d wanted, and I am happy with the result.

Of course there are some things I wish I’d added but forgot with the distraction of ever decreasing distance to deadline. Additional sound events would have added texture: wooshes when you miss a ball, some sort of triumphant ring when you eliminate one – that sort of thing.
Particles or some other animation on elimination, or even bounce (sparks) would have been nice. In general more colours, lights and sounds and movement. Casinos have taught me people love those things.

Karl added an OpenID thing to the GDF library. I attempted to add it to the GDF Overlay prior to my submission, but failed and was too tired and confused to worry about it. That would have been a nice addition as well.

GDF 5 Submission

December 11th, 2010 No comments

So, I’m too tired from programming to talk much about it at the moment, but here is
my GDF 5 submission, entitled Chromatic Restitution.

Categories: Dev, Personal, Uncategorized Tags: ,

Tic Tac Whatsit

December 8th, 2009 3 comments

Long days ago I spoke with a dentist of game demos, and of a festival dedicated to those. We talked of Ticktacktoe, a classic game of boxes and shapes – a boring, beatable game, but an easy one to program.
It’d be easy to program, right? We could probably make one with flash in less than thirty minutes, couldn’t we? At least one way to find out!

Yup. Sure could!

Ticktacwhatsit is made up of nine (9) blocks, and each can be either blank, an X, or an O. That’s so easy to represent in flash!

I started by making a symbol called called block which had two layers and three keyframes on one layer: blank, X, and O. On the other layer, i added the action stop(); to prevent it from flipping through the frames.

I dragged 9 instances of block onto the stage, and arranged them into a game board (named them in sequence) – and drew some lines between them.

And then I wrote the game code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var boxes:Array = [ b0, b1, b2, b3, b4, b5, b6, b7, b8 ];
var nextSymbol:int = 0;
 
removeChild( done );
done.addEventListener( 'go_again', restart );
 
function restart( e:Event ) : void {
	nextSymbol = 0;
	for( var i:int=0; i < boxes.length; i++ ) 
		boxes[i].gotoAndStop( 1 );
	removeChild( done );
}
 
for( var i:int=0; i < boxes.length; i++ ) {
	boxes[i].addEventListener( MouseEvent.CLICK, onClick );
	boxes[i].buttonMode = true;
}
 
 
function onClick( e:MouseEvent ) : void {
	if ( e.currentTarget.currentFrame == 1 ) {
		e.currentTarget.gotoAndStop( nextSymbol+2 );
		if ( checkGame() ) {
			trace( 'won!' );
			done.gotoAndStop( nextSymbol + 1 );
			addChild( done );
		}
		nextSymbol = (nextSymbol+1)%2;
	}
}
 
function checkGame() {
	for( var t:int=0; t < possible.length; t++ ) {
		var val:int = boxes[possible[t][0]].currentFrame;
		for( var i:int=0; i < possible[t].length; i++ ) {
			if ( boxes[possible[t][i]].currentFrame != val || val == 1 )
				break;
			else if ( i == 2 )
				return true;
		}
	}
	return false;
}
 
 
var possible:Array = [
		[ 0, 1, 2 ],
		[ 3, 4, 5 ],
		[ 6, 7, 8 ],
 
		[ 0, 3, 6 ],
		[ 1, 4, 7 ],
		[ 2, 5, 8 ],
 
		[ 0, 4, 8 ],
		[ 2, 4, 6 ]
	];

So the main idea is that we have a bunch of boxes and whenever one of them gets clicked, we may have to do something. I added each of the boxes to an array (line 1), so I could easily loop through them all (line 14), and set the buttonMode and add an onClick event handler to each. A true buttonMode tells flash to display the little hand when you mouseover the object.

The main processing is done whenever you click a block, and the onClick event handler starts on line 20. That’s really all there is to the game, the rest of the stuff are just extras.

The mouse event is passed as a param to the event handler. Its currentTarget property represents the object clicked, which in this case is one of the blocks.
The first test to do on that block is see if it’s empty. If it’s not empty, there’s nothing for us to do.
A block is empty if it is still on its first frame, which is where currentFrame comes in. If it’s not on its first frame it’s either an X (frame 2) or an O (frame 3).

If it is empty, I need to either fill it with an X or an O, whichever wasn’t used last. For this, I have the nextSymbol variable, which is only ever either a 0(X) or a 1(O). I set the block using its gotoAndStop function, passing it the frame we wish it to change to.

After that, I just check if a player has won!
I was pretty lazy about checking; I made a list of every possible victory combination (line 46), and check each of those (line 32) to ensure all the squares in each aren’t on the same frame, or on frame 1 (line 36).

Done!

Line 28: I wonder why I did nextSymbol = ( nextSymbol + 1 ) % 2; instead of nextSymbol ^= 1; Laziness?

BCAC concept

October 5th, 2009 1 comment

Last night i sent in a concept for the new BCAC website, here’s a screenshot:

The header is a slideshow, images drop down from the top. I did that guy for free because I thought it would help. I am a nice guy nbd.

Categories: Business Tags: ,