keychera / AquaAesthetic

The last Java project for OOP
0 stars 0 forks source link

<Design> Fish Positioning and Movement #2

Closed keychera closed 7 years ago

keychera commented 7 years ago

the feasibility of method of moving fish forward to specific distance and angle

keychera commented 7 years ago

testing solution in separate branch testingFish, referencing issue #3

keychera commented 7 years ago

the reference from #11 have some manner of position interpolation that result in smooth movement and can of course be useful but the logic is intertwined with everything else (at least that I understand of)

keychera commented 7 years ago
public void update()
      {
         lastBallX = ballX;
         lastBallY = ballY;

         ballX += ballXVel;
         ballY += ballYVel;

         if (ballX + ballWidth/2 >= getWidth())
         {
            ballXVel *= -1;
            ballX = getWidth() - ballWidth/2;
            ballYVel = (float) Math.random() * ballSpeed*2 - ballSpeed;
         }
         else if (ballX - ballWidth/2 <= 0)
         {
            ballXVel *= -1;
            ballX = ballWidth/2;
         }

         if (ballY + ballHeight/2 >= getHeight())
         {
            ballYVel *= -1;
            ballY = getHeight() - ballHeight/2;
            ballXVel = (float) Math.random() * ballSpeed*2 - ballSpeed;
         }
         else if (ballY - ballHeight/2 <= 0)
         {
            ballYVel *= -1;
            ballY = ballHeight/2;
         }
      }

and

int drawX = (int) ((ballX - lastBallX) * interpolation + lastBallX - ballWidth/2);
int drawY = (int) ((ballY - lastBallY) * interpolation + lastBallY - ballHeight/2);
g.fillOval(drawX, drawY, ballWidth, ballHeight);
keychera commented 7 years ago

continued and extended by the issue #17