erinmoll wrote on Feb 26th, 2010, 2:17pm:So, 2.0 is the middle of all screens And why does "/" need to be there
I have a suspicion you need a very introductory level tutorial on a few things, like what an expression is.
"f / g" means "f divided by g"
"f * g" means "f times g"
+ and - are hopefully obvious (plus and minus)
So, "height / 2" means (approximately) "half the height" or in other words, about halfway down the output window (since y values start from 0 at the top of the window). "height / 2.0" is
nearly the same; the difference is that, because height is an integer (whole-number) variable and "2" is an integer constant, "height / 2" specifies an "integer divide" operation (meaning the result will always be an integer), and because "2.0" is a floating-point constant (having the "." makes it so, even though the fractional part is 0), so "height / 2.0" specifies a floating-point divide operation (which can result in a value such as 99.5).
This fundamental description of "/" and "*" appears to be missing from the
Learning section of this website (even the
Basics section), and I might guess, given your question, also from Shiffman's book.
I do suggest that you have a look in the
Basics section all the same, as it may help to explain some simple things that you might have missed reading Shiffman's book.
You might also note that the bottom of the window is actually height-1, because the top is 0, and 0 to height-1 is exactly the value of height.
-spxl
PS: I think you might be supposing that
float paddleAsPosition = height / 2.0;
is something like, in CSS:
border:5px solid red;
(meaning border-width=5px, border-style=solid, border-color=red)
but this is not the case. An assignment such as "x = blah;" is setting the variable x, which has only one value, so "x = blah blah blah blah;" means set the value of x to the
result of the
expression "blah blah blah blah". The blahs will generaly alternate between symbols (such as +,-,* and /, but also several others) and variable names and/or method calls.