Archive

Posts Tagged ‘Games’

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 , , ,

Set 1: There may be bugs

September 21st, 2009

A game called Set, to which I was recently introduced, got me thinking about algorithms. A lot.
In particular, set finding algorithms.

I found in myself the desire to program a set player, but what use is a set player without a game to set? It is of little use, my friend.

Here’s an example with a single human player. Mouse over it to enlarge.

Next step? Write a player and get shaun to write one – AND MAKE THEM COMPETE.

Dev , , , ,

!Victory is mine

June 10th, 2009

Guys, I lost and it wasn’t even close. Here is the scoring breakdown:

Game Art/Presentation Completeness Fun
Pizza Deliverator 4 4 4
Save the princess 4 2 4

Each category was scored out of 5, giving Shaun 75% and leaving me with a humiliating 62.5%. I am heartbroken and a little ashamed.

My demo actually failed the completeness category. A surprise to me, but as more played I discovered an alarming trend. They would replay over and over, thinking that if they were just a little faster they could save the princess.
I would not have thought the art-style lent itself to envisioning a romantic rescue and the sharing of a final, however doomed, kiss. A failing on the part of my ‘art’ abilities.

Saving a princess is a convention so common as to raise in me a certain apprehension, and on seeing the princess the impossibility of her rescue should have dawned with some clarity. But this, I believe, was prevented by a lack of visual details. A better picture might have successfully shown her as long dead.
The “Oops, too late” message was also confusing, though meant as a joke.

In my mind, the demo was game-play complete (it was supposed to be basically reverse-pong). There were some small visual effects I would have liked to implement. Most were trivial or better, subtle, though one final animation would have marked the ending more effectively.
I would have liked the player-character to walk from the screen (left), a pause, and for the princess to lift her head and open her eyes and perhaps her mouth to signify her growing hunger for human flesh.

Oh, well.

Uncategorized , ,

Save the princess, she is feeble

June 8th, 2009

I can tell from the hurtful lack of emails and comments that this past week without update has been noticed by most of you. I can explain. And this isn’t just one of those explanations meant to stall for time and an opportunity for escape. It is that, but also nothing more.
There were a lot of things to be done after coming back from Victoria this past weekend. Most interesting being a second game demo contest with Shaun Kiernan, to be judged by his girl-friend’s sister’s boy-friend Richard.

Once long ago a similar competition resulted in Prawnager’s Nightmare (which can be found somewhere in this blog’s past). That time, we had a month. This time, we had only a week.

The limited time forced me to leave bits and pieces I’d have rather included out. Smoke does not rise from points of fire and destruction in the distance. There is no in-game restart, null-opt rich menu, or title screen. The player animations are limited and few. And the princess. I had only ten minutes or so to draw the princess. Which is why she is in silhouette. Unfortunately it was anything but clear over the dark, looming mountains which hints at explanation for the gross gradient.

Oh, well. It was submitted with only three minutes to spare. And I think it looks pretty cool.

Also, I really like the way I handled parallaxing, code-wise.

The demo is here. It’s of reasonable size, so it might take some time to load.

Art, Dev , , , , ,