0

I'm constructing the basis of a game and when the character hits an NPC, I want a number to float around the player for a second or two. The problem I'm having is when I try to draw the number following a parabolic equation, all that gets drawn is the number in a diagonal line, as seen below.

fig. 1

The equation I want it to follow is x^2/50 + 2x, from x=0 to x=100.

Here is the code I've made.

for(int x=0; x<100; x++) {
    g.drawString("5", x, ((x^2)/50) + (2*x));
}

I've adjusted the equation in multiple ways so that the line is wider and skinnier, but still having no luck. Any ideas about where I'm going wrong?

2kan
  • 95
  • 2
  • 10

1 Answers1

3

If your question is why are you not getting a parabola, the reason is that in Java the way you say "x squared" is

x * x

and not

x ^ 2

The later does a binary exclusive or with 2. Not what you want.

Ray Toal
  • 86,166
  • 18
  • 182
  • 232
  • Yes! Thank you, I wasn't aware of this in Java. Works just as expected now :) – 2kan Mar 13 '12 at 05:20
  • Cool. Many languages have a power operator, such as `**` in Python and Ruby, and `^` in Lua. Unfortunately (or fortunately for some people), Java does not have one. – Ray Toal Mar 13 '12 at 05:23