Wednesday, December 26, 2007

It's NPC Time, Bitch

I realized I have no idea how to start to structure my NPC code. Well, I did have an idea, and I am having it critiqued on a forum, now. 112,000 files scanned.

Defrag

My computer has not been defragmented in a long time. So I cleared off a lot of stuff, and I am going to start a defrag right now. Later, people. A lot later, depending on how much stuff I need is on my hard drive.

EDIT: Okay, that took nowhere near as much time as I thought it would. It took longer to free up the space needed to defrag in the first place. And apparently my D drive needs no defrag. So, it being only nine at night, I am ready for the programming to continue. In four hours, you shall see me post, "So, it being only one in the morning, I am going to do some more programming." I am, I admit, somewhat obsessed. But, I have reason to be; I only have just over two weeks until college begins. A new semester, six classes, friends who live with me, not nearly as much free time.

Well, I only have one class on Monday and Friday, so there's time then.

EDIT TWO: Running a virus scan, and later a spyware scan. My Explorer.exe is, for some reason, randomly consuming 50-60 percent of my processing capabilities. I don't mind it so much, I suppose, except for the fact that I'm afraid it is degrading the performance of my Java compilations. More later.

EDIT THREE: ~60,000 files scanned, and nothing yet. Unfortunately, there are 300,000 to 400,000 files on my computer. Maybe a little less, since I just deleted a few programs, and games. Now I start on NPCs. Damn, this is tough.

First Look

Okay, so I got the idea to make a small video of how my program is doing so far. I guess all I'm gonna say is that this is just a test map. Two of the protrusions in the corners started life as NPCs in my old map, and that 3X3 block toward the lower left edge was once a small building. They will be again, but for now they are trees. Also, I want to say that all the images are sprites taken from various versions of Nintendo's Pokemon games. They own them, and I am not collecting any sort of fee for their use, so I am off the hook as far as legality goes. Enjoy... me walking around a map....



So, how was it? Was it cool? Did it make you all tingly with anticipation? Did you notice the background trees shifting unevenly?

Bah, never you mind that last part. It looks good enough in person, and better on video, I think.

I am suddenly exhausted, and my eyes hurt a little. Break time. I'll begin anew later.

Success, Success

I am very happy with myself. After looking online for a very long time, running through forums and websites and shit, I have determined that my game is pretty damned good. I also "fixed" it again. Remember all that crap I gave myself about making the character turn in place? Well, I ended up setting the direction, and then starting the move thread, and finally adding a slight pause to the thread. That pause gave the computer a chance to ascertain whether or not the key was still being held down. So very quick taps gave a turn in place reaction (just like the actual game). Well, I realized that this pause (30 milliseconds) was actually showing up in the game, giving my animation a very slightly noticeable hiccup every half second or so. You would have to be paying attention to spot it, but it was there, it was responsible for part of the perceived crappy animation, and it was getting on my nerves.

So what I did was change the location of the small pause. I made it only register if the direction was not set. So when the direction was set (like after you had finished turning in the direction, and either held the button, or went to tap it again), the pause no longer occurred. This led to some smoother animation, and a happier me.

I now have the player done (for the moment). I still need to shift more of the code to the player class, but that will come later. I'd say, as far as the entire game is done, I am now somewhere around 1/200 - 2/100 done. For those of you more idiotic than a fifth grader, that's 1/200 - 2/200. Not much. Some of it will be easier, though, so I am alright. Art and music will be death; I may have to find someone else to help me with them.

Later, peoples, I'ma gonna find something else to do (programming-wise).

Hey Justin.

New Ideas

So I stumbled across an interesting little tidbit, while roaming through Java forums. I now about an interesting little thing call a Rectangle. No, I'm not a moron. It's a programming thing that can help me know when stuff comes into view of my "camera" into the little world I have created. The Rectangle would be updated constantly to follow my character, and the rectangles of other things, like NPCs for instance, would set off an alarm when they intersect with it.

Unfortunately, while this is a good way to detect other characters, I do not see how it can be effectively used to make my tile map faster. Oh well. I heard Quadtrees are good for large maps, but I cannot find good documentation on them. I'll look around again, though.

