Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For Example, There is a tree(image) and i want to destroy it. I want my character only destroy it (For example the character must be facing the tree to destroy it and there must be a range were you can destroy. How do i do this? Note: THis is a game made with slick!

share|improve this question

closed as not a real question by Byte56, Laurent Couvidou, doppelgreener, John McDonald, Trevor Powell Sep 20 '12 at 5:20

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
What do you mean by "only destroy it in front"? How do you character destroy trees, with projectiles? Or with a simple contact? Please edit your question with a bit more details. –  Laurent Couvidou Sep 14 '12 at 12:04
    
"and there m must be a radius or length were you can destroy" you mean a range where the player can destroy the tree... –  nathan Sep 14 '12 at 12:32
    
You could use collision detection for that, set a bounding-box around (or in front of) the player in the range you want him to be able to destroy objects. Then check if the object collides with the Range-Bounding-Box and do your stuff. –  bryan226 Sep 14 '12 at 13:12
1  
SystemNetworks. You need to think about your question more and rephrase it. Try to make it as clear as possible. Give examples from current games if that helps. Remember, you're asking for help, and you need to make giving that help as easy as possible. –  Byte56 Sep 14 '12 at 15:43

2 Answers 2

To figure out whether the player is facing the tree or not, get the angle from the player to the tree and the angle the player is facing. If the absolute value of the difference is less than a certain amount, the player is facing the tree.

For range, just use the distance formula.

share|improve this answer
up vote -1 down vote accepted
  1. Find the position of the object
  2. Create a boolean destroy = false boolean tree1 = true
  3. Make an if statement
  4. Make your method.
  5. Example of a position if((posx<360 && posx>300) && (posy<500 && posy>485))
  6. Put key input
  7. Inside it put destroy = true; and tree1 =false;
  8. You may repeat it but change tree1!

For Image: 1. add Image tree; //You may use this a lot of times!

  1. To use tree add tree = new Image ("your_folder/imagename.png") //png is recommended

  2. Create an if statement in your render if(!destroy) and if(tree1==true)

  3. The first if statement must be tree 1!
  4. Inside tree1, put tree.draw(cord, cord);
  5. Repeat it if you want to destroy more

Note: Your character need to be in that pos to destroy it! I'm working on the code for range attacks...

Link to full source code: http://systemnetworks.comeze.com/Source%20Codes.php

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.