Bounding screen limit

Started by Viren, January 28, 2014, 03:02:15 PM

Previous topic - Next topic

Viren

Hello Sir!
Sir, I am working on an android game. Firstly, I have made collision between characters through collision detection method of JPCT-ae.
but it was not satisfying. Now I have carried out it based on action and distance between character as follow:

SimpleVector dist=ninja_cpu.getRoot().getTransformedCenter(). calcSub(ninja_user.getRoot().getTransformedCenter());
if (animation_user==2 && dist.length()<3.5*NinjaWidth){
BattryLevelUSER.setProgress(counter_user--);
}

and similarly for opponent
SimpleVector dista=ninja_user.getRoot().getTransformedCenter(). calcSub(ninja_cpu.getRoot().getTransformedCenter());
if (animation_cpu==2 && dist.length()<3.5*NinjaWidth){
BattryLevelCPU.setProgress(counter_cpu--);
}

It works fine sometime but  sometime it doesn't works( seems if condition doesn't get satisfied properly.

For bounding the screen limit( character should not move outside of the screen) I have used following logic
if(ninja_user.getRoot().getTransformedCenter().x<220)

{
  if(ninja_cpu.getRoot().getTransformedCenter().x+ 3.5*NinjaWidth < ninja_user.getRoot().getTransformedCenter().x)
  ninja_user.getRoot().translate(-5,0,0);

This for cpu ninja whreas for user to move left
if(ninja_user.getRoot().getTransformedCenter().x > locationofcpu)
{

//if Ninja is greater than 100 bring it in 100

if(ninja_cpu.getRoot().getTransformedCenter().x<=-150)
{
ninja_cpu.getRoot().translate(10, 0, 0);
}

  and to move right if(ninja_user.getRoot().getTransformedCenter().x > locationofcpu)
  
{
//if Ninja is greater than 100 bring it in 100
if(ninja_cpu.getRoot().getTransformedCenter().x>=200)
{
ninja_cpu.getRoot().translate(-10, 0, 0);
}

}

This sometimes give satisfactory result whereas some times wrong. I don't think I am carrying out it in a proper way. I am testing this on my Samsung Galaxy Ace but in some other device it doesn't gives satisfactory result. i am using progress bar as battery.

EgonOlsen

Where have you placed this code? Make sure that you don't do it in an event listener method like onTouch() or similar, because....http://www.jpct.net/wiki/index.php/Thread_safety