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

2013/5/26

How can I make an enemy "lose health" when an arrow hits it?

1
2
Yongjoon Yongjoon

2013/5/26

#
I'm trying to make it so that when my character fires an arrow and it hits an enemy, the enemy loses health based on how much armor it has and what type of unit it is. What and where should i put this code? In the arrow class or the character class?
danpost danpost

2013/5/26

#
In the character class, since it will hold its health value.
Yongjoon Yongjoon

2013/5/26

#
Whoops, been doing it wrong then. Thanks! I'll give word if I screw up some more! ^.^
Yongjoon Yongjoon

2013/5/26

#
Ok, could you give me some tips on how to do this? So far, I've tried to create an ArrayList and add all the other actors. After that, i try to remove the actors that are "friendly". I can't add any actors for some reason. Im using getObjects but can't really figure out how to use it. I havent gotten the arrow to damage any actor either. :/ ...I'm a newbie programmer haha sorry for all the trouble
danpost danpost

2013/5/26

#
Let me make sure that I was totally clear as to what should go where. (1) the code to fire (or shoot) the arrow goes in the character class (2) the code to detect the arrow hitting an enemy goes in the enemy class I wanted to be clear on number two because 'enemy' was not one of the options that you gave. You should not need to create an ArrayList. Each cycle (which would be about 60 times a second) only need act on one intersecting object at a time.
Yongjoon Yongjoon

2013/5/28

#
Well, im making 2 sides. One wave of creeps are your helpers kinda. And i dont want to let the character damage their own creeps. So i wanted to make an arrayList of enemy creeps and only be able to hurt the creeps/objects inn the array
danpost danpost

2013/5/28

#
Would it not be easier to just add a boolean instance field to the creep class? set it to true if you can damage it; else false, it is on your side.
Yongjoon Yongjoon

2013/5/28

#
ah...that's smart you sir are a great help to me and my puny mind
Yongjoon Yongjoon

2013/5/28

#
If you can't tell, i'm a terrible programmer. I have no clue how to check if they are hit. I just tried this: public void CheckDamg() { if(purple) { enemy=true; if(VayneArrow.getLeft().equals(PurpMins.getLeft()) {PurpMinHp-=vayneAttk; } } else {enemy=false}
Yongjoon Yongjoon

2013/5/28

#
and uh...it doesn't work. help ? thanks
danpost danpost

2013/5/28

#
How does it not work? are you getting an error message? does it say something like 'non-static method cannot be referenced in a static context'? are VayneArrow and PurpMins actor class names? or references to objects created from actor classes?
Yongjoon Yongjoon

2013/5/28

#
VayneArrow and PurpMins are actor classes yes. It just shows a red line and wont let me compile
Yongjoon Yongjoon

2013/5/28

#
Im doing this in the VayneArrow class btw.
public void damg()
    {
        if(enemy)
        {
            if(VayneArrow.getLeft().equals(PurpMins.getLeft())
            {PurpMinHp-=vayneAttk;
            }
            else
            {enemy=false}
        }
    }
danpost danpost

2013/5/28

#
Do you only create one object from each of those two classes?
Yongjoon Yongjoon

2013/5/28

#
enemy is a boolean. PurpMinHp is a static int. vayneAttk is equal to 60.
There are more replies on the next page.
1
2