Monday, November 10, 2008

A crate and sprinting

So while working, I quickly built a crate since there are quite a few areas already in which I need crates, cellars, storage rooms.

Here is the crate, a basic six sided cube with a skin made in Photoshop:

As simple as it is, I'm proud of the cube because of the skin. Its a simple skin that a pro could do in photoshop in two minutes, but me? I felt like I leveled up, like I gained a skill, when I saw how it came out.



I was roughly following a tutorial, but had to make most of it up because the tutorial was using a program I don't have.

What I did was I opened a file, 512x512 pixels. I filled it with a brown color. Then I grabbed the Paintbrush tool, picked a large brush, Chalk, size 44, reduced the opacity to around 25%, chose a darker brown and made several diagnal and vertical strokes to rough in the big parts of a wood textured.

What I got looked like a large 'M' with a few extra lines. But that's okay, I added the grain with a filter called "Graphic Pen," and set the stroke direction to horizontal. It made a whole bunch of brown and white jagged strokes. Since I didn't want the white, I went to the magic wand tool, turned off "contiguous" and "anti-aliasing" and deleted the white areas, and finally, I got a wooden texture.

Then I went to the rectangle marquee selection tool. I picked up the paint brush and selected a very dark brown with a low opacity and colored in around the edges, making the illusion of an indented square.

I grabbed the airbrush and made several vertical lines to give the illusion of planks. Then I used the airbrush to add knots. Last, I used the airbrush, by clicking in one place only to make the nails, which I think came out well.

And then I was finished. After fighting with MED to get the faces in the skin editor arranged properly, my cube was skinned and is now a crate.



Above is a stack of crates in game.

Since the game is based on a lot of movement, I actually have to get a movement code working before I go too far with the level design. The player needs to be able to crawl, climb, sprint and other things to get from place to place.

Sprint should be finished.

function sprint()  
{
if(key_shift)
{
if(tired == 0)
{
if(sprinting < 15)
{
sprinting += time_step * 0.0625;
player.speed = 60;
}
else
{
tired = 1;
player.speed = 10;
}
}
else
{
sprinting -= (time_step * 0.0625) * (sprinting >= 0);
tired = (sprinting >= 0);
}
}
else
{
sprinting -= (time_step * 0.0625) * (sprinting >= 0);
tired = (sprinting >= 0);
player.speed = 10;
}
}


What does this code do? Basically, it allows the player to run at an increased speed for a maximum of fifteen seconds. When she stops running, she can't sprint again for the time that she sprinted.

Line by line: The first line, "if(key_shift)" checks if the shift key is pressed. If so, it goes to the next if() statement, "if(tired == 0)." If not, it goes to the else section and sets things back to walking speed.

The next line, "if(tired == 0)" checks if she's run recently. If not, it goes to the next if-branch, "if(sprinting < 15) checks that the sprinting variable is under 15. The next line adds to "sprinting," time_step * 0.0625, which allows for the counter to hit 15 in 15 seconds. Time_step is the time one frame of the game takes, and is about 1/16th of a second, hence "time_step * 0.0625." 0.0625 = 1/16.

The line under it sets the player speed to 60, a high variable to help me see the results. Since this function is called in a while() loop, it will continue to increase sprinting until sprinting == 15.

(side note, = is an assignment. x = 2 means that x has been assigned the value '2'. == is comparison. x == 2 means that x is being compared with the value 2, but x can be anything)

When sprinting is 15, the lines under the Else part of the "if(sprinting > 15) branch are read. They set tired to one and set speed back to the default, which is 10.

Since tired is now 1, the if(tired == 0) branch goes to its else branch. You see this line: "sprinting -= (time_step * 0.0625) * (sprinting >= 0);" All this does is reduce sprinting by 1 every second until sprinting is less than or equal to 0. The way it works is, if sprinting is greater than zero, the second part, "(sprinting >= 0), is equal to 1 because it is true, that part of the expression is a binary conditional. 1 * 1 = 1 and so it decreases by 1 every second. But when sprinting is zero, (sprinting >= 0); is false, thus it equals 0, and 1 * 0 = 0 which means it no longer decreases.

Then tired also uses a conditional, which works the same way. If sprinting is less than or equal to zero, the conditional becomes false, tired becomes zero and Suzetta can run again.

The last chunk of code is the else branch attached to the if(key_shift). This does the same thing as I described in the above two paragraphs. It is also down here in case the player releases shift before sprinting == 15. And then finally, the speed is set back to its default of 10.



while(thisCodeDoesntWork)
{
smashComputer(); //take out some pent out anger
throwDartsAtBoss(); //take out more anger
sleep(6*60*60); //sleep six hours
}

1 comment:

Anonymous said...

sprinting:
Prolonged exposure to superfluous element nesting might product eye strain, mental fatigue, psychosis, migraines, and gangrene.
Consult a doctor prior to persistent application of:
{
}
{
{
{
{
}
}
}
}
}
;)