Showing posts with label game a week. Show all posts
Showing posts with label game a week. Show all posts

Wednesday, April 1, 2009

Balance Air Game

This is the best one so far. Didn't have a lot of time again so I went 2D and wished I had enough time to add a little sound (like a hair dryer sound) and do some more complex goals (like a bucket), but I think it's probably the most fun so far. It's not super pretty, but good luck, it's really really hard.


The game is called Balance Air. You have a hair dryer at the bottom of the screen and you need to balance the ball on air and force it into the goal. You move the blower left or right to change the direction of the ball. There are 7 levels which are basically just different locations for the goal. The score for each goal is dropping over time.

As I did last time you can download a free executable of the game. It is available here: http://www.woodsgoods.com/gawxna/02balanceair.

The complete source and Visual Studio project is available for $5 at http://store.payloadz.com/go?id=246205 .

Enjoy and please give me some feedback.

Wednesday, March 25, 2009

Skeet Slider game

I didn't even think I was going to be able to get a game done this week. I was spending a bunch of time on HLSL (the XNA shader language) and not getting where I needed to get. I decided I still needed to get a game done this week and I have yet to do a 2D game using XNA so I decided (yesterday) that would be the best way to complete the project in the time left.

The game is called Skeet Slider. Not my best by far, but much better than the past few weeks while I've been learning the XNA framework. You slide a puck across the bottom of the screen trying to avoid bouncing blocks. It's all about timing. I wanted to add a feature to change the velocity of the puck, but I'm out of time. Here is a screen shot of the game on level 4, the highest level. I spent a little time at the end to add better art for the game so it is cleaner that what I've written in XNA so far.



I also messed with the publish system in XNA Game Studio 3.0 and created an installer you can use to run the game. It is available here: http://www.woodsgoods.com/gawxna/01skeetslider.

I have also been considering offering the source code to some of these games to try and cover some of my time. It's a minimal $5 to purchase the C# source code to the Skeet Slider XNA Game. Please tell me if you think this is reasonable or not? I could really use some feedback.

Wednesday, March 18, 2009

SpinMag game

I used the same rotating magnet from last week and added a different scoring mechanic. I also added a levels using png images to place items on the map. There are four levels, but the game is really tough. Currently it only has one life. I wanted to add more, but ran out of time. I again spent a bunch of time reading about texturing and lighting and have not made the progress I had hoped. I'm considering a game that uses spot lights as a mechanic next week.

This is a screen shot of the game.

This is the map image. Each pixel represents the location of one of the 3d spheres.

Here is the code that reads the map image and converts it to 3d objects.

protected void LoadMap(String mapname)
{
// the map is just an image file with pixels of various colors
// red = barrier
// black = open space
// cyan = closed space
// green = starting point
Texture2D map1 = content.Load<Texture2D>(mapname);

mapwid = map1.Width;
maphei = map1.Height;
int numpix = mapwid*maphei;

if ((map == null) (map.Length < numpix))
{
map = new byte[numpix];
}

// want this map to fit over the circle, so calculate the size of each ball
// scale of the ball
mapballsz = (int)(maxballdist*2) / mapwid;
mapxstart = -(mapwid / 2-1) * mapballsz;
mapystart = -(maphei / 2-1) * mapballsz;

/*
* the sample I used to write this method
* ms-help://MS.VSCC.v90/MS.VSIPCC.v90/MS.XNAGS30.1033/XNA/GetData``1_B8CC1053 */

Rectangle sourceRectangle = new Rectangle(0, 0, mapwid, maphei);

Color[] retrievedColor = new Color[numpix];


map1.GetData<Color>(
0,
sourceRectangle,
retrievedColor,
0,
numpix);

goalcount = 0;
int i;
for (i = 0; i < numpix; i++)
{
if (retrievedColor[i] == Color.Cyan)
{
map[i] = MAP_CLOSED;
}
else if (retrievedColor[i] == Color.Red)
{
map[i] = MAP_BAR;
}
else if (retrievedColor[i] == Color.Blue)
{
map[i] = MAP_GOAL;
goalcount++;
}
else
{
map[i] = MAP_OPEN;
}
}
}

