Getting rid of old stuff
|
I’m so happy that themepark has begun! And I really want to start working on our game! But I can’t, and I feel so bad about that. There’s a task that I have not completed that I have to do first. It’s for one of the previous courses in which we were supposed to make a game that included some stuff on a list, for example a collisionmanager and a statemanager. I thought we were almost completed with this project, but I was wrong! We went to talk to Jerry about what we could cross on this list, and apparently practically nothing we had made was good enough. The last few days me and Evelina have been rewriting the code for practically our whole project. Mostly to make stuff ”generic”, a word I didn’t know existed before our talk with Jerry. To have something generic in programming, for example a generic collisionmanager, you have to be able to easily add new objects without changing any code in the collisionmanager. Say, instead of in the collisionmanager writing that if an enemy is hit by a bullet it dies, you write that in the enemy’s code itself, in an ”OnCollision”-funcion, which you call to in your collisionmanager. Then if you add a new enemy type, you won’t have to change the code in the collision manager at all, you just type whatever you want to happen on certain collisions in it’s own ”OnCollision”-function. So that was one thing I had to change. The next thing that came with it was colliders. Previously all collision offset was coded right in to the objects’ ”Update”-functions, but now they are put into colliders and are completely handled in the collider and in the collisionmanager. We had to make a couple of different collision types, these were circle vs circle, box vs box, box vs circle and pixel perfect. We dicided to skip pixel perfect since there was much to do apart from that, and we thought that pixel perfect collision would take a lot of time. However we made the other collisions! I will now shortly explain how they were made. Circle vs circle: This was made by calculating a distance between the objects that could collide by using pythagora’s theorem. If this distance became shorter than the designated radius of the two colliders’ added together an offset would be calculated using trigonometry. Circle vs box: First the circle checks collision against the corners of the box, in a way very similar to circle vs circle collision. It then checks if the points on the circle farthest away from it’s middle to the west, east, north and south is within the rectangle. If the western point is inside the rectangle the offset will be towards the east. Box vs Box: This was made using a whole bunch of if-functions, limiting areas by saying ”if x is less than this and more than that, if y is less than this and more than that…”. If this was correct, an offset would be calculated in the x-direction and the y-direction. Then the object was moved by the smallest offset. I did not make an ”exeption” if both of these offsets would be equal, since that is probably very hard to make happen with the float-datatype, and also it won’t even be noticed. Another thing we had to remake was our inputmanager, but that went fast. Previously we just had a keyboard object and a mouse object and called to one of them where one of them was needed. Our teacher wanted us to stuff them both together into an inputmanager, so we did. Then of corse it was the game object manager, in which we previously had all the objects in different vectors. It was basically just to put them all in to one vector. A lot of ”GetType”-functions and stuff had to be added, but it worked out quite well and it’s now far less code in the game object manager. We’ve been working very focused on this during the previous days, we have as good as remade the whole game. We really want it out of our world as fast as possible, it was really bad of us not to get rid of this earlier because honestly it’s not that hard, just irritating and lots of work. Had to do it sooner or later. And now it’s giving us troubles. Sigh. We’re writing reports about it as well, we’re doing this at the same time as we’re coding to be as effective as possible. It’s realy stressful, I’m so happy I’m not capable of feeling stress. |