abraker95 / tanks

2D arcade top-view shooting game
1 stars 0 forks source link

Make the Camera::Update function more readable #27

Closed ghost closed 9 years ago

ghost commented 9 years ago

The code in Camera::Update needs to break down into several functions.

ghost commented 9 years ago

So I completely restructured the camera update code. Also, I'm keeping camera initialization inside the environment class instead of the main function. This would make more sense when we have sub environments for stuff like menus and such.

ghost commented 9 years ago

Added smooth camera effects. Also I made it so that the objects that are being focused by some camera render separately from objects not being focused by some camera. There was also a crash when closing the game. I changed something and it disappeared, but I'm not sure if it's still there or not.

ghost commented 9 years ago

It's not crashing for me now, i think it's fixed.

ghost commented 9 years ago

ok good. And the other mysterious crashing bug too it seems. Excellent!

On Sat, Nov 15, 2014 at 5:03 AM, Sherushe notifications@github.com wrote:

It's not crashing for me now, i think it's fixed.

— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/27#issuecomment-63166988.

ghost commented 9 years ago

I tried your code and it works, but I have trouble understanding the code itself.

ghost commented 9 years ago

I try to refractor my code and maybe you understand? Or you want to fix the current version?

ghost commented 9 years ago

I fixed up the current version, but if you want to explain your code to me for the parts responsible for calculating the needed ratio that'll be good too.

On Sun, Nov 16, 2014 at 2:52 AM, Sherushe notifications@github.com wrote:

I try to refractor my code and maybe you understand? Or you want to fix the current version?

— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/27#issuecomment-63209086.

ghost commented 9 years ago

Okay. I will try to explain what i know about ratios because the code looks weird.

The aspect ratio is the width/height. In other words, if you have a 1px height, how much px in the width you need to have the same ratio. Also it's just a number not a 2d vector.

For the aspect ratio correction: To have viewsize with the correct ratio you just need to scale objBounds. You just have to scale up one side (you can determine which one with the objBounds ratio ). This way you have the smallest view size with the correct ratio, and which contains all the focused objects. You can also do it like you did where you take the biggest side of objBounds and make a square out of it and scale it even more to have to correct ratio. But it is a waste of space. I hope you know what i mean.

Now the code starts to be a bit long. I hope you can do something about it. I would still prefer to take the old version if it's working.

ghost commented 9 years ago

I was focused on having the objects in view. I actually thought of a way to have all 3 conditions met:

1) The aspect ratio is maintained, the objects are within the viewing area, the viewing area is BEYOND its limit.

2) The aspect ratio is NOT maintained, the objects are within the viewing area, the viewing area is within its limit

3) The aspect ratio is maintained, the objects are NOT within the viewing area, the viewing area is within its limit Just make the level shaped such that it square, and just set boundaries where the tanks can go. So in this level, we extend the top and bottom, but block it off. I don't think a game where the tanks go off who knows where off the screen would be enjoyable. I tried getting the tanks back in view, and most times I gave up.

Or maybe we can do what Smash Bros did and implement a cursor to the object outside the camera's view.

On Sun, Nov 16, 2014 at 7:53 AM, Sherushe notifications@github.com wrote:

Okay. I will try to explain what i know about ratios because the code looks weird.

The aspect ratio is the width/height. In other words, if you have a 1px height, how much px in the width you need to have the same ratio. Also it's just a number not a 2d vector.

For the aspect ratio correction: To have viewsize with the correct ratio you just need to scale objBounds. You just have to scale up one side (you can determine which one with the objBounds ratio ). This way you have the smallest view size with the correct ratio, and which contains all the focused objects. You can also do it like you did where you take the biggest side of objBounds and make a square out of it and scale it even more to have to correct ratio. But it is a waste of space. I hope you know what i mean.

Now the code starts to be a bit long. I hope you can do something about it. I would still prefer to take the old version if it's working.

— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/27#issuecomment-63217966.

ghost commented 9 years ago

Sorry i didn't clearly say what i wanted with this type of camera. I just wanted a single screen camera for the dev stage of our program. But for the final game, we wanted split screen, right? So if the tank goes off screen it doesnt matter. The cursor thing is not bad, we could implement that but we will use split-screen at the end to avoid the contradictions you said.

ghost commented 9 years ago

I think I got carried away with the single screen so much, I forgot we were doing split screen haha. So which one of us will be fixing up the camera code?

Also, I will try to get some guidelines down about working with the code so that we don't come across to this conflict again.

On Sun, Nov 16, 2014 at 2:11 PM, Sherushe notifications@github.com wrote:

Sorry i didn't clearly say what i wanted with this type of camera. I just wanted a single screen camera for the dev stage of our program. But for the final game, we wanted split screen, right? So if the tank goes off screen it doesnt matter. The cursor thing is not bad, we could implement that but we will use split-screen at the end to avoid the contradictions you said.

— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/27#issuecomment-63233525.

ghost commented 9 years ago

I think i can finally close this issue. The update function is now refactored.