Wednesday, March 11, 2009

SpinDart

The games are getting closer, but still have a ways to go on getting my art pipeline down in a week. That's where I spent a bunch of time this week trying to get some models out of 3ds Max which I'm new to. I got the models out, then left them on a different machine so this screen shot is untextured models.

It isn't what I started out to make and I may make a different game with this same mechanic next week. Locking the z axis and making this a 2d game helped the time constraints some, but I would like to be able to get that third axis in a week long game cycle.

The game is a "gravity" style game which is one of my favorites. Impossible to control which means the mechanic doesn't really work, but I'm not 100% sure it is impossible to control. Given a shared high score system I think I would see some different approaches to making points, but alas I haven't written the shared high score system yet...




Here is a code snipet that does the collision checking. I didn't use the XNA system which I looked into a little and decided it was easier to write this simplified code.

private void checkCollision()
{
// check the position of the ball with that of the spinner
Vector3 vspin; // = Vector3.Backward; // pointed up
Matrix m = Matrix.CreateRotationY(spinnerRot);
vspin = Vector3.Transform(Vector3.Forward, m);

// I know the spinner is 7.2 units before scaling (looking in milkshape)
vspin = vspin * 7.42f * scaleXY;

// now check the position of the ball in z space
if ((ballPos.Length()>vspin.Length()+ballradius) && (distToOriginLineXZ(ballPos, vspin) < ballradius))
{
// collision

// wwh score or death?
score = score + 1;
}

// check if we are inside the center of the spinner
// spinner sphere radius = 2
if (ballPos.Length() < 2 * scaleXY + ballradius)
{
// wwh score or death?
mode = STATE_OVER;
if (score > highscore)
score = highscore;
//score = score + 1;
}
}
private float distToOriginLineXZ(Vector3 pt, Vector3 oline)
{
// used this reference
// http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
// p1 = 0.0,0.0
// p2 = oline.x,oline.z
// p3 = pt.x,pt.z

// oline is a line from the origin
Vector3 vi = Vector3.Zero;
float u = ((pt.X - 0.0f) * (oline.X - 0.0f) + (pt.Z - 0.0f) * (oline.Z - 0.0f)) / (oline.Length()*oline.Length());
vi.X = u * (oline.X);
vi.Z = u * (oline.Z);

pt = pt - vi;
return pt.Length();
}

Wednesday, March 4, 2009

Sphere Pong

This week's mechanic I was working on didn't really work, but it was a fun idea. I created a 3d pong game where you move the puck around a sphere and try and keep the ball in the middle. The problem is there is no reference point. I need some sort of skysphere or spherical markings or maybe also a tail on the ball so you can more easily tell direction. Ran out of time, but may come back and revisit this one someday.

I'm still learning XNA and the graphics look crummy, but for me right now this is more about learning the api than working on making a good looking game. Forward progress at any rate.
For a code sample a lot of the time was spent in positioning the puck around the sphere. I only finished the x,z plane as it didn't work for that, so no reason to add the third dimension. Here is the code to position the puck around the sphere.
// move the paddle using the upVector (true) or the cross product of the origin and up (false)
// direction is a + or - 1 for up, down, left or right
private void movePaddle(bool usingUpVector, float dir)
{

if (!usingUpVector)
{
// need to take the cross between the up and the origin
Vector3 vp = paddlePos;
vp.Normalize();
// vector change
Vector3 vc = Vector3.Cross(vp, paddleUp) * dir;
vc.Normalize();
vc = vc * paddleSpeed;

// find the new location, will be outside the sphere
vp = paddlePos + vc;

// fix up the distance ot the sphere
vp.Normalize();
vp = vp * radius;

paddlePos = vp;

// the up vector should not have changed, right?

// move the camera behind the puck
fixupCamera();
}
else
{
// for this case, take the cross product
// move in the direction of the up vector (+ or -)
// position against the spehere
// use the cross product to calculate the new up vector
}
}

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))
{
}