Oh, That Was Easy

I did it. In record time, too, I might add. My character turns in place (mind you, you must tap the arrow key pretty damned quickly), and turns and walks without significant pause. Gonna work on some other stuff, now.

EDIT: Blah, did some more stuff. Tried experimenting with VolatileImages. I did not like it. It actually slowed everything down. I thought it was supposed to make images faster accessed? Whatever. Back to BufferedImages. There's a small amount of distortion in the images as they are drawn (something like tearing but not nearly as bad), but I think I'm cool with that.

So, I also checked out, once more, my emulator for the Gameboy Advance. I played some Pokemon Crystal (my absolute favorite version), and looked at how that looked. And I realized it was just as terrible as mine. That same sort-of-tearing is there too, even through the best filters. So that means my version of the game is just as good as the best emulated version out there. Awesome.

So, I have finished the basics with my character (just the walking, though), collision detection, the tiled map, all that sort of stuff. Next up is the NPCs. I am going to make two of them (like in the original test map), that walk around a predetermined path. I have no idea how I am going to do this, but I suppose it will be something like, look around the visible portion of the map (can be done while in the animation loop). If there is any portion of an NPC's path being animated, I shall set that NPC into motion. If their path is no longer animated, they go dormant.

But first, lunch, and Rush Hours.

Ah, Sleep

I obeyed myself, and went to sleep last night without programming anymore. I woke up fresh with no headache, and took a nice, warm shower. And then I got some breakfast and started programming. I have it now so that my character can turn in place, and I also have him moving smoothly across the board. The method I wrote down last night did work, although it took making a new thread in order to do so.

My only problem with it now is that the pause when turning in place is too long. In the actual game, if you quickly tap the directional pad, the character turns in place. However, if you press it down, the character turns and immediately starts walking. I replicated this in my original program (I looked at that code, tried to adapt it, and promptly trashed it, starting from scratch). But on my program, when you turn and walk, there is a pause (allowing you to otherwise turn in place), before the walking. The rest of my day shall probably be spent getting rid of that pause.

It is almost time for lunch, though, so I may give it a rest for a little while. I also wish to enjoy my copies of Rush Hour and Rush Hour 2 once more. I'll see what I can get done.

Later, peoples.

Why Do I Do This To Myself?

I started programming again. Why? Just because I did. I had a goal in mind. Did I reach that goal? Yes and no.

Well, I realize that there are some things I should have done, that I did not. Before, I had the code for making the character look like he's walking separate from the code to actually move him. This is trouble, because when the character is moving against a wall, his feet still move. In a perfect world, that is. This was accomplished in my old program. However, the code to do that is now dependent on the the arrow keys being effective, which, now, when I run into a barrier, they no longer are. This is a problem I must fix.

Also, I am experimenting with different ways to move the character continuously. I have tried several ways, but none seem to work to my liking. I am actually getting an idea right now, so bear with me while I write it down.

I use steps in the X and Y directions to mark movement. These are increased by 8's until the desired goal (+tileSize, -tileSize) is reached. This produces the smooth movement as the character walks. I am thinking of using the flag methods to flag the keys I am pressing down. I am thinking that I can program it to only acknowledge the held key when no other keys are pressed, and also the steps are only divisible by tileSize. That way, it will not continuously read the flagged key and zip my character across the board.

Tomorrow, though. Absolutely no more programming tonight.

Later, fucktards.

More Done

Phew, did a little more. I got my guy to walk. And I figured out how to use classes and junk. I have a class for my character now. Of course, there's some stuff I should do to optimize it, to ready it for possible changing resolutions, but I'll get around to that later.

Next up is something I completely forget how to do. I need to make it so that I can turn in place, rather than automatically walking in the new direction. Then, I need to make it so that I have smooth walking, without that little jerk at the beginning. Now, I know what some of you are saying. "Flag the keys being pressed, and you won't have that pause!" Well, fuck you all. That makes my game too fast. I had a way of doing it with just the keyPressed() code, and that's what I'm going with.

It's almost one in the morning, so I think I will finally call it in, and get ready for sleep. Tomorrow I will look at the old code I have for that, and find a way to implement it into the current programming.