Computer Science Canada [C++ Help (SDL)] How do I know what coordinate to draw things to? |
Author: | Shinobu [ Thu Sep 12, 2013 4:22 pm ] |
Post subject: | [C++ Help (SDL)] How do I know what coordinate to draw things to? |
http://lazyfoo.net/SDL_tutorials/lesson02/index.php I get everything he says in there, after reading it a lot of times. But how did he know where to draw his coordinates? He drew his to (0,0), (320,0), (0,240), and (320,24). I just made a random picture to practice with, but how do I know what coordinates to draw to? I mean if I just copy his coordinates, I'm not going to learn where to draw things if I wanted to make a game. Will I learn that later on? Should I care about it yet? ![]() |
Author: | Insectoid [ Thu Sep 12, 2013 5:03 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
He set his window size to 640x480. 320x240 is simply 1/4 of that (half of each dimension). |
Author: | Shinobu [ Thu Sep 12, 2013 5:34 pm ] |
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Insectoid @ September 12th 2013, 5:03 pm wrote: He set his window size to 640x480. 320x240 is simply 1/4 of that (half of each dimension).
Dang, that's kinda confusing ![]() So to know where to draw things, I will have to always do something like that? ![]() |
Author: | Insectoid [ Thu Sep 12, 2013 5:38 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Well, if you know the size of your window, you can roughly approximate where a coordinate is. The top-left of the screen is (0,0) and the bottom right is (width, height). You will have to experiment with values a bit if you want precise placement, but it's really not that hard. |
Author: | Shinobu [ Thu Sep 12, 2013 5:41 pm ] |
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Insectoid @ September 12th 2013, 5:38 pm wrote: Well, if you know the size of your window, you can roughly approximate where a coordinate is. The top-left of the screen is (0,0) and the bottom right is (width, height). You will have to experiment with values a bit if you want precise placement, but it's really not that hard.
So I'll have to always guess? ![]() Dang, 3d games must be really hard to make then. Just wondering, what if I don't know the size of the window (just pretend I don't). Then what? XD I'm just curious ![]() |
Author: | Nathan4102 [ Thu Sep 12, 2013 6:20 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
In 3d games, you're never using hard numbers, its all done with calculations and crazy wizardry. ![]() If you don't know the size of your window, there's always a function to find the size of your window, so that shouldn't be a problem. If you can't do that, assume you have a 2x2 window, and do your best to get your point across using that. |
Author: | Shinobu [ Thu Sep 12, 2013 7:04 pm ] |
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Nathan4102 @ September 12th 2013, 6:20 pm wrote: In 3d games, you're never using hard numbers, its all done with calculations and crazy wizardry.
![]() If you don't know the size of your window, there's always a function to find the size of your window, so that shouldn't be a problem. If you can't do that, assume you have a 2x2 window, and do your best to get your point across using that. Arghhhhhhhh making games just becomes 1000 times harder than before now -_- Guess I'll just continue LazyFoo's tutorials now xD Thanks guys |
Author: | Nathan4102 [ Thu Sep 12, 2013 8:30 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Don't worry about 3d games right now! I've been programming for a couple years now and I've never tried anything 3D. I remember one time I looked at some code of a 3D engine, and I realied it's WAY past me, both programming wise and math/physics wise. Making games isn't THAT hard, you just need to be a good problem solver, and be persistent enough to keep trying until you finally get the result you want. Oh, and you should know the basic syntax of your language, how to draw stuff to the screen, and how to recieve input from the user via mouse clicks and key presses. |
Author: | Raknarg [ Thu Sep 12, 2013 9:40 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
3D engines aren't as hard as they looks, it's more of a matter of wrapping your head around converting 3d to 2d. Once that makes sense, they're no different. Imagine, people use 4 dimensions sometimes when programming in 3d ![]() As for the graphics, it's not really hard, just very, very time consuming if you hard code everything. In most cases, you can use sprites or pictures for everything, the only thing you need to hard code is menu screens and HUD interfaces, which are much simpler. |
Author: | Shinobu [ Sat Sep 14, 2013 10:05 am ] |
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Nathan4102 @ September 12th 2013, 8:30 pm wrote: Don't worry about 3d games right now! I've been programming for a couple years now and I've never tried anything 3D. I remember one time I looked at some code of a 3D engine, and I realied it's WAY past me, both programming wise and math/physics wise.
Making games isn't THAT hard, you just need to be a good problem solver, and be persistent enough to keep trying until you finally get the result you want. Oh, and you should know the basic syntax of your language, how to draw stuff to the screen, and how to recieve input from the user via mouse clicks and key presses. Haha, that's what I'm doing ![]() Raknarg @ September 12th 2013, 9:40 pm wrote: 3D engines aren't as hard as they looks, it's more of a matter of wrapping your head around converting 3d to 2d. Once that makes sense, they're no different. Imagine, people use 4 dimensions sometimes when programming in 3d
![]() As for the graphics, it's not really hard, just very, very time consuming if you hard code everything. In most cases, you can use sprites or pictures for everything, the only thing you need to hard code is menu screens and HUD interfaces, which are much simpler. I thought people hard coded the whole game, like Diablo 3 for example. So they use level editors or something? XD |
Author: | Insectoid [ Sat Sep 14, 2013 1:43 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
They absolutely use level editors. Once you have an engine, the editor can be built on top of it relatively quickly, especially compared to coding the levels by hand. |
Author: | Shinobu [ Sun Sep 15, 2013 6:12 pm ] | ||||||
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? | ||||||
Insectoid @ September 14th 2013, 1:43 pm wrote: They absolutely use level editors. Once you have an engine, the editor can be built on top of it relatively quickly, especially compared to coding the levels by hand.
What are engines? LazyFoo's tutorials didn't mention that... at least I don't think so when I just checked lol. I found in article of his talking about level editors, which I'll take a look at that later ![]() I have a question that's bothering me right now, if you'd like to help ![]() Let's say we have an add function that returns the variables x and y. Does the way I code it matter? The way I see all the time:
The way I do it (more clear in my opinion):
And the way the professional teacher in a DVD my dad gave me does it:
The last way is the worst way to do it in my opinion, but my dad keeps saying he's professional and everything, and I'm wondering if companies actually care about which way you make your programs. Does it really matter about just saving a few lines but deleting spaces like that? It really confuses me when I read code like that. ![]() Thanks ![]() |
Author: | DemonWasp [ Sun Sep 15, 2013 7:38 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Teams will usually choose one standard and will expect all programmers on that team to stick to that standard (usually the first one you listed, though there are tons of variations). The most organized teams will have some established way of having the computer format your code for you. The last example you listed is usually frowned upon and may be used only because it neatly fits on one line, which is important in (for example) presentations with limited screen space. |
Author: | Shinobu [ Sun Sep 15, 2013 8:11 pm ] |
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
DemonWasp @ September 15th 2013, 7:38 pm wrote: Teams will usually choose one standard and will expect all programmers on that team to stick to that standard (usually the first one you listed, though there are tons of variations). The most organized teams will have some established way of having the computer format your code for you.
The last example you listed is usually frowned upon and may be used only because it neatly fits on one line, which is important in (for example) presentations with limited screen space. Ah, no wonder the person in the video used the last way. The screen was limited, and he wanted to fit the whole code without having to scroll down and up I think. I wish people liked the second way, it's more readable in my opinion XD I'm always trying to make my code as readable as it can be ![]() Thanks ![]() |
Author: | Insectoid [ Sun Sep 15, 2013 8:21 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
There's no real consensus about which of the two formats to use. All of my teachers have always used the 2nd format, but I prefer the first. I find it more difficult to find the indents in the 2nd format, and all the extra whitespace really bothers me. |
Author: | Raknarg [ Sun Sep 15, 2013 9:31 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
I think the first way makes linguistic sense. The opening brace shows that it is indefinitely referring to that statement, otherwise it is (at a glance) indistinguishable from any other statement (that don't use braces, that is). I just prefer it. |
Author: | Dreadnought [ Sun Sep 15, 2013 11:22 pm ] |
Post subject: | Re: [C++ Help (SDL)] How do I know what coordinate to draw things to? |
I think the most important thing about coding styles is to decide on one style and stick with it. Consistency of your style throughout a project is much more important than the style itself in my opinion. |
Author: | Shinobu [ Mon Sep 16, 2013 4:47 pm ] |
Post subject: | Re: [C++ Help (SDL)] How do I know what coordinate to draw things to? |
Dreadnought @ September 15th 2013, 11:22 pm wrote: I think the most important thing about coding styles is to decide on one style and stick with it. Consistency of your style throughout a project is much more important than the style itself in my opinion.
Yeah, I just recently started naming my variables by a certain way, and lowercase/uppercase stuff. It's just a lot easier ![]() I'm probably used to the second way because Alex Allain (the author of my ebook) does it. I just copy most the things he does ![]() To me it's just easier to see { and } directly above and below each other, rather than the first way (it's just harder to find the curly brackets imo) If people like the first way more, I think I might just try and get out of my comfort zone and try the first way ![]() |
Author: | Raknarg [ Mon Sep 16, 2013 6:26 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
As said, it doesn't really matter which method you use. Use what you're comfortable with. And yes, using proper names is almost as good as documenting properly. A good goal with all your programs is make it so it's like reading an English manual. It makes it easier for you and everyone else, especially on the larger scale. |
Author: | Dreadnought [ Mon Sep 16, 2013 7:48 pm ] |
Post subject: | Re: [C++ Help (SDL)] How do I know what coordinate to draw things to? |
I'd also like to add that if you're working on someone else's project, you should try to follow their style as much as possible, again for consistency. |
Author: | Shinobu [ Mon Sep 23, 2013 7:21 pm ] |
Post subject: | Re: [C++ Help (SDL)] How do I know what coordinate to draw things to? |
Dreadnought @ September 16th 2013, 7:48 pm wrote: I'd also like to add that if you're working on someone else's project, you should try to follow their style as much as possible, again for consistency.
That clears up a lot of things for me ![]() But for LazyFoo's tutorials, he uses a heck of a lot of global variables. There's a lot that I find very unnecessary, to use in such a large scope. Should I just do what he does and change later on when I'm really good? I'm stuck on a chapter because I just don't exactly know how to make the scopes smaller lol (I'm just going to use global variables for now) |
Author: | Raknarg [ Mon Sep 23, 2013 8:51 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Well, think about how each variable is used. Are you only using a certain variable within a certain method? If so, make it local. Is it used across the program? Make it global. It should only be global if it needs to be imo |
Author: | Shinobu [ Fri Sep 27, 2013 7:41 pm ] |
Post subject: | Re: RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Raknarg @ September 23rd 2013, 8:51 pm wrote: Well, think about how each variable is used. Are you only using a certain variable within a certain method? If so, make it local. Is it used across the program? Make it global. It should only be global if it needs to be imo
You're the best! ![]() I had a hard time deciding whether or not making variables local or non-local lol. I always ended up making them non-local because of what I saw on examples on YouTube. Sometimes, I ended up making things look weird by making a lot of pointers (which now, I don't anymore) That actually clears up a lot of my programming time lol. I have a better idea of how many things can access a variable now ![]() I'm still not used to it, but my code does look better now XD |
Author: | Raknarg [ Fri Sep 27, 2013 7:54 pm ] |
Post subject: | RE:[C++ Help (SDL)] How do I know what coordinate to draw things to? |
Remember the idea is to make your code like an instruction manual, so the less convoluted the better. That means good names for everything, comments, and do things that make sense. |