January 30, 2011

Technical B-Ball

We were able to make a lot of progress in the first week of the game development, even though I was only able to work on it for 3 days. I wanted to start making some more technical posts about how I solved specific problems within the game for the purpose of recording it for myself as well as serve as a mini tutorial for people trying to do the same things.

Rectangular to trapezoid coordinates:

The first problem I ran into, is the way the court is drawn. I wanted to keep the coordinates in a rectangle and yet have the court be displayed to the player at an angle so the hoop and sidelines are more visible. The view to the player would look something like this:

In order to keep the coordinates rectangular, I had to change the position that the player was drawn on the screen so that it did not display rectangular, but displayed on a trapezoid. I had to come up with a function to convert the coordinates. My first idea was to use the barycentric coordinates relative to the two vectors that make up the trapezoid, which would convert the display nicely to a parallelogram, but it would not work here because opposite ends of the court angle in toward each other, instead of the same direction.

View mapping

I decided that the angle would change based on how close you are to the center. If the angle at the top left edge of the shape is 10°, then the player a quarter of the way down the court would move at a 5° angle, the center would move at a 0° angle, 3 quarters of the way would be -5° , and the entire other end of the court would be -10°.

An equation to describe the current angle based on player position would be:

angle = 10° * ( DIST_FROM_CENTER / (COURT_WIDTH / 2) )

with DIST_FROM_CENTER being a signed value.

We can then use this angle to find the two vectors describing the shape.

The first will always be along the positive x axis: (1,0)

The second will be: (cos(angle), sin(angle))

And then we can find our draw coordinates. With rectangular coordinates (x,y) we will have new coordinates:

new_x = x + ( y * cos(angle) )

new_y = y

Note: the new_y value is not affected by the vectors because we want the movement to look like the player is always moving parallel to the sideline (not realistic.) I made the error in adding y*sin(angle) to the new y value at first which made the player move along an arc, but since the view is warped to make it easier to see the game, this does not look correct.

Basic 3d Physics:

One of the main tasks in basketball, from what I've learned, is to shoot the ball in the hoop. However, we did not want this to be the main focus of the game, so we wanted to do an automatic aiming system that is based on a percentage chance that it goes in (rather than manually aiming the player's arms.)

He's like the Michael Jordan of basketball.

So we need to find the velocity at which the player needs to throw the ball from any position in the court in order to make it in the hoop. Since the game takes place in a full 3d world, we will have to use 3d kinematics (which is the exact same thing as 2d with an extra d somewhere (it doesn't change things too much.))

We can define a specific velocity in the z (up) direction that we want to throw the ball (as long as it is strong enough to reach the hoop) and we know the height of the ball at start. We must find the amount of time the ball will remain in the air until it reaches the height of the hoop on the way back down. We can use the kinematic equation:

(z_target – z_initial) = velocity_z*t + 0.5 * GRAVITY * t^2

solving for t we get:

GRAVITY * t^2 + 2*velocity_z*t – 2*(z_target – z_initial) = 0

using the quadratic equation:

a = GRAVITY

b = 2*velocity_z

c = 2*(z_target – z_initial)

t = max( (-b ± sqrt(b^2 – 4*a*c)) / (2*a) )

We want to use the max value of t because we want to know the time it takes to collide with the hoop on the way back down, otherwise we would have the player chucking the ball directly at the hoop instead of arcing it in.

So we now have the time the ball will be in the air, we now need to find the velocity in the x and y directions the player needs to throw the ball so that it will make it in the hoop.

We will use the same equation as before, but this time we are trying to find the initial velocity and we know the time. Solving for velocity we get:

velocity_x = ( (target_x – initial_x) – (acceleration*t^2/2)) / t

velocity_y = ( (target_y – initial_y) – (acceleration*t^2/2)) / t

I don't have any acceleration or deceleration while the ball is in the air (acceleration = 0) so I simplified the equations to:

velocity_x = ( (target_x – initial_x)) / t

velocity_y = ( (target_y – initial_y)) / t

And with that, we get a perfect shot every time.

January 22, 2011

Caveman Basketball Begins!

We started a new game a couple days ago, currently called Caveman Basketball! It will be a 2vs2 basketball game set in prehistoric times that allows up to 4 players (network or local.) It is going to be our entry in Tigsource's Versus competition which started about a week ago. Here is our Tigsource entry post and a couple early game sprites:

The ultimate Prehistoric 2vs2 B-Ball showdown! Grab your cave-jersey and tie up your loin cloth because this is going to be one boulder-shattering game!

Featuring:
-Naturally select your B-Ball players (Cavemen, Cavewomen, Dinos, Dinowomen, and more)
-Visit prehistoric B-Ball courts, referenced from ancient archeological B-Ball sites that may or may not have actually existed
-Matches take place before the emergence of the concept of "unsportman-like conduct", so anything can happen (clubs, boulders, slingshots, fists, claws, etc.)
-Slam dunk your way to the top and leave your opponents for extinction

January 15, 2011

Award Winning Game: City of Doom


I can now official say that City of Doom is an award winning game. I received an email from Softpedia today declaring that City of Doom has passed all of its tests and has been awarded the "100% CLEAN" Softpedia award. That's amazing. Really it is, I don't even know what to say. I wasn't expecting this. I have so many people to thank, so many people that helped us out along our journey. In case you aren't observing our live webcam right now, I'm starting to tear up a bit. I wonder when they send us our trophy?

I'm not quite certain if the "100% CLEAN" award is in reference to there being no viruses in the program or the fact that there aren't any nude people in the game. If it's the former, I'm glad to see that my hand didn't slip while writing the game and accidentally write code to redirect the user's homepage to viagra.com. If it's the latter, it's probably a good thing I never added the feature into the game where you can peek in a window and see a dude on the toilet.

Unfortunately, a hidden frame in Bravehorse would prevent that game from getting the same award.

Our game was also added to the Softpedia database "featured with a description text,
screenshots, download links and technical details". Well from the looks of it the description text is ripped directly from the earlier post on the site which the first line reads:

"In case you didn't see before, City of Doom is another Action 52 Remake like our previous game Mash Man."

It is taken out of context from a blog post on the site and now reads as if City of Doom is so popular that you are some sort of cave-dwelling idiot if you have not heard of it yet (this may or may not be the context that I was going for when I originally wrote it.)

This is a great day for all SharkArm developers everywhere. We finally have an award winning game that we can use to brag about and let other people know we are better than them. This is the best day of my life!

The Softpedia City of Doom page is here.

January 7, 2011

City of Doom Art

City of Doom fanart by Vinh "Gutter":


Click for the fullsize image. Thanks Vinh!

He actually had this done a while back when we were working on the game, but I forgot to post it.
 
Home Blog About Games ?