Welcome!

Hey, I'm Skylar, a kid aspiring to become a competent programmer. This blog is here to detail my dabbles in development.

My dream is to one day become a professional programmer and do some game development in my spare time.

Thanks for visiting my blog, and I hope you'll come back!

Pages

Day 7 of Charge Development

I'm very sorry, I know it's been a few days since I shared an update, but I have gotten quite a lot done.


I actually wiped my computer, so I have very few programs, I'm still working on getting some kind of screen camming software, and video editing software. Once I do I'll throw a video together, and upload it to youtube, for viewing pleasure.

The first few days were real unproductive. I kept getting errors when trying to use static surfaces. I finally fixed it after like 3 days. That meant the particle engine was done for my purposes. I haven't made any more implementations of it, but I'm planning to have particles follow some types of bullets.

So after that got done, I decided to get working on the next thing: Path System.
As of now, the Path System is done, later I'll make the actual paths themselves better.

So the trouble I had with the static variables were all over the place.
I got the right implementation after a while, but the problem was I couldn't load the image for the surfaces, because it would result in a segfault. The segfault happened because SDL functions were called before SDL was initialized. After a day of trying different things and getting help from different people, I finally got it working.

That's the end of the static variable trouble, now let's see what happened with the Path system...


So with the path system I decided each path was going to be an array of points. I'd pass the array into a function that would follow the path. It did this simply by adjusting velocities according to it's position.

The first small problem I came to, was how to find the number of elements in an array. I wanted this function to work on any path, so it needed to be able to find the number of elements in an array. I found using:

sizeof(array) / sizeof(array type)

was a way to get the amount of elements in an array. So I implemented this, and found out they weren't following the path at all. That was the last thing I thought it could be, but then I found the problem.

When you pass an array into a function, what your really getting is a pointer to the first element of the array... so I just had to dereference the array, right?

Wrong.

I tried that thinking it must work now, and I found it went to the first point in the path, and then stopped.

It's a pointer to the FIRST element in the array, not the array. so really what I was doing was this:

sizeof(someArrayOfInts[0]) / sizeof(int)

So really, this is going to evaluate to 1 every time, hence why it only accomplishes one point.

I thought for a second of using a multi dimensional array. When you pass those into a function, you get a pointer to an array, so that could work... except for the fact that anything past the first dimension must be specified.

At that point, I didn't think there would be a way to do it... until after I implemented it with vectors.

So I started using vectors and instantly got it working just how I wanted it to. I just had to make one small tweak. After it completed the path, I wanted it to return to its starting position. After some thought, I realized I couldn't just add their original points in at the end, because the Paths are for all of them. That's when I decided to have each enemy hold a Path that would determine their current path. They also have an integer that controls their path. So when the integer is -1, they don't have a current path, so no path is followed.

After I found this worked perfectly, I just made a function to perform the path logic and it looked a little bit like:

if(rand() == 0)
{
switch(rand() % 3)
{
case 0: pathID = PATH_1; change_path(); break;
//etc
}
}

change_path() just copies the contents of one vector into the enemies own vector of points and then adds in a last point which is it's original coordinates.

So this worked great. After I finished this I just made some wacky paths and let it rip and it works awesomely great.


So that's it for now, I'm still contemplating on what to work on next, but you can expect a video soon.

0 Response to "Day 7 of Charge Development"

Post a Comment