Wednesday, February 25, 2009

Bounce game

This week I was working on learning and using the physics engine JigLibX. Painful to say the least. I need to be spending my time learning XNA since this is only the third week. No documentation on JigLib and I spent a lot of time trying to figure out the connections between it and the XNA rendering system. I don't have a good understanding of the rendering system in the first place and mix that with a lack of understanding of JigLibX and it was a surprise that I actually got a game done.



In this game the ball is bouncing at a regular rate. The idea is to move the little green dot around and tilt the tiles so the bouncing ball ends up landing on the green platform with the least number of bounces. The ball started in the bottom right corner. One of the biggest time sinks was the fact that there is no hidden surface removal (as you can see in the top right corner platform) and I spent a bunch of time trying to figure that out and didn't get it done. Had to move on. For me the jury is still out on JigLibX, but it seemed like it had a lot of potential, just needed more samples (that included hidden surface removal) and documentation.

If you want the source, send me a message and I'll consider sending it to you.

Wednesday, February 18, 2009

First Full Circle XNA Game

After going through the tutorial last week I decided my best bet was to create a full circle game. That's a game with a main menu, the game, and a game over screen that moves back to the main menu. This is a shot of that main menu (very simple).


There also needs to be some sort of scoring or timing sytem. This will typically end up being the template for the rest of the games from this point forward. I used the art work from the tutorial and created a grid. Then added on model that could move up, down, left and right (only 2d) in the grid. One of the models is spinning and the idea is to move the red model on top of that model with as few moves as possible (looping around the other side is a key mechanic). In the screen shot, pressing the right key will move on top of the spinning ship as clicking the left key will take three moves. Get it?

For a piece of sample code, this is the row column stuff and grid keyboard movement I have written a million times. Maybe I can come back here next time and just cut and paste.

private int rowFromPos(int p)
{
return p / tilerows;
}
private int colFromPos(int p)
{
return p % tilecols;
}
private int posFromRowCol(int row, int col)
{
return (row * tilecols) + col;
}

private void positionXYFromIndex(int idx, ref Vector3 vSet)
{
vSet.X = fLeftX + colFromPos(idx)*gapX;
vSet.Y = fTopY + rowFromPos(idx)*gapY;
vSet.Z = 0.0f;
}

if ((newState.IsKeyDown(Keys.Right)) && (!oldState.IsKeyDown(Keys.Right)))
{
int row = rowFromPos(curSel);
int col = colFromPos(curSel);

col++;
if (col >= tilecols)
{
col = 0;
}

curSel = posFromRowCol(row, col);
positionXYFromIndex(curSel, ref selPosition);
moves++;
score--;
}
else if (oldState.IsKeyDown(Keys.Right))
{
}

if ((newState.IsKeyDown(Keys.Left)) && (!oldState.IsKeyDown(Keys.Left)))
{
int row = rowFromPos(curSel);
int col = colFromPos(curSel);

col--;
if (col < 0)
{
col = tilecols - 1;
}

curSel = posFromRowCol(row, col);
positionXYFromIndex(curSel, ref selPosition);
moves++;
score--;
}
else if (oldState.IsKeyDown(Keys.Left))
{
}

if ((newState.IsKeyDown(Keys.Up)) && (!oldState.IsKeyDown(Keys.Up)))
{
int row = rowFromPos(curSel);
int col = colFromPos(curSel);

row++;
if (row >= tilerows)
{
row = 0;
}

curSel = posFromRowCol(row, col);
positionXYFromIndex(curSel, ref selPosition);
moves++;
score--;
}
else if (oldState.IsKeyDown(Keys.Up))
{
}

if ((newState.IsKeyDown(Keys.Down)) && (!oldState.IsKeyDown(Keys.Down)))
{
int row = rowFromPos(curSel);
int col = colFromPos(curSel);

row--;
if (row < 0)
{
row = tilerows - 1;
}

curSel = posFromRowCol(row, col);
positionXYFromIndex(curSel, ref selPosition);
moves++;
score--;
}
else if (oldState.IsKeyDown(Keys.Down))
{
}

Sunday, February 1, 2009

XNA learning started

I am mentoring a group of students at Chapman in a game development contest to build a game around the U.N. Millennium goals. I'm having a ton of fun with it.(http://imaginecup.com/Competition/mycompetitionportal.aspx?competitionId=21).

That said, I don't have any code duties on that so to learn XNA I've been back to trying to write a game a week, this time using XNA instead of Java (http://www.woodsgoods.com/gaw). I don't think the quality will be there, but I'll try and post some screenshots and lessons learned moving forward.