overidon.com Central Database for Overidon Omnimedia

June 23, 2013

2D Character AI and Trace Debugging

Filed under: Programming — Tyler @ 9:16 pm
Click the image to see the code (rough)

Click the image to see the code (rough)

When designing 2-Dimensional characters in their appropriate 2D worlds, it’s easy to make dull characters that have buggy and unexciting movement patterns. My current project which originally was just going to be a simple character/inventory simulator with 2D movement has expanded into a rudimentary 2D Arcade-like action game. This new direction has added complexity to the project and it also has increased its value to me as a showcase project. As usual when the program is finished, this showcase project will have the full code available for download. In this case the program is being written in Actionscript 3.0.

One of the problems I was having with my first, “bad guy” named, “bladeSkel1” which is short for Blade Wielding Skeleton Number One, was that the skeleton didn’t move correctly. I wanted him to change direction whenever he hit a wall. At first, when he’d hit a wall, there was a chance that he would change direction…but not always. Sometimes the skeleton would get caught in the wall and then strangely walk completely off the stage. I was astonished to see all my hard work simply exit the workspace. It was as if my critter didn’t want to participate in the program anymore and wanted to leave my game!

After looking at the issue after a day of letting it sit, I realized that I needed to “trace” the problem down. By using the, “trace()” command I was able to see that the skeleton wasn’t changing his x and y location properly after hitting a wall. Instead of simply changing his velocity, the skeleton should also be redirected to an “x” coordinate which was constant if he hit the “west” or “east” borders. And if he hit the “north” or “south” borders, a new “y” coordinate needed to be implemented.

Now you might be thinking, “Why not change both the “x” and the “y” coordinates? Doesn’t the skeleton have both an X and Y location on the stage?” And you’d be quite right for asking that. But you’ll see in your own projects, that if your character is hitting a wall or border in a 2D game environment…then the character already has both an X and Y location.

So by adjusting only the X location when the horizontal borders are touched and adjusting the Y location when the vertical borders are touched…you save yourself from having to use extra dispatch events. You can simply keep the Y location as it is when the skeleton hits a horizontal border. This kind of thinking can lead to greater efficiency in coding.

The first half of the Blade Skeleton’s ai is in the picture. And here’s the second half:

// begin code snippet
bladeSkel1.x = bladeSkel1.x + _skelVx;
 bladeSkel1.y = bladeSkel1.y + _skelVy;
 // begin the test bladeskel1 ai
 {if ((southBorder.hitTestObject(bladeSkel1)) || (westBorder.hitTestObject(bladeSkel1)) 
|| (eastBorder.hitTestObject(bladeSkel1)) || (northBorder.hitTestObject(bladeSkel1)))}
 {
 if (_skelVx != 0)
 {
 trace(_skelVx);
 _skelVx = 0;
 if (bladeSkel1.x >= 350)
 {
 bladeSkel1.x = 488;
 }
 else
 {
 bladeSkel1.x = 64;
 }
 _binaryRand = Math.round(Math.random());
trace(_binaryRand);
if (_binaryRand == 1)
 {
 _skelVy = -6;
 }
 else
 {
 _skelVy = 6;
 }
 }
 else if (_skelVy != 0)
 {
 _skelVy = 0
 _binaryRand = Math.round(Math.random());
if (bladeSkel1.y >= 272)
 {
 bladeSkel1.y = 338;
 }
 else
 {
 bladeSkel1.y = 73;
 }
if (_binaryRand == 1)
 {
 _skelVx = -6;
 }
 else
 {
 _skelVx = 6;
 }
 }
 }
// End code snippet

Now you may be wondering what I’m doing with the “_binaryRand” and it is a fun subject to discuss. The _binaryRand is a private variable that creates a random decimal number between 0 and 1  and then rounds that number to either 0 or 1. The end result is a type of switch. ‘0’ means the switch is off, and ‘1’ means the switch is on. In the case of the Blade Skeleton, I’m using that variable to spice things up whenever the skeleton hits a wall.

