Archive

Archive for the ‘Dev’ Category

youtube powered video gallery and isometry

June 29th, 2011 1 comment

Are those two related? They may not be. (They might be; who knows?)

Even so, I wanted to try out some isometry. You know, get some stuff displaying and sorting. That sort of thing? Big news: I did it! :D

 

That’s all for isometry, on to youtube powered video galleries!



  • http://www.youtube.com/watch?v=L5JHMpLIqO4
  • http://www.youtube.com/watch?v=VG82USg5mtE
  • http://www.youtube.com/watch?v=-jMruFHTwrY
  • http://www.youtube.com/watch?v=zxK8y7XuEu8
  • http://www.youtube.com/watch?v=ADBKdSCbmiM
  • http://www.youtube.com/watch?v=28sAsvzMW6s
  • http://www.youtube.com/watch?v=V-24m-KRkn0

 

That’s one I made quickly. It works like this:

First you have some HTML.

<ul class="video library">
	<li>http://www.youtube.com/watch?v=L5JHMpLIqO4</li>
	<li>http://www.youtube.com/watch?v=VG82USg5mtE</li>
	<li>http://www.youtube.com/watch?v=-jMruFHTwrY</li>	
	<li>http://www.youtube.com/watch?v=zxK8y7XuEu8</li>	
	<li>http://www.youtube.com/watch?v=ADBKdSCbmiM</li>	
	<li>http://www.youtube.com/watch?v=28sAsvzMW6s</li>	
	<li>http://www.youtube.com/watch?v=V-24m-KRkn0</li>
</ul>

 

Just throw the Youtube URLs into a list and add the classes video and library to it, and that’s all there is to the HTML! (Well, there’s some minor javascript to include).

 

<link href="http://www.gigglingcorpse.com/dev/video-gallery/style.css" rel="stylesheet" type="text/css" media="screen" />
<script src="http://www.gigglingcorpse.com/dev/video-gallery/video-library.js" type="text/javascript"></script> 
<script src="http://www.google.com/jsapi" type="text/javascript"></script> 
<script type="text/javascript"> 
		google.load("jquery", "1");
		google.setOnLoadCallback(function() {
			videofy();
		});		
</script>

 

I included the Javascript file for you know doing stuff, as well as CSS file for some basic formatting. It makes use of JQuery, which i’ve included by way of Google’s JsAPI (out of laziness). And then when everything has loaded, there’s the one call to videofy().

After that, the list gets converted into the video gallery you should see above!

Thank you for your time.

Categories: Dev, Uncategorized Tags:

PHP functions

May 16th, 2011 3 comments

I sometimes find writing regular expressions of any complexity difficult. That’s true, though it would be more accurate if I’d said always.
It’s not because regular expressions themselves are difficult (though there is a lot to remember, or look up), but it can be so easy to make mistakes and so difficult to find those mistakes in that confusing mass of characters.

Eventually I give up and make a dedicated PHP file just to test the regular expression against various inputs. In fact, I have done the same with other functions to ensure that they do what I expect them to.

And you know what they say: If you’ve done something more than once, and will probably do it again, why not automate it? And if you can’t automate it, make a tool for it. There’s even the more appropriate: Make a web-tool for testing functions with arguments.
(I have no idea if those are real saying or not.)

I like to listen to people and what they say, and so that is exactly what I did: http://gigglingcorpse.com/dev/phpfunctions

Here it is in iframe, although it doesn’t really fit:

Rock, paper, scissors, bots!

March 22nd, 2011 3 comments

This Google AI challenge thing seems so neat, and like it’d be fun! Because who doesn’t like bots??

A couple of nights ago I made a rock/paper/scissors bot arena. You can make bots using Javascript and have them compete.
It seemed like it’d be fun to make, and who knows, maybe it’ll trick some people into trying out some easy programming since it’s all web-based.

It’s a little weirder than normal Javascript, but that’s because the code gets wrapped into an object before use:

 
function bot1() {
 
	this.name = "Random (from array)";
 
	// Actual bot code starts here
 
	this.ROCK = 0;
	this.PAPER = 1;
	this.SCISSORS = 2;
 
	/**
	 * This is the deciding function for your bot.
	 * It should return ROCK, PAPER, or SCISSORS.
	 **/
	this.evaluate = function() {
		var values = [0, 1, 2];
		// Pick a random element in the array
		return values[ Math.floor( Math.random()*values.length ) ];	
	}
 
	 // And ends here
}

There are a couple of special functions:

  • this.evaluate = function() gets called when it’s time for the bot to throw down.
  • this.opponentPicked = function( v ) (if it exists) gets called with your opponents choice for the game that’s just finished.

A good example of the opponentPicked function is the Watcher bot.

this.ROCK = 0;
this.PAPER = 1;
this.SCISSORS = 2;
 
this.memory = [0,0,0];
 
/**
 * This is the deciding function for your bot.
 * It should return ROCK, PAPER, or SCISSORS.
 **/
this.evaluate = function() {
	var total = 0;
	for( var i=0; i < this.memory.length; i++ )
		total += this.memory[i];
	var po = Math.floor( Math.random()*total );
 
	for( var i=0; i < this.memory.length; i++ )
		if ( po > this.memory[i] ) {
			po - this.memory[i];	
		} else 
			return (i+1)%3;
	return 0;	
}
 
/**
 * Let's you know what you're opponent has picked.  
 * This gets called after evaluate.
 * @param int v
 */
this.opponentPicked = function( v ) {
	if ( v >= 0 && v < this.memory.length ) 
		this.memory[ Math.floor( v ) ]++;
}

There are a bunch of example bots anyway. Just don’t try this is going to be bad!

Categories: Dev, Uncategorized Tags:

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.