Archive

Archive for the ‘Dev’ Category

Codepaste 2 and Google Chrome: friends at last?

May 14th, 2010

Codepaste2 displays correctly in Chrome! Finally!

In Opera, Safari, Firefox, and IE everything was great; in Chrome things went so very wrong: lines would wrap, lose opacity, and display behind themselves. Code was super difficult to read.

But now it works! And, to be honest, I’m not sure why. I updated the version of EditArea it uses, and didn’t see a change. When I switched its allow_resize option from both to y everything magically got better. I was pretty happy. But then I changed y back to both and things didn’t get worse, which left me confused and a little scared.

I hope the issue was resolved by updating EditArea, and all the confusion was caused by some weird caching issue. Or maybe I forgot to refresh?

Codepaste v1 still gets heavier use than Codepaste v2. I wonder if that is by conscious decision, or if people just don’t know about Codepaste v2 and how much better it is.

Codepaste, Dev ,

Counter example!

December 14th, 2009

So there’s this website that let’s you convert regular image files into icons. You’ve probably seen it before, maybe used it once or twice. It has a donate button, which allows donations by way of Paypal. That button is there for one reason, and one reason only: to prove Karl wrong.

You see, he once posited that no one ever donates. And now, finally, after all six of these months and 100978 icon conversions, someone has. An entire American(USD) cent, and all the way from Italy. I mean sure, it may have been a mistake. I might even concede that it probably was a mistake. Either way, it’s a counter example!

Theory disproven.

Bradicon!, Personal, Uncategorized

Tic Tac Whatsit

December 8th, 2009

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?

Dev, Uncategorized, being helpful to people less experienced than myself in the ways of the world; mostly in the ways of the web actually , , ,

btw

September 25th, 2009

I removed the project wonderful advertisement from Bradicon. Shaun once called it a failed experiment, and he was right.

Oh, and I decided averaging groups-of-days on that graph was misleading. Why would I average them? That doesn’t make sense.
Now they are summed but no longer divided.

Bradicon!, Uncategorized