Gionne Lapuz
Gionne Lapuz

Reputation: 548

Changing object speed

I have been creating this simple game for fun, and I have ran into to some troubles.

Setting new speed on an object falling down. As the score rises for the user, I woudl want to change the speed and increase it little by little. But what happens is that the current speed just adds with the speed I want to increase so it because more faster.

This is my Activity:

   public void startTimer() {
    timer = new Timer();
    initializeTimerTask();
    timer.schedule(timerTask, 100, 20);

}
public void stoptimertask() {
    if (timer != null) {
        timer.cancel();
        timer = null;
    }
}
public void initializeTimerTask() {
    timerTask = new TimerTask() {
        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    goDown();
                }
            });
        }
    };
}

public void goDown() {
    frame = (FrameLayout) findViewById(R.id.frame);
    frameHeight = frame.getHeight();
    boxY = (int) txtWord.getY();
    boxSizeY = txtWord.getHeight();

    if(scoreCount >= 0)
    {
        boxY += 1;
    }
    if(scoreCount >= 5)
    {
        boxY += 2;
    }
    if(scoreCount >= 10)
    {
         boxY += 3;
    }

    txtWord.setY(boxY);

    if (boxY > frameHeight - boxSizeY) {
        boxY = frameHeight - boxSizeY;
        stoptimertask();
        displayGameOver();
    }

}

Thanks in advance for any insight or help! :D

Upvotes: 0

Views: 49

Answers (1)

Elinor
Elinor

Reputation: 101

 if(scoreCount >= 0 && scoreCount < 5)
{
    boxY += 1;
}
if(scoreCount >= 5 && scoreCount < 10)
{
    boxY += 2;
}
if(scoreCount >= 10)
{
     boxY += 3;
}

Try this for the speed issue.

Upvotes: 2

Related Questions