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

2018/7/12

Damage change

B_rob1 B_rob1

2018/7/12

#
I am trying to work on my game with multiple "rays" attacking an enemy called unit with the damage code inside of said unit.
if (isTouching(LazerAmmo.class))
        {
            ((MyWorld) getWorld()).addMoney(1);
            //removeTouching(LazerAmmo.class);
            unitHP -=1;
        }
Is there any way I can make it to where if they are touching multiple different rays the damage they take will change? Depending on the time, there can be many, or few on the world at once
B_rob1 B_rob1

2018/7/12

#
I also tried
if (isTouching(LazerAmmo.class))
        {
            ((MyWorld) getWorld()).addMoney(1);
            //removeTouching(LazerAmmo.class);
            unitHP -=1;
          if (isTouching(LazerAmmo.class))
            {
              unitHP -=1;
             }
        }
and it always triggered the second variable with only one lazer ammo touching it
danpost danpost

2018/7/12

#
B_rob1 wrote...
I also tried << Code Omitted >> and it always triggered the second variable with only one lazer ammo touching it
I guess so -- it is still touching the same laser if you do not change anything (remove the laser or move one off the other). Are you planning on having each laser removed or not when touching a unit?
B_rob1 B_rob1

2018/7/13

#
danpost wrote...
B_rob1 wrote...
I also tried << Code Omitted >> and it always triggered the second variable with only one lazer ammo touching it
I guess so -- it is still touching the same laser if you do not change anything (remove the laser or move one off the other). Are you planning on having each laser removed or not when touching a unit?
    public void act() 
    {
        move(0);
        die();
    }  
    public void die()
    {
        timer -=1;
        if (timer <= 0)
        {
            getWorld().removeObject(this);
        }
        
    }
B_rob1 B_rob1

2018/7/13

#
The laser stays alive for a short duration, but one is created right afterward if a target is in range
danpost danpost

2018/7/13

#
B_rob1 wrote...
The laser stays alive for a short duration, but one is created right afterward if a target is in range
Maybe you can have a laser hold which unit it is touching and only deal damage when it does not currently hold the unit it is found to be touching (setting it to a unit when found touching and dealing damage so it does not deal multiple damage).
You need to login to post a reply.