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

2015/6/6

Actor collision help

1
2
3
danpost danpost

2015/6/8

#
Gingervitis wrote...
Yes, so that means that the with the other code I had, the EnemyDamageField was never actually touching the MrBoom object, right?
Not necessarily; but probably. That is, they could have been intersecting without the EnemyDamageField image intersecting that particular point. As a matter of interest, the 'isTouching' method is actually the same as the 'canSee' method.
Gingervitis Gingervitis

2015/6/8

#
That makes sense. Thank you for the help. I will probably need help again soon because I have more glitches in my game but I am going to try to fix them myself before I request assistance.
danpost danpost

2015/6/8

#
Gingervitis wrote...
That makes sense. Thank you for the help. I will probably need help again soon because I have more glitches in my game but I am going to try to fix them myself before I request assistance.
Sorry, I was about to edit my last post after doing a little checking. The two methods are not the same -- 'canSee' is like 'getOneObjectAtOffset(0, 0, clss) != null'.
Gingervitis Gingervitis

2015/6/8

#
If using this code below, what would cause the EnemyDamageField to move in the opposite direction and not follow the 'turnTowards' method?
if(isTouching(Castle.class)){
           Actor actor = (Actor)(getWorld().getObjects(Castle.class).get(0));
           turnTowards(actor.getX(), actor.getY());
        }
danpost danpost

2015/6/8

#
The code you gave will have the actor turn toward a specific Castle object (not necessarily the one it is touching) when it is touching any Castle object. In other words, the code given is equivalent to this:
Actor castleTouched = getOneIntersectingObject(Castle.class);
if (castleTouched != null)
{
    Actor someCastle = (Actor)getWorld().getObjects(Castle.class).get(0);
    turnTowards(someCastle.getX(), someCastle.getY());
}
where 'castleTouched' may or may not be the same actor as 'someCastle'. If you explain exactly what you are trying to do (in detail), a solution to your issue may be presentable.
Gingervitis Gingervitis

2015/6/8

#
The same issue with the EnemyDamageField contacting the MrBoom object is occurring when it comes into contact with the castle class. Originally, there were no errors with this but then once I got the MrBoom to take damage, the castle stopped taking damage. I would be most grateful if there were a solution to this because I intend on adding many more ally and enemy classes in the future and collision errors will not make my tower defense function properly. If you need me to supply the current code I have, I will gladly do so. Thanks again.
danpost danpost

2015/6/8

#
Gingervitis wrote...
If you need me to supply the current code I have, I will gladly do so. Thanks again.
It would certainly help. Publishing the scenario would be the easier way.
danpost danpost

2015/6/8

#
If you want to delete it from the site, I did get it already.
Gingervitis Gingervitis

2015/6/8

#
danpost wrote...
If you want to delete it from the site, I did get it already.
My apologies if it does not fit your screen.
danpost danpost

2015/6/9

#
Things to be aware of: * the GreenfootImage 'setColor' method does not apply any color to the image; it only sets the drawing color for future drawing operations on that image; * the GreenfootImage 'fill' method fills the image with the color last set by 'setColor'; it sets the color of each and every pixel in the image to that color; it does not necessarily make an actor visible (from a comment on a 'fill' statement) * you need to realize that subclasses are intended to be for objects of the same type as the class they extend -- the purpose is to apply extra state and behavior to the object created; for example, you would not subclass a Week class with a Day class -- a day is only one part of a week (not a week, in itself); hence, your Menu subclasses should not extend the Menu class (they are not in themselves menus; they may belong to the menu, but they are only particular parts of the menu); same goes with the HUD class structure; as a sidenote, the menu classes should probably not extend the Animal class either; You have yet to do anything with the 'player2' list in your MrBoom 'isAttacking' method which is for the enemy castle collisions.
Gingervitis Gingervitis

2015/6/9

#
Yes I did know that setColor does apply to the color of the image. I had used that to set the base color for the new GreenfootImage (Without doing so would set the menu box to the default black) and I had figured out it sets the color to the future drawing operations when I had to add the text. You may correct me on this but the only reason I made the menu parts subclasses of the menu is because with inheritance, the subclasses have direct contact to the Menu class (and the subclasses perform actions based on the Menu super class). I will, however, once my final project is completed (due next Wednesday) continue to make progress on this scenario and adjust ALL my code to be as efficient as possible. The 'player2' list will actually never be used so I should not have kept that in my code.... I hope this year's AP Java course has made my coding and coding logic much better (as opposed to my first project "Turtle Adventure" which is absolutely atrocious)
danpost danpost

2015/6/9

#
Just for clarification, I said the 'setColor' method does not apply any color to the image. It only changes the value of a field that the GreenfootImage object uses when the image is drawn on. There is no change to the image itself (the array of Color objects that make up the image) when calling this method.
Gingervitis Gingervitis

2015/6/9

#
danpost wrote...
It would certainly help. Publishing the scenario would be the easier way.
Any errors found with my code for the castle not taking damage?
danpost danpost

2015/6/9

#
Gingervitis wrote...
Any errors found with my code for the castle not taking damage?
What class, method, and line is the castle supposed to be losing health on?
You need to login to post a reply.
1
2
3