This site requires JavaScript, please enable it in your browser!
Greenfoot back
StudyNerd
StudyNerd wrote ...

2020/1/19

need help

StudyNerd StudyNerd

2020/1/19

#
if (touchHealth == 1) { curTime = System.currentTimeMillis(); if (curTime >= lastAdded + 5000) { if (touchEnemy == 0) { ((HealthBar)getWorld().getObjects(HealthBar.class).get(0)).healthNum++; removeTouching(Enemy.class); touchHealth = 0; } } } everything in this code is working fine except for the curTime. For example; if the enemy touches the player for 5 seconds, it should remove the enemy. However, it doesn't do that. If I take the cutTime part out it works, but I won't have a timer. Please help
danpost danpost

2020/1/19

#
StudyNerd wrote...
<< Code Omitted >> everything in this code is working fine except for the curTime. For example; if the enemy touches the player for 5 seconds, it should remove the enemy. However, it doesn't do that. If I take the cutTime part out it works, but I won't have a timer. Please help
How are you controlling the value of lastAdded? (show relevant codes)
StudyNerd StudyNerd

2020/1/19

#
danpost wrote...
StudyNerd wrote...
<< Code Omitted >> everything in this code is working fine except for the curTime. For example; if the enemy touches the player for 5 seconds, it should remove the enemy. However, it doesn't do that. If I take the cutTime part out it works, but I won't have a timer. Please help
How are you controlling the value of lastAdded? (show relevant codes)
if (isTouching(Enemy.class)) { if (touchEnemy == 0) { changeHealth(); } else if (touchEnemy == 1) { touchEnemy = 0; } } else { touchHealth = 0; } public void changeHealth() { lastAdded = System.currentTimeMillis(); touchHealth = 1; }
danpost danpost

2020/1/19

#
In changeHealth method, try changing first line to this:
if (touchHealth == 0) lastAdded = System.currentTimeMillis();
StudyNerd StudyNerd

2020/1/19

#
danpost wrote...
In changeHealth method, try changing first line to this:
if (touchHealth == 0) lastAdded = System.currentTimeMillis();
thank you
You need to login to post a reply.