Archive for the ‘video games’ Category

JavaScript Haxagon Game Board with Hexagon tiles

Thursday, August 27th, 2009

I’m working on a JavaScript version of The Settlers of Catan. The first problem I decided to tackle was constructing (visually and array-structure wise) the game board using nothing but loops (didn’t want to hard code it).

This ended up being much more difficult than I thought it would be.

I am going to split this up into two parts:

1. Setting up the game board visually
2. Setting up the array structure

Creating a Hexagonal game board with hexagonal spaces in JavaScript with for loops:

For this to work properly, you must have an even number of columns and rows. I chose seven since that is what makes up the Settlers of Catan game-board.

You have to split the building of the board into three stages:

1. The expanding stage
2. The apex or middle of the board
3. The contracting stage

I placed everything in one large for loop that counted off the “rows”.

I figured out that while the rows are less than half the max rows divided by two (and rounded down) the board would be contracting. The number of tiles you would start with would be equal to the maximum number of tiles divided by two, rounded up, plus the current row number.

Once the number of rows equals exactly half the number of maximum tiles (rounded down) you are on the middle row. In this case the number of tiles is the max number of tiles, no math required.

Otherwise, you are in the contracting stage and the number of tiles you need is equal to the maximum number of tiles, minus the current row, minus half of the maximum rounded down.

Sound complicated? That’s because it is. This took me about 30 minutes to get straight in my head after studying the game-board shape, tiles, and making several diagrams and sudo-coding and then writing the actual code and fixing bugs (and deciding if I had to round up or down at certain places).

Here is the actual code:

<html>
<head>
<style>
img{
	margin-top: -18px;
}
#board{
	padding: 50px 25px;
	background-color: #000;
}
</style>
</head>
<body>
<div id="board">error loading</div>
</body>
<script>
function boardSetup(){
	var max = 7;
	var html = "";

	for(var row = 0; row < max; row++){
		if(row < Math.floor(max/2)){
			//place spacer tiles
			for(var space = 0; space < (Math.floor(max/2) - row); space++){
				html += '<img src="spacerTile.png" />';
			}

			//place game tiles
			for(var cols = 0; cols < (Math.ceil(max/2) + row); cols++){
				html += '<img src="tile.png" />';
			}
			html += "<br />";
		}else if(row == Math.floor(max/2)){
			for(var cols = 0; cols < max; cols++){
				html += '<img src="tile.png" />';
			}
			html += "<br />";
		}else{
			for(var space = 0; space < (row - Math.floor(max/2)); space++){
				html += '<img src="spacerTile.png" />';
			}
			for(var cols = 0; cols < (max - (row - Math.floor(max/2))); cols++){
				html += '<img src="tile.png" />';
			}
			html += "<br />";
		}
	}

	document.getElementById("board").innerHTML = html;
}

boardSetup();
</script>
</html>

Here are the images that go with it:

Here is the tile:tile
Here is the spacer. This one is completely invisible: start->spacerTile<-end

Here is the code running on my site.

Other M

Thursday, June 4th, 2009

So, I know this blog has been leaning more towards serious development than flash game development recently. But if you pay any attention to www.chomperstomp.com (you shouldn’t) you will know that the last game I developed was a Metroid clone. Which might give you a hint at how I feel about Metroid. I love it. It was the first video game I ever bought, and I’ll be a Metroid fan till I die. It’s right there behind Zelda and in front of Mario and Mega Man, which are all embraced in the loving arms of Double Dribble…

So, that said, and without further ado, I present to you (as if you hadn’t already seen this from reading PA or just having an appendage flaccidly placed in the vicinity of the pulse of video game culture) Metroid:Other M.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHWSOME!!!!

Christian Video Games

Tuesday, June 10th, 2008

If I ever have time to make another video game (it will be a while) I want to make one like this:

http://www.nintendo8.com/game/165/spiritual_warfare/

Yes, by today’s standards it’s lame. But at the time it (to me) was awesome. A Christian Zelda clone. It doesn’t get any better than that.

The concept is so simple. Run around converting people to Christianity with the fruits of the spirit, the armor of God, and learning about Scripture to increase your faith.

I played this game for maybe a week as a kid (until I had to give it back to the person I borrowed it from) and I retained a TON of what I learned about the Bible because of it. I’d love to see a modern Zelda clone version of this game…

Anyone know of any good Christian Edutainment that puts fun before education like this one does (and therefor actually gets you to play it, and then you actually learn from it)?