As the skeleton hits a wall, he will change direction. But that direction will be random. The character walks like a “rook” in chess. He can’t walk diagonally according to his programming. This is evident in the code by how whenever his “_skelVx” which is short for “Blade Skeleton’s Velocity in the X Direction” is zero…then his _skelVy is always a number other than zero. Never will you see both velocities as zero (which would mean the skeleton has stopped moving) and also never would you see both velocities as numbers other than zero (that would mean the skeleton is moving diagonally).

Now to make the movement of the enemy character more exciting you can read the code in the above image. If you click on the image the code will become readable. This code creates a “timer” of sorts which makes the skeleton change directions every 100 frames or so. So when the “_skelTrav” variable reaches the number 100, then the skeleton will move in a new direction at a faster rate than normal. The fun aspect to this type of code is that it makes the enemy seem more “alive” than if it walked always at a constant rate.

I hope you enjoyed this article and I’ll keep everyone posted as more features and progress are implemented into this game which will be free to play at overidon.com

-Tyler

June 22, 2013

Captain Picard Joke

Filed under: Humor — Tyler @ 3:19 pm
Tailor's Yarn

Tailor’s Yarn

So, Captain Picard walks into Suzzane’s Expert Tailor Shop and rings the bell. A well-dressed man with a measuring tape draped around his neck and three pins in his hand walks up with a smile. “Hello, sir! My name’s Gregory! And I DO believe I have the perfect suit for you today!”

Captain Picard squinted his eyes and asked, “What? I thought this was Suzzane’s Tailor Shop? What kind of trickery is this?”

“Ah,” Gregory said, “This is my shop. Suzzane’s the name of my machine. I’ve been using the same machine for rapid mends and patching sleeves for years. Since she does all the work, I named the place after her.”

Captain Picard pulled tightened his coat and then said, “All right. So what do you think you can do with my jacket? It feels a little loose around the sleeves and shoulders.”

After examining Picard’s coat with the tape measure, Gregory said, “I can easily take a 1/2 inch off your sleeves and a 1/4 inch from the shoulders and it won’t even cost you more than a pretty penny. I could have the work done before you leave town.”

Captain Picard stood back aghast with amazement. “How did you know I was leaving town?”

“Well, you do have tickets to the Wharf sticking out of your jacket pocket.”

“Quite right good Gregory. Well met indeed.”

Gregory wrote down the bill for his services. “So what do you say? Ten dollars is all I’ll need for my work. Shall we begin?”

Captain Picard pulled out his checkbook and made his $10 check out to ‘Suzzane’ and said, “Make it so.”

-Tyler

June 18, 2013

Black Cube White Cube

Filed under: Observations — Tyler @ 8:37 pm
On a hot and sunny day, which cube would you choose? And why?

On a hot and sunny day, which box would you choose? And why?

Imagine it is a hot and sunny day. A friend of yours says that he has a gift certificate for a full tank of gasoline and he wants to give it to you.

“What’s the catch?” You ask.

He says, “The catch is that in order to receive your full tank of gasoline…I need you to sit in a box for 15 minutes.”

You look outside, “I see two boxes in a field.”

“Yes, you only need to sit in one of those large 11 x 11 x 11 foot cubes for 15 minutes. So you’ll need to choose which box you’d like to sit in.”

You ask a question, “What are these boxes made out of?”

“Metal.”

“They don’t look metallic,” You say.

He then responds by saying, “Both cubes are made out of thin sheet-metal. One is painted black on its exterior. And one is painted white on its exterior. But both boxes are painted grey on the inside.”

“Will you close the door after me?”

“Yes I will close the door after you. But there is no lock, so you can leave at any time. Although if you leave before I open the door for you at the 15 minute mark…I will not give you the gasoline gift card.”

After inspecting the black cube and the white cube, you observe how your friend was telling the truth. They appear to be identical in size and shape, only the color of their exteriors differ. Also, you notice that neither cube block sunlight in any way for their counterpart cube. So neither cube gets the net effect of a shadow.

You think for a moment…your car does guzzle a great deal of gasoline. Also, your friend is trust-worthy and you don’t think he’ll bar the door and/or evacuate the air from the cubes. So you make up your mind on which box you choose to sit in for 15 minutes on this hot summer day.

What is your choice? And more importantly, why?

[there is no right or wrong answer]

June 18th, 2013 – www.overidon.com  – Tyler

June 12, 2013

Fasting Lethargy and Bread

Filed under: Innovation — Tyler @ 12:17 am
bread can make you tired

bread can make you tired

Fasting isn’t just for religious purposes or for preparing for surgery…actually, we do it every night! Our first meal of the morning is called, “Breakfast” because we’re breaking the “FAST” that was taking place due to sleep. While one is truly sleeping, he or she cannot eat or drink (unless he’s getting some sort of intravenous solution in a hospital) and that sleep allows our cells to do work on our bodies without having to compensate for movement, and the ingestion of new fluids, solids and/or toxins. So while we sleep, we’re letting our little cellular workers get their duties done without giving them extra work to do.

The reason why fasting is related to the concept of “I need to get my work done FAST today” is quite interesting.

Have you ever been very full and you already ate a gigantic meal and then someone like your parents or maybe a friend says, “Hurry up! Dinner’s ready! Come downstairs and let’s eat,” but for some reason…you don’t walk very quickly down the stairs? You might blob down the stairs with a sad face because you were busy talking to a friend. Or maybe you don’t come downstairs on time and upset everyone who is waiting on you for dinner.

Now let’s take a different look at the situation with different variables. Let’s say this time, you actually had to skip a meal earlier in the day due to some important event like a piano recital…or maybe you didn’t have time to eat because a colleague needed advice on a big presentation of which subject matter you were an expert. So this time when your loved ones say dinner is ready, what speed do you get downstairs? “FAST” right? It’s as if you don’t even walk downstairs, you somehow bent space and time to the will of your stomach!

Well, fasting is very interesting and can be equally dangerous. Fasting too often can cause people to become weak, fain and also acquire nervous disorders. But the reason why fasting is part of so many religions and cultures around the world for at least 1 day per year…is because it can make one rethink their mind/body relationship and how it relates to their dietary behaviors.

Just today, I was feeling very strange and lethargic. I rarely feel lethargic at all and I was quite confused. This was especially disconcerting because I have a huge demo project which is due in a week. And although I could probably discuss with my friend how I might need more time, I don’t want to. Because this project is going to be a showcase of my programming work and progress over the last couple months. (stay tuned because I’m going to post the project on this site in a week if all goes well.)

So I couldn’t grind very easily on my programming and I was wondering why. So I retraced my food intake over the past couple days and I realized that I had eaten a tremendous amount of pastas, pizzas and chow mein type foods. All these foods are very starchy and are high in carbohydrates. In other words…these foods are part of the bread family.

The only way to confront this bread lethargy is the hard way. I had to take a dreaded…nap.

While I slept in this non-productive torpor of the mind, I found my thoughts drifting. I couldn’t pinpoint any dreams or any real emotions. The thoughts just bubbled around like pasta in boiling water. Until finally, I woke up a couple hours later but didn’t have the energy to work just yet. So I just relaxed for a bit. And while I relaxed, my mind began working on my programming project! It was so weird! I’m just lying there, trying to NOT think, and then out of nowhere, “IF (inventory.visible == True ) && (Keyboard…” Basically, my project was being coded by my subconscious or perhaps my pseudo-consciousness. I’m not really sure, what matters was that after not eating for a while and getting some sleep, I was able to both get my energy back and also solve a major problem I was having with my character’s inventory and the idea of making keyboard presses correlate to movement on the inventory screen, as opposed to movement of the character in the cave area.

One good way of dealing with lethargy and sloth is to get to know what your desired energy levels are. I prefer having a lot of energy so I like things like coffee and high-fiber vegetables like celery and carrots, as well as other items like meats and tons of other stuff. But you might have a desired energy level which may be vegetarian or vegan or perhaps you’re a big fish eater. It could be anything. Everyone’s body is unique and his or her’s goals and responsibilities can directly be affected by having a comfortable energy level in order to getting the work done right.

So have fun and enjoy life!

-Tyler

« Newer PostsOlder Posts »

Powered by WordPress