Author Topic: Bounding screen limit  (Read 1561 times)

Offline Viren

  • byte
  • *
  • Posts: 3
    • View Profile
Bounding screen limit
« on: January 28, 2014, 03:02:15 pm »
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:
Code: [Select]

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
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Bounding screen limit
« Reply #1 on: January 28, 2014, 08:07:36 pm